mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
Introduce a single SBOM document (#606)
* [wip] single sbom doc Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix more tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update cli tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove scope in import path Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * swap SPDX tag-value formatter to single sbom document Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * bust CLI cache Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update fixture to byte diff Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * byte for byte Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * bust the cache Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * who needs cache Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * add jar for testing Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * no more bit flips Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * update apk with the delta for image and directory cases Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * restore cache workflow Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> Co-authored-by: Christopher Angelo Phillips <christopher.phillips@anchore.com>
This commit is contained in:
co-authored by
Christopher Angelo Phillips
parent
6d0ee326d8
commit
bb0f35bac4
@@ -3,8 +3,6 @@ package cli
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/anchore/syft/syft/source"
|
||||
)
|
||||
|
||||
func TestPackagesCmdFlags(t *testing.T) {
|
||||
@@ -30,7 +28,6 @@ func TestPackagesCmdFlags(t *testing.T) {
|
||||
args: []string{"packages", "-o", "json", request},
|
||||
assertions: []traitAssertion{
|
||||
assertJsonReport,
|
||||
assertScope(source.SquashedScope),
|
||||
assertSuccessfulReturnCode,
|
||||
},
|
||||
},
|
||||
@@ -65,7 +62,7 @@ func TestPackagesCmdFlags(t *testing.T) {
|
||||
name: "squashed-scope-flag",
|
||||
args: []string{"packages", "-o", "json", "-s", "squashed", request},
|
||||
assertions: []traitAssertion{
|
||||
assertScope(source.SquashedScope),
|
||||
assertPackageCount(17),
|
||||
assertSuccessfulReturnCode,
|
||||
},
|
||||
},
|
||||
@@ -73,18 +70,18 @@ func TestPackagesCmdFlags(t *testing.T) {
|
||||
name: "all-layers-scope-flag",
|
||||
args: []string{"packages", "-o", "json", "-s", "all-layers", request},
|
||||
assertions: []traitAssertion{
|
||||
assertScope(source.AllLayersScope),
|
||||
assertPackageCount(19),
|
||||
assertSuccessfulReturnCode,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "packages-scope-env-binding",
|
||||
name: "all-layers-scope-flag-by-env",
|
||||
args: []string{"packages", "-o", "json", request},
|
||||
env: map[string]string{
|
||||
"SYFT_PACKAGE_CATALOGER_SCOPE": "all-layers",
|
||||
},
|
||||
args: []string{"packages", "-o", "json", request},
|
||||
assertions: []traitAssertion{
|
||||
assertScope(source.AllLayersScope),
|
||||
assertPackageCount(19),
|
||||
assertSuccessfulReturnCode,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -80,6 +80,24 @@ func assertStdoutLengthGreaterThan(length uint) traitAssertion {
|
||||
tb.Helper()
|
||||
if uint(len(stdout)) < length {
|
||||
tb.Errorf("not enough output (expected at least %d, got %d)", length, len(stdout))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func assertPackageCount(length uint) traitAssertion {
|
||||
return func(tb testing.TB, stdout, _ string, _ int) {
|
||||
tb.Helper()
|
||||
type partial struct {
|
||||
Artifacts []interface{} `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)
|
||||
}
|
||||
|
||||
if uint(len(data.Artifacts)) != length {
|
||||
tb.Errorf("expected package count of %d, but found %d", length, len(data.Artifacts))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user