mirror of
https://github.com/anchore/syft.git
synced 2026-11-05 00:46:38 +01:00
condense binary cataloger config in JSON output (#2499)
This commit is contained in:
@@ -3,8 +3,10 @@ package binary
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/anchore/packageurl-go"
|
||||
"github.com/anchore/syft/syft/cpe"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
)
|
||||
@@ -83,3 +85,46 @@ func Test_ClassifierCPEs(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassifier_MarshalJSON(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
classifier Classifier
|
||||
want string
|
||||
wantErr assert.ErrorAssertionFunc
|
||||
}{
|
||||
{
|
||||
name: "go case",
|
||||
classifier: Classifier{
|
||||
Class: "class",
|
||||
FileGlob: "glob",
|
||||
EvidenceMatcher: FileContentsVersionMatcher(".thing"),
|
||||
Package: "pkg",
|
||||
PURL: packageurl.PackageURL{
|
||||
Type: "type",
|
||||
Namespace: "namespace",
|
||||
Name: "name",
|
||||
Version: "version",
|
||||
Qualifiers: nil,
|
||||
Subpath: "subpath",
|
||||
},
|
||||
CPEs: []cpe.CPE{cpe.Must("cpe:2.3:a:some:app:*:*:*:*:*:*:*:*")},
|
||||
},
|
||||
want: `{"class":"class","fileGlob":"glob","package":"pkg","purl":"pkg:type/namespace/name@version#subpath","cpes":["cpe:2.3:a:some:app:*:*:*:*:*:*:*:*"]}`,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if tt.wantErr == nil {
|
||||
tt.wantErr = assert.NoError
|
||||
}
|
||||
cfg := tt.classifier
|
||||
got, err := cfg.MarshalJSON()
|
||||
if !tt.wantErr(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, tt.want, string(got))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user