syft/test/cli/license_test.go
Christopher Angelo Phillips e584c9f416
feat: 3626 add option enable license content; disable by default (#3631)
---------
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
2025-02-05 20:41:03 +00:00

46 lines
1.2 KiB
Go

package cli
import "testing"
func Test_Licenses(t *testing.T) {
testImage := getFixtureImage(t, "image-unknown-licenses")
tests := []struct {
name string
args []string
env map[string]string
assertions []traitAssertion
}{
{
name: "licenses default with no content",
args: []string{"scan", "-o", "json", testImage, "--from", "docker-archive"},
env: map[string]string{"SYFT_FORMAT_PRETTY": "true"},
assertions: []traitAssertion{
assertJsonReport,
assertUnknownLicenseContent(false),
assertSuccessfulReturnCode,
},
},
{
name: "licenses with content",
args: []string{"scan", "-o", "json", testImage, "--from", "docker-archive"},
env: map[string]string{"SYFT_FORMAT_PRETTY": "true", "SYFT_LICENSE_INCLUDE_UNKNOWN_LICENSE_CONTENT": "true"},
assertions: []traitAssertion{
assertJsonReport,
assertUnknownLicenseContent(true),
assertSuccessfulReturnCode,
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd, stdout, stderr := runSyft(t, test.env, test.args...)
for _, traitFn := range test.assertions {
traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode())
}
logOutputOnFailure(t, cmd, stdout, stderr)
})
}
}