From 62f57ea0a8fa828ab2620ebbd73b72abc093d464 Mon Sep 17 00:00:00 2001 From: Ondrej Ezr Date: Tue, 2 Jan 2024 19:50:38 +0100 Subject: [PATCH] test: weldr api module_hotfixes flag --- internal/client/blueprints_test.go | 59 ++++++++++++++++++++++++++++++ internal/weldr/json.go | 12 ++++++ 2 files changed, 71 insertions(+) diff --git a/internal/client/blueprints_test.go b/internal/client/blueprints_test.go index 2fb35c59e5b..30bb9928b24 100644 --- a/internal/client/blueprints_test.go +++ b/internal/client/blueprints_test.go @@ -14,6 +14,7 @@ import ( "encoding/json" "fmt" "os/exec" + "runtime" "sort" "strconv" "strings" @@ -1006,6 +1007,64 @@ func TestBlueprintDepsolveGlobsV0(t *testing.T) { assert.True(t, common.IsStringInSortedSlice(names, "tmux")) } +// depsolve a blueprint with package from 3rd party with module_hotfixes +func TestBlueprintDepsolveModuleHotfixesV0(t *testing.T) { + // Depends on real packages, only run as an integration test + if testState.unitTest { + t.Skip() + } + var repo string + switch runtime.GOARCH { + case "amd64": + repo = "https://rpmrepo.osbuild.org/v2/mirror/public/el8/el8-x86_64-nginx-20231207" + case "arm64": + repo = "https://rpmrepo.osbuild.org/v2/mirror/public/el8/el8-aarch64-nginx-20231207" + default: + // We don't know how to test for another architectures :) + t.Skip() + } + + source := fmt.Sprintf(`{ + "id": "nginx", + "name": "nginx disabled modularity filtering", + "url": "%s", + "type": "yum-baseurl", + "check_gpg": true, + "gpgkeys": ["https://nginx.org/keys/nginx_signing.key"], + "module_hotfixes": true + }`, repo) + + respSource, err := PostJSONSourceV1(testState.socket, source) + require.NoError(t, err, "POST source failed with a client error") + require.True(t, respSource.Status, "POST blueprint failed: %#v", respSource) + + bp := `{ + "name": "test-deps-blueprint-module-hotfixes-v0", + "description": "CheckBlueprintDepsolveModuleHotfixesV0", + "version": "0.0.1", + "packages": [{"name": "nginx", "version": "*"}, + {"name": "nginx-module-njs", "version": "*"}] + }` + t.Log(bp) + + // Push a blueprint + resp, err := PostJSONBlueprintV0(testState.socket, bp) + require.NoError(t, err, "POST blueprint failed with a client error") + require.True(t, resp.Status, "POST blueprint failed: %#v", resp) + + // Depsolve the blueprint + deps, api, err := DepsolveBlueprintV0(testState.socket, "test-deps-blueprint-module-hotfixes-v0") + require.NoError(t, err, "Depsolve blueprint failed with a client error") + require.Nil(t, api, "DepsolveBlueprint failed: %#v", api) + require.Equal(t, 0, len(deps.Errors), "Errors occurred during depsolving") + require.Greater(t, len(deps.Blueprints), 0, "No blueprint dependencies returned") + + // cleanup the repo + resp, err = DeleteSourceV1(testState.socket, "nginx") + require.NoError(t, err, "DELETE source failed with a client error") + require.True(t, resp.Status, "DELETE source failed: %#v", resp) +} + // depsolve a non-existent blueprint func TestNonBlueprintDepsolveV0(t *testing.T) { resp, api, err := DepsolveBlueprintV0(testState.socket, "test-deps-non-blueprint-v0") diff --git a/internal/weldr/json.go b/internal/weldr/json.go index 6e96b917a88..9222cf2b066 100644 --- a/internal/weldr/json.go +++ b/internal/weldr/json.go @@ -170,6 +170,10 @@ func (s SourceConfigV0) SourceConfig() (ssc store.SourceConfig) { ssc.URL = s.URL ssc.CheckGPG = s.CheckGPG ssc.CheckSSL = s.CheckSSL + if s.ModuleHotfixes != nil { + modHotfixesVal := *s.ModuleHotfixes + ssc.ModuleHotfixes = &modHotfixesVal + } return ssc } @@ -196,6 +200,10 @@ func NewSourceConfigV1(id string, s store.SourceConfig) SourceConfigV1 { sc.RHSM = s.RHSM sc.CheckRepoGPG = s.CheckRepoGPG sc.GPGKeys = s.GPGKeys + if s.ModuleHotfixes != nil { + modHotfixesVal := *s.ModuleHotfixes + sc.ModuleHotfixes = &modHotfixesVal + } return sc } @@ -244,6 +252,10 @@ func (s SourceConfigV1) SourceConfig() (ssc store.SourceConfig) { ssc.RHSM = s.RHSM ssc.CheckRepoGPG = s.CheckRepoGPG ssc.GPGKeys = s.GPGKeys + if s.ModuleHotfixes != nil { + modHotfixesVal := *s.ModuleHotfixes + ssc.ModuleHotfixes = &modHotfixesVal + } return ssc }