From 41331a67f69e7a483e990a4437127f9889e45fde Mon Sep 17 00:00:00 2001 From: Chris Prather Date: Sun, 26 Jan 2020 19:41:18 +0000 Subject: [PATCH] start moving to testify it has better debugging output --- Gopkg.lock | 17 +++++++++++++++++ builds_test.go | 18 ++++++++++-------- hardware_test.go | 4 +++- organizations_test.go | 20 +++++++------------- roles_test.go | 4 +++- rooms_integration_test.go | 5 ++++- rooms_test.go | 4 +++- 7 files changed, 47 insertions(+), 25 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 32471c5..57a59ba 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -88,6 +88,14 @@ revision = "e6d60cf7ba1f42d86d54cdf5508611c4aafb3970" version = "v0.0.1" +[[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + pruneopts = "UT" + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + [[projects]] digest = "1:d235e49bf6cae4fe6a794352b5e74656f9e3c15b1f6b097b0382865414110e2e" name = "github.com/qri-io/jsonpointer" @@ -104,6 +112,14 @@ revision = "b244d4b99401d163bd9e382fd58698794259d091" version = "v0.1.1" +[[projects]] + digest = "1:8548c309c65a85933a625be5e7d52b6ac927ca30c56869fae58123b8a77a75e1" + name = "github.com/stretchr/testify" + packages = ["assert"] + pruneopts = "UT" + revision = "221dbe5ed46703ee255b1da0dec05086f5035f62" + version = "v1.4.0" + [[projects]] digest = "1:59f10c1537d2199d9115d946927fe31165959a95190849c82ff11e05803528b0" name = "gopkg.in/yaml.v2" @@ -125,6 +141,7 @@ "github.com/jawher/mow.cli", "github.com/olekukonko/tablewriter", "github.com/qri-io/jsonschema", + "github.com/stretchr/testify/assert", ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/builds_test.go b/builds_test.go index 1ce3b44..305f1fb 100644 --- a/builds_test.go +++ b/builds_test.go @@ -8,6 +8,8 @@ import ( "net/http" "net/http/httptest" "testing" + + "github.com/stretchr/testify/assert" ) func TestBuildsGetAll(t *testing.T) { @@ -28,7 +30,7 @@ func TestBuildsGetAll(t *testing.T) { assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, "/build") - assertData(t, got, buildList) + assert.Equal(t, got, buildList) } func TestBuildsGet(t *testing.T) { @@ -49,7 +51,7 @@ func TestBuildsGet(t *testing.T) { assertRequestMethod(t, spy.requestMethod, "GET") assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, fmt.Sprintf("/build/%s", build.ID)) - assertData(t, got, build) + assert.Equal(t, got, build) } func TestBuildsGetByName(t *testing.T) { @@ -70,7 +72,7 @@ func TestBuildsGetByName(t *testing.T) { assertRequestMethod(t, spy.requestMethod, "GET") assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, fmt.Sprintf("/build/%s", build.Name)) - assertData(t, got, build) + assert.Equal(t, got, build) } func TestBuildsCreate(t *testing.T) { @@ -100,7 +102,7 @@ func TestBuildsCreate(t *testing.T) { } // now let's check what we made in the server is what we got in the client - assertData(t, got, want) + assert.Equal(t, got, want) } func TestBuildsGetUsers(t *testing.T) { @@ -123,7 +125,7 @@ func TestBuildsGetUsers(t *testing.T) { assertRequestMethod(t, spy.requestMethod, "GET") assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, fmt.Sprintf("/build/%s/user", build.ID)) - assertData(t, got, list) + assert.Equal(t, got, list) } func TestBuildsAddUser(t *testing.T) { @@ -191,7 +193,7 @@ func TestBuildsGetOrgs(t *testing.T) { assertRequestMethod(t, spy.requestMethod, "GET") assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, fmt.Sprintf("/build/%s/organization", build.ID)) - assertData(t, got, list) + assert.Equal(t, got, list) } func TestBuildsAddOrg(t *testing.T) { @@ -259,7 +261,7 @@ func TestBuildsGetDevices(t *testing.T) { assertRequestMethod(t, spy.requestMethod, "GET") assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, fmt.Sprintf("/build/%s/device", build.ID)) - assertData(t, got, list) + assert.Equal(t, got, list) } func TestBuildsAddDevice(t *testing.T) { @@ -327,7 +329,7 @@ func TestBuildsGetRacks(t *testing.T) { assertRequestMethod(t, spy.requestMethod, "GET") assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, fmt.Sprintf("/build/%s/rack", build.ID)) - assertData(t, got, list) + assert.Equal(t, got, list) } func TestBuildsAddRack(t *testing.T) { diff --git a/hardware_test.go b/hardware_test.go index 1487e51..836eece 100644 --- a/hardware_test.go +++ b/hardware_test.go @@ -8,6 +8,8 @@ import ( "net/http" "net/http/httptest" "testing" + + "github.com/stretchr/testify/assert" ) func TestHardwareProductCreate(t *testing.T) { @@ -43,7 +45,7 @@ func TestHardwareProductCreate(t *testing.T) { assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, "/hardware_product") assertRequestMethod(t, spy.requestMethod, "POST") - assertData(t, got, want) + assert.Equal(t, got, want) } func TestHardwareProductDelete(t *testing.T) { diff --git a/organizations_test.go b/organizations_test.go index b38af0c..07a978f 100644 --- a/organizations_test.go +++ b/organizations_test.go @@ -7,8 +7,9 @@ import ( "io/ioutil" "net/http" "net/http/httptest" - "reflect" "testing" + + "github.com/stretchr/testify/assert" ) func TestOrganizationsGet(t *testing.T) { @@ -37,7 +38,7 @@ func TestOrganizationsGet(t *testing.T) { assertRequestMethod(t, spy.requestMethod, "GET") assertRequestCount(t, spy.requestCount, i+1) assertRequestPath(t, spy.requestPath, fmt.Sprintf("/organization/%s", org.ID)) - assertData(t, got, org) + assert.Equal(t, got, org) }) } @@ -69,7 +70,7 @@ func TestOrganizationsGetByName(t *testing.T) { assertRequestMethod(t, spy.requestMethod, "GET") assertRequestCount(t, spy.requestCount, i+1) assertRequestPath(t, spy.requestPath, fmt.Sprintf("/organization/%s", org.Name)) - assertData(t, got, org) + assert.Equal(t, got, org) }) } @@ -93,7 +94,7 @@ func TestOrganizationsGetAll(t *testing.T) { assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, "/organization") - assertData(t, got, orgList) + assert.Equal(t, got, orgList) } func TestOrganizationsCreate(t *testing.T) { @@ -123,7 +124,7 @@ func TestOrganizationsCreate(t *testing.T) { } // now let's check what we made in the server is what we got in the client - assertData(t, got, want) + assert.Equal(t, got, want) } func TestOrganizationsDelete(t *testing.T) { @@ -169,7 +170,7 @@ func TestOrganizationsGetUsers(t *testing.T) { assertRequestMethod(t, spy.requestMethod, "GET") assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, fmt.Sprintf("/organization/%s/user", org.ID)) - assertData(t, got, userList) + assert.Equal(t, got, userList) } func TestOrganizationsAddUser(t *testing.T) { @@ -255,10 +256,3 @@ func assertRequestCount(t *testing.T, got, want int) { t.Errorf("Wrong number of requests, got %d wanted %d", got, want) } } - -func assertData(t *testing.T, got, want interface{}) { - t.Helper() - if !reflect.DeepEqual(got, want) { - t.Fatalf("Got wrong results, got %v wanted %v", got, want) - } -} diff --git a/roles_test.go b/roles_test.go index a7548c9..71d2ac1 100644 --- a/roles_test.go +++ b/roles_test.go @@ -7,6 +7,8 @@ import ( "net/http" "net/http/httptest" "testing" + + "github.com/stretchr/testify/assert" ) func TestRackRoleCreateFromStruct(t *testing.T) { @@ -31,5 +33,5 @@ func TestRackRoleCreateFromStruct(t *testing.T) { assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, "/rack_role") assertRequestMethod(t, spy.requestMethod, "POST") - assertData(t, got, want) + assert.Equal(t, got, want) } diff --git a/rooms_integration_test.go b/rooms_integration_test.go index b0bac5a..fbe2358 100644 --- a/rooms_integration_test.go +++ b/rooms_integration_test.go @@ -2,6 +2,8 @@ package main import ( "testing" + + "github.com/stretchr/testify/assert" ) func TestRoomsAPIIntegration(t *testing.T) { @@ -21,7 +23,8 @@ func TestRoomsAPIIntegration(t *testing.T) { want.Alias, want.VendorName, ) - //assertData(t, got, want) + assert.NotNil(t, testRoom.ID) + // TODO write a functional test here -- perigrin }) t.Run("Get all rooms", func(t *testing.T) { diff --git a/rooms_test.go b/rooms_test.go index c304eb2..9431c26 100644 --- a/rooms_test.go +++ b/rooms_test.go @@ -7,6 +7,8 @@ import ( "net/http" "net/http/httptest" "testing" + + "github.com/stretchr/testify/assert" ) func TestRoomsCreateFromStruct(t *testing.T) { @@ -31,5 +33,5 @@ func TestRoomsCreateFromStruct(t *testing.T) { assertRequestCount(t, spy.requestCount, 1) assertRequestPath(t, spy.requestPath, "/room") assertRequestMethod(t, spy.requestMethod, "POST") - assertData(t, got, want) + assert.Equal(t, got, want) }