Skip to content

Commit

Permalink
RHINENG-11297: support partial os filters
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy committed Jul 10, 2024
1 parent 0887e31 commit 2a7785b
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
72 changes: 72 additions & 0 deletions docs/v3/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2346,6 +2346,30 @@
"type": "string"
}
},
{
"name": "filter[osname]",
"in": "query",
"description": "Filter OS name",
"schema": {
"type": "string"
}
},
{
"name": "filter[osmajor]",
"in": "query",
"description": "Filter OS major version",
"schema": {
"type": "string"
}
},
{
"name": "filter[osminor]",
"in": "query",
"description": "Filter OS minor version",
"schema": {
"type": "string"
}
},
{
"name": "tags",
"in": "query",
Expand Down Expand Up @@ -4089,6 +4113,30 @@
"type": "string"
}
},
{
"name": "filter[osname]",
"in": "query",
"description": "Filter OS name",
"schema": {
"type": "string"
}
},
{
"name": "filter[osmajor]",
"in": "query",
"description": "Filter OS major version",
"schema": {
"type": "string"
}
},
{
"name": "filter[osminor]",
"in": "query",
"description": "Filter OS minor version",
"schema": {
"type": "string"
}
},
{
"name": "filter[satellite_managed]",
"in": "query",
Expand Down Expand Up @@ -5337,6 +5385,30 @@
"type": "string"
}
},
{
"name": "filter[osname]",
"in": "query",
"description": "Filter OS name",
"schema": {
"type": "string"
}
},
{
"name": "filter[osmajor]",
"in": "query",
"description": "Filter OS major version",
"schema": {
"type": "string"
}
},
{
"name": "filter[osminor]",
"in": "query",
"description": "Filter OS minor version",
"schema": {
"type": "string"
}
},
{
"name": "tags",
"in": "query",
Expand Down
6 changes: 6 additions & 0 deletions manager/controllers/systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ func systemsCommon(c *gin.Context) (*gorm.DB, *ListMeta, []string, error) {
// @Param filter[satellite_managed] query string false "Filter"
// @Param filter[built_pkgcache] query string false "Filter"
// @Param filter[os] query string false "Filter OS version"
// @Param filter[osname] query string false "Filter OS name"
// @Param filter[osmajor] query string false "Filter OS major version"
// @Param filter[osminor] query string false "Filter OS minor version"
// @Param tags query []string false "Tag filter"
// @Param filter[group_name] query []string false "Filter systems by inventory groups"
// @Param filter[system_profile][sap_system] query string false "Filter only SAP systems"
Expand Down Expand Up @@ -311,6 +314,9 @@ func SystemsListHandler(c *gin.Context) {
// @Param filter[created] query string false "Filter"
// @Param filter[baseline_name] query string false "Filter"
// @Param filter[os] query string false "Filter OS version"
// @Param filter[osname] query string false "Filter OS name"
// @Param filter[osmajor] query string false "Filter OS major version"
// @Param filter[osminor] query string false "Filter OS minor version"
// @Param filter[satellite_managed] query string false "Filter"
// @Param filter[built_pkgcache] query string false "Filter"
// @Param tags query []string false "Tag filter"
Expand Down
3 changes: 3 additions & 0 deletions manager/controllers/systems_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import (
// @Param filter[system_profile][mssql][version] query string false "Filter systems by mssql version"
// @Param filter[baseline_name] query string false "Filter"
// @Param filter[os] query string false "Filter OS version"
// @Param filter[osname] query string false "Filter OS name"
// @Param filter[osmajor] query string false "Filter OS major version"
// @Param filter[osminor] query string false "Filter OS minor version"
// @Param tags query []string false "Tag filter"
// @Success 200 {array} SystemDBLookup
// @Failure 415 {object} utils.ErrorResponse
Expand Down
12 changes: 12 additions & 0 deletions manager/controllers/systems_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,15 @@ func TestSystemsExportBaselineFilter(t *testing.T) {
assert.Equal(t, "00000000-0000-0000-0000-000000000001", output[0].ID)
assert.Equal(t, "00000000-0000-0000-0000-000000000002", output[1].ID)
}

func TestSystemsExportFilterPartialOS(t *testing.T) {
w := makeRequest(t, "/?filter[osname]=RHEL&filter[osmajor]=8&filter[osminor]=1", "application/json")

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

assert.Equal(t, 3, len(output))
for _, o := range output {
assert.Equal(t, "RHEL 8.1", o.OS)
}
}
8 changes: 8 additions & 0 deletions manager/controllers/systems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ func TestSystemsFilterOS(t *testing.T) {
assert.Equal(t, "RHEL 8.1", output.Data[2].Attributes.OS)
}

func TestSystemsFilterPartialOS(t *testing.T) {
output := testSystems(t, "?filter[osname]=RHEL&filter[osmajor]=8&filter[osminor]=1", 1)
assert.Equal(t, 3, len(output.Data))
for _, d := range output.Data {
assert.Equal(t, "RHEL 8.1", d.Attributes.OS)
}
}

func TestSystemsOrderOS(t *testing.T) {
output := testSystems(t, `?sort=os`, 1)
assert.Equal(t, "RHEL 7.3", output.Data[0].Attributes.OS)
Expand Down

0 comments on commit 2a7785b

Please sign in to comment.