Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
start moving to testify
Browse files Browse the repository at this point in the history
it has better debugging output
  • Loading branch information
perigrin committed Jan 27, 2020
1 parent 1af623a commit 41331a6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
17 changes: 17 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

func TestBuildsGetAll(t *testing.T) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion hardware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

func TestHardwareProductCreate(t *testing.T) {
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 7 additions & 13 deletions organizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestOrganizationsGet(t *testing.T) {
Expand Down Expand Up @@ -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)
})
}

Expand Down Expand Up @@ -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)
})
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
4 changes: 3 additions & 1 deletion roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRackRoleCreateFromStruct(t *testing.T) {
Expand All @@ -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)
}
5 changes: 4 additions & 1 deletion rooms_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestRoomsAPIIntegration(t *testing.T) {
Expand All @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion rooms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRoomsCreateFromStruct(t *testing.T) {
Expand All @@ -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)
}

0 comments on commit 41331a6

Please sign in to comment.