Skip to content

Commit

Permalink
fix up some overly brittle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorVin committed Apr 19, 2024
1 parent 1432f25 commit 60c4214
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
18 changes: 13 additions & 5 deletions pkg/api/v1/router_server_components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestIntegrationServerGetComponents(t *testing.T) {
// fixture to create a server components
csFixtureCreate := fleetdbapi.ServerComponentSlice{
{
ServerUUID: servers[0].UUID,
ServerUUID: servers[1].UUID,
Name: "My Lucky Fin",
Vendor: "barracuda",
Model: "a lucky fin",
Expand All @@ -226,7 +226,7 @@ func TestIntegrationServerGetComponents(t *testing.T) {
}

// create server component
_, err = s.Client.CreateComponents(context.TODO(), servers[0].UUID, csFixtureCreate)
_, err = s.Client.CreateComponents(context.TODO(), servers[1].UUID, csFixtureCreate)
if err != nil {
t.Fatal(err)
}
Expand All @@ -247,10 +247,10 @@ func TestIntegrationServerGetComponents(t *testing.T) {
},
{
"component Versioned Attributes is returned as expected",
servers[0].UUID,
servers[1].UUID,
3,
fleetdbapi.ServerComponent{
ServerUUID: servers[0].UUID,
ServerUUID: servers[1].UUID,
Name: "My Lucky Fin",
Vendor: "barracuda",
Model: "a lucky fin",
Expand Down Expand Up @@ -504,8 +504,16 @@ func TestIntegrationServerUpdateComponents(t *testing.T) {
t.Fatal(err)
}

var nemo *fleetdbapi.Server
for _, s := range servers {
if s.Name == dbtools.FixtureNemo.Name.String {
nemo = &s
}
}
require.NotNil(t, nemo, "couldn't find nemo")

// update serial attribute for update to work
sc = fleetdbapi.ServerComponentSlice{servers[0].Components[0]}
sc = fleetdbapi.ServerComponentSlice{nemo.Components[0]}
sc[0].Serial = "lala"
}

Expand Down
23 changes: 10 additions & 13 deletions pkg/api/v1/router_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ func TestIntegrationServerList(t *testing.T) {
r, resp, err := s.Client.List(ctx, nil)
if !expectError {
require.NoError(t, err)
assert.Len(t, r, 3)
assert.Len(t, r, 4)

assert.EqualValues(t, 3, resp.PageCount)
assert.EqualValues(t, 4, resp.PageCount)
assert.EqualValues(t, 1, resp.TotalPages)
assert.EqualValues(t, 3, resp.TotalRecordCount)
assert.EqualValues(t, 4, resp.TotalRecordCount)
// We returned everything, so we shouldnt have a next page info
assert.Nil(t, resp.Links.Next)
assert.Nil(t, resp.Links.Previous)
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestIntegrationServerList(t *testing.T) {
{
"empty search filter",
nil,
[]string{dbtools.FixtureNemo.ID, dbtools.FixtureDory.ID, dbtools.FixtureMarlin.ID},
[]string{dbtools.FixtureInventoryServer.ID, dbtools.FixtureNemo.ID, dbtools.FixtureDory.ID, dbtools.FixtureMarlin.ID},
false,
"",
},
Expand Down Expand Up @@ -436,14 +436,14 @@ func TestIntegrationServerList(t *testing.T) {
{
"search for server without IncludeDeleted defined",
&fleetdbapi.ServerListParams{},
[]string{dbtools.FixtureNemo.ID, dbtools.FixtureDory.ID, dbtools.FixtureMarlin.ID},
[]string{dbtools.FixtureInventoryServer.ID, dbtools.FixtureNemo.ID, dbtools.FixtureDory.ID, dbtools.FixtureMarlin.ID},
false,
"",
},
{
"search for server with IncludeDeleted defined",
&fleetdbapi.ServerListParams{IncludeDeleted: true},
[]string{dbtools.FixtureNemo.ID, dbtools.FixtureDory.ID, dbtools.FixtureMarlin.ID, dbtools.FixtureChuckles.ID},
[]string{dbtools.FixtureInventoryServer.ID, dbtools.FixtureNemo.ID, dbtools.FixtureDory.ID, dbtools.FixtureMarlin.ID, dbtools.FixtureChuckles.ID},
false,
"",
},
Expand Down Expand Up @@ -511,12 +511,10 @@ func TestIntegrationServerListPagination(t *testing.T) {

assert.NoError(t, err)
assert.Len(t, r, 2)
assert.Equal(t, dbtools.FixtureServers[2].ID, r[0].UUID.String())
assert.Equal(t, dbtools.FixtureServers[1].ID, r[1].UUID.String())

assert.EqualValues(t, 2, resp.PageCount)
assert.EqualValues(t, 2, resp.TotalPages)
assert.EqualValues(t, 3, resp.TotalRecordCount)
assert.EqualValues(t, 4, resp.TotalRecordCount)
// Since we have a next page let's make sure all the links are set
assert.NotNil(t, resp.Links.Next)
assert.Nil(t, resp.Links.Previous)
Expand All @@ -528,16 +526,15 @@ func TestIntegrationServerListPagination(t *testing.T) {
resp, err = s.Client.NextPage(context.TODO(), *resp, &r)

assert.NoError(t, err)
assert.Len(t, r, 1)
assert.Equal(t, dbtools.FixtureServers[0].ID, r[0].UUID.String())
assert.Len(t, r, 2)

assert.EqualValues(t, 1, resp.PageCount)
assert.EqualValues(t, 2, resp.PageCount)

// we should have followed the cursor so first/previous/next/last links shouldn't be set
// but there is another page so we should have a next cursor link. Total counts are not includes
// cursor pages
assert.EqualValues(t, 2, resp.TotalPages)
assert.EqualValues(t, 3, resp.TotalRecordCount)
assert.EqualValues(t, 4, resp.TotalRecordCount)
assert.NotNil(t, resp.Links.First)
assert.NotNil(t, resp.Links.Previous)
assert.Nil(t, resp.Links.Next)
Expand Down

0 comments on commit 60c4214

Please sign in to comment.