From b169272a9550aedd53d1b11e2c4ec44097409901 Mon Sep 17 00:00:00 2001 From: Michael Mraka Date: Thu, 11 Jul 2024 11:28:33 +0200 Subject: [PATCH] RHINENG-11302: add test for template filters --- manager/controllers/systems_export_test.go | 24 ++++++++++++++++++++++ manager/controllers/systems_ids_test.go | 20 ++++++++++++++++++ manager/controllers/systems_test.go | 18 ++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/manager/controllers/systems_export_test.go b/manager/controllers/systems_export_test.go index 01231b054..0575ca443 100644 --- a/manager/controllers/systems_export_test.go +++ b/manager/controllers/systems_export_test.go @@ -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) + } +} diff --git a/manager/controllers/systems_ids_test.go b/manager/controllers/systems_ids_test.go index 8c4d630d2..1a4d21734 100644 --- a/manager/controllers/systems_ids_test.go +++ b/manager/controllers/systems_ids_test.go @@ -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) diff --git a/manager/controllers/systems_test.go b/manager/controllers/systems_test.go index 80e8b7ab0..d4a3bb8c3 100644 --- a/manager/controllers/systems_test.go +++ b/manager/controllers/systems_test.go @@ -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) @@ -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)