From f4412ff07f59a29403448da0fabb052d8d785676 Mon Sep 17 00:00:00 2001 From: Martin Sehnoutka Date: Mon, 15 Nov 2021 15:02:21 +0100 Subject: [PATCH] osbuild2: update rhsm stage The stage now allows for customizations specific to YUM or DNF. So far it is just an alias to the same definition, meaning that composer can use exactly the same structures for both. Ref: https://github.com/osbuild/osbuild/pull/876 --- internal/osbuild2/rhsm_stage.go | 1 + internal/osbuild2/rhsm_stage_test.go | 56 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/internal/osbuild2/rhsm_stage.go b/internal/osbuild2/rhsm_stage.go index 160e6529f..9f487ea95 100644 --- a/internal/osbuild2/rhsm_stage.go +++ b/internal/osbuild2/rhsm_stage.go @@ -6,6 +6,7 @@ package osbuild2 // related components. Currently it allows only configuration of the enablement // state of DNF plugins used by the Subscription Manager. type RHSMStageOptions struct { + YumPlugins *RHSMStageOptionsDnfPlugins `json:"yum-plugins,omitempty"` DnfPlugins *RHSMStageOptionsDnfPlugins `json:"dnf-plugins,omitempty"` SubMan *RHSMStageOptionsSubMan `json:"subscription-manager,omitempty"` } diff --git a/internal/osbuild2/rhsm_stage_test.go b/internal/osbuild2/rhsm_stage_test.go index 68867c763..49b8c9136 100644 --- a/internal/osbuild2/rhsm_stage_test.go +++ b/internal/osbuild2/rhsm_stage_test.go @@ -1,9 +1,12 @@ package osbuild2 import ( + "encoding/json" + "reflect" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNewRhsmStage(t *testing.T) { @@ -14,3 +17,56 @@ func TestNewRhsmStage(t *testing.T) { actualStage := NewRHSMStage(&RHSMStageOptions{}) assert.Equal(t, expectedStage, actualStage) } + +func TestRhsmStageJson(t *testing.T) { + tests := []struct { + Options RHSMStageOptions + JsonString string + }{ + { + Options: RHSMStageOptions{ + YumPlugins: &RHSMStageOptionsDnfPlugins{ + ProductID: &RHSMStageOptionsDnfPlugin{ + Enabled: true, + }, + SubscriptionManager: &RHSMStageOptionsDnfPlugin{ + Enabled: false, + }, + }, + }, + JsonString: `{"yum-plugins":{"product-id":{"enabled":true},"subscription-manager":{"enabled":false}}}`, + }, + { + Options: RHSMStageOptions{ + DnfPlugins: &RHSMStageOptionsDnfPlugins{ + ProductID: &RHSMStageOptionsDnfPlugin{ + Enabled: true, + }, + SubscriptionManager: &RHSMStageOptionsDnfPlugin{ + Enabled: false, + }, + }, + }, + JsonString: `{"dnf-plugins":{"product-id":{"enabled":true},"subscription-manager":{"enabled":false}}}`, + }, + { + Options: RHSMStageOptions{ + SubMan: &RHSMStageOptionsSubMan{ + Rhsm: &SubManConfigRHSMSection{}, + Rhsmcertd: &SubManConfigRHSMCERTDSection{}, + }, + }, + JsonString: `{"subscription-manager":{"rhsm":{},"rhsmcertd":{}}}`, + }, + } + for _, test := range tests { + marshaledJson, err := json.Marshal(test.Options) + require.NoError(t, err, "failed to marshal JSON") + require.Equal(t, string(marshaledJson), test.JsonString) + + var jsonOptions RHSMStageOptions + err = json.Unmarshal([]byte(test.JsonString), &jsonOptions) + require.NoError(t, err, "failed to parse JSON") + require.True(t, reflect.DeepEqual(test.Options, jsonOptions)) + } +}