github.com/anchore/syft@v1.38.2/test/cli/license_test.go (about) 1 package cli 2 3 import "testing" 4 5 func Test_Licenses(t *testing.T) { 6 testImage := getFixtureImage(t, "image-pkg-coverage") 7 tests := []struct { 8 name string 9 args []string 10 env map[string]string 11 assertions []traitAssertion 12 }{ 13 { 14 name: "licenses default with no content", 15 args: []string{"scan", "-o", "json", testImage, "--from", "docker-archive"}, 16 env: map[string]string{"SYFT_FORMAT_PRETTY": "true"}, 17 assertions: []traitAssertion{ 18 assertJsonReport, 19 assertUnknownLicenseContent(false), 20 assertSuccessfulReturnCode, 21 }, 22 }, 23 // deprecated LICENSE_INCLUDE_UNKNOWN_LICENSE_CONTENT 24 { 25 name: "licenses with content works without deprecated LICENSE_INCLUDE_UNKNOWN_LICENSE_CONTENT", 26 args: []string{"scan", "-o", "json", testImage, "--from", "docker-archive"}, 27 env: map[string]string{"SYFT_FORMAT_PRETTY": "true", "SYFT_LICENSE_INCLUDE_UNKNOWN_LICENSE_CONTENT": "true"}, 28 assertions: []traitAssertion{ 29 assertJsonReport, 30 assertUnknownLicenseContent(true), 31 assertSuccessfulReturnCode, 32 }, 33 }, 34 // use new license content configuration 35 { 36 name: "licenses with content works with new CONTENT configuration", 37 args: []string{"scan", "-o", "json", testImage, "--from", "docker-archive"}, 38 env: map[string]string{"SYFT_FORMAT_PRETTY": "true", "SYFT_LICENSE_CONTENT": "unknown"}, 39 assertions: []traitAssertion{ 40 assertJsonReport, 41 assertUnknownLicenseContent(true), 42 assertSuccessfulReturnCode, 43 }, 44 }, 45 } 46 47 for _, test := range tests { 48 t.Run(test.name, func(t *testing.T) { 49 cmd, stdout, stderr := runSyft(t, test.env, test.args...) 50 for _, traitFn := range test.assertions { 51 traitFn(t, stdout, stderr, cmd.ProcessState.ExitCode()) 52 } 53 logOutputOnFailure(t, cmd, stdout, stderr) 54 }) 55 } 56 }