Skip to content

Commit

Permalink
pkg/osbuild: remediation stage options tests
Browse files Browse the repository at this point in the history
Add some new test cases to make sure that the remediation stage options
are set correctly when tailoring options have been specified.
  • Loading branch information
kingsleyzissou authored and achilleas-k committed Aug 1, 2024
1 parent 7cc2db4 commit 24cd028
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions pkg/osbuild/oscap_remediation_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package osbuild
import (
"testing"

"github.com/osbuild/images/pkg/customizations/oscap"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -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)
})
}
}

0 comments on commit 24cd028

Please sign in to comment.