mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
feat: 3626 add option enable license content; disable by default (#3631)
--------- Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/acarl005/stripansi"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/anchore/syft/syft/format/syftjson/model"
|
||||
)
|
||||
|
||||
type traitAssertion func(tb testing.TB, stdout, stderr string, rc int)
|
||||
@@ -148,6 +151,34 @@ func assertPackageCount(length uint) traitAssertion {
|
||||
}
|
||||
}
|
||||
|
||||
func assertUnknownLicenseContent(required bool) traitAssertion {
|
||||
return func(tb testing.TB, stdout, _ string, _ int) {
|
||||
tb.Helper()
|
||||
type NameAndLicense struct {
|
||||
Name string `json:"name"`
|
||||
Licenses []model.License `json:"Licenses"`
|
||||
}
|
||||
type partial struct {
|
||||
Artifacts []NameAndLicense `json:"artifacts"`
|
||||
}
|
||||
|
||||
var data partial
|
||||
if err := json.Unmarshal([]byte(stdout), &data); err != nil {
|
||||
tb.Errorf("expected to find a JSON report, but was unmarshalable: %+v", err)
|
||||
}
|
||||
|
||||
for _, pkg := range data.Artifacts {
|
||||
for _, lic := range pkg.Licenses {
|
||||
if strings.Contains(lic.SPDXExpression, "UNKNOWN") && required {
|
||||
assert.NotZero(tb, len(lic.Contents))
|
||||
} else {
|
||||
assert.Empty(tb, lic.Contents)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertFailingReturnCode(tb testing.TB, _, _ string, rc int) {
|
||||
tb.Helper()
|
||||
if rc == 0 {
|
||||
|
||||
Reference in New Issue
Block a user