Skip to content

Commit

Permalink
RHINENG-11302: add test for template filters
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMraka committed Jul 12, 2024
1 parent 8aadbd6 commit b169272
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
24 changes: 24 additions & 0 deletions manager/controllers/systems_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,27 @@ func TestSystemsExportArchFilter(t *testing.T) {
assert.Equal(t, "x86_64", o.Arch)
}
}

func TestSystemsExportTemplateNameFilter(t *testing.T) {
w := makeRequest(t, "/?filter[template_name]=temp1-1", "application/json")

var output []SystemDBLookup
CheckResponse(t, w, http.StatusOK, &output)

assert.Equal(t, 2, len(output))
for _, o := range output {
assert.Equal(t, "temp1-1", o.TemplateName)
}
}

func TestSystemsExportTemplateUUID(t *testing.T) {
w := makeRequest(t, "/?filter[template_uuid]=99900000-0000-0000-0000-000000000001", "application/json")

var output []SystemDBLookup
CheckResponse(t, w, http.StatusOK, &output)

assert.Equal(t, 2, len(output))
for _, o := range output {
assert.Equal(t, "99900000-0000-0000-0000-000000000001", o.TemplateUUID)
}
}
20 changes: 20 additions & 0 deletions manager/controllers/systems_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,26 @@ func TestSystemsIDsFilterArch(t *testing.T) {
}
}

func TestSystemsIDsFilterTemplateName(t *testing.T) {
output := testSystems(t, `?filter[template_name]=temp1-1`, 1)
outputIDs := testSystemsIDs(t, `?filter[template_name]=temp1-1`, 1)
assert.Equal(t, 2, len(outputIDs.Data))
assert.Equal(t, 2, len(output.Data))
for i, d := range outputIDs.Data {
assert.Equal(t, output.Data[i].ID, d.ID)
}
}

func TestSystemsIDsFilterTemplateUUID(t *testing.T) {
output := testSystems(t, `?filter[template_uuid]=99900000-0000-0000-0000-000000000001`, 1)
outputIDs := testSystemsIDs(t, `?filter[template_uuid]=99900000-0000-0000-0000-000000000001`, 1)
assert.Equal(t, 2, len(outputIDs.Data))
assert.Equal(t, 2, len(output.Data))
for i, d := range outputIDs.Data {
assert.Equal(t, output.Data[i].ID, d.ID)
}
}

func testSystemsIDs(t *testing.T, queryString string, account int) IDsSatelliteManagedResponse {
core.SetupTest(t)
w := CreateRequestRouterWithAccount("GET", "/", "", queryString, nil, "", SystemsListIDsHandler, account)
Expand Down
18 changes: 18 additions & 0 deletions manager/controllers/systems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func TestSystemsDefault(t *testing.T) {
assert.False(t, output.Data[0].Attributes.SatelliteManaged)
assert.False(t, output.Data[0].Attributes.BuiltPkgcache)
assert.Equal(t, "x86_64", output.Data[0].Attributes.Arch)
assert.Equal(t, "temp1-1", output.Data[0].Attributes.TemplateName)
assert.Equal(t, "99900000-0000-0000-0000-000000000001", output.Data[0].Attributes.TemplateUUID)

// links
assert.Equal(t, "/?offset=0&limit=20&filter[stale]=eq:false&sort=-last_upload", output.Links.First)
Expand Down Expand Up @@ -244,6 +246,22 @@ func TestSystemsFilterArch(t *testing.T) {
}
}

func TestSystemsFilterTemplateName(t *testing.T) {
output := testSystems(t, `?filter[template_name]=temp1-1`, 1)
assert.Equal(t, 2, len(output.Data))
for _, d := range output.Data {
assert.Equal(t, "temp1-1", d.Attributes.TemplateName)
}
}

func TestSystemsFilterTemplateUUID(t *testing.T) {
output := testSystems(t, `?filter[template_uuid]=99900000-0000-0000-0000-000000000001`, 1)
assert.Equal(t, 2, len(output.Data))
for _, d := range output.Data {
assert.Equal(t, "99900000-0000-0000-0000-000000000001", d.Attributes.TemplateUUID)
}
}

func testSystems(t *testing.T, queryString string, account int) SystemsResponse {
core.SetupTest(t)
w := CreateRequestRouterWithAccount("GET", "/", "", queryString, nil, "", SystemsListHandler, account)
Expand Down

0 comments on commit b169272

Please sign in to comment.