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:
Christopher Angelo Phillips
2025-02-05 20:41:03 +00:00
committed by GitHub
parent 7bab6e9851
commit e584c9f416
25 changed files with 436 additions and 98 deletions
+31
View File
@@ -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 {