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)) + } +}