From 24cd02892d6411d6aba0f5bb4cfe085b002a2a79 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Mon, 29 Jul 2024 13:36:45 +0100 Subject: [PATCH] pkg/osbuild: remediation stage options tests Add some new test cases to make sure that the remediation stage options are set correctly when tailoring options have been specified. --- pkg/osbuild/oscap_remediation_stage_test.go | 62 +++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/pkg/osbuild/oscap_remediation_stage_test.go b/pkg/osbuild/oscap_remediation_stage_test.go index 1cd68e32bf..8ca3af33fb 100644 --- a/pkg/osbuild/oscap_remediation_stage_test.go +++ b/pkg/osbuild/oscap_remediation_stage_test.go @@ -3,6 +3,7 @@ package osbuild import ( "testing" + "github.com/osbuild/images/pkg/customizations/oscap" "github.com/stretchr/testify/assert" ) @@ -85,3 +86,64 @@ func TestOscapRemediationStageOptionsValidate(t *testing.T) { }) } } + +func TestInternalConfigToStageOptions(t *testing.T) { + tests := []struct { + name string + options *oscap.RemediationConfig + expected OscapConfig + }{ + { + name: "no-tailoring", + options: &oscap.RemediationConfig{ + ProfileID: "some-profile", + Datastream: "some-datastream", + }, + expected: OscapConfig{ + ProfileID: "some-profile", + Datastream: "some-datastream", + }, + }, + { + name: "tailoring", + options: &oscap.RemediationConfig{ + ProfileID: "some-profile", + Datastream: "some-datastream", + TailoringConfig: &oscap.TailoringConfig{ + TailoredProfileID: "some-tailored-profile", + TailoringPath: "/some/tailoring/path.xml", + Selected: []string{"one", "two", "three"}, + }, + }, + expected: OscapConfig{ + ProfileID: "some-tailored-profile", + Datastream: "some-datastream", + Tailoring: "/some/tailoring/path.xml", + }, + }, + { + name: "json-tailoring", + options: &oscap.RemediationConfig{ + ProfileID: "some-profile", + Datastream: "some-datastream", + TailoringConfig: &oscap.TailoringConfig{ + TailoredProfileID: "some-tailored-profile", + TailoringPath: "/some/tailoring/path.xml", + JSONFilepath: "/some/tailoring/path.json", + }, + }, + expected: OscapConfig{ + ProfileID: "some-tailored-profile", + Datastream: "some-datastream", + Tailoring: "/some/tailoring/path.xml", + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + stageOptions := NewOscapRemediationStageOptions("data-dir", tt.options) + assert.Equal(t, tt.expected, stageOptions.Config) + }) + } +}