mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
add case to decode GolangBinMetadata for syftjson model (#901)
Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
This commit is contained in:
parent
752b03b2d6
commit
4231f38fa2
@ -124,6 +124,11 @@ func (p *Package) UnmarshalJSON(b []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.Metadata = payload
|
p.Metadata = payload
|
||||||
|
case pkg.GolangBinMetadataType:
|
||||||
|
var payload pkg.GolangBinMetadata
|
||||||
|
if err := json.Unmarshal(unpacker.Metadata, &payload); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
log.Warnf("unknown package metadata type=%q for packageID=%q", p.MetadataType, p.ID)
|
log.Warnf("unknown package metadata type=%q for packageID=%q", p.MetadataType, p.ID)
|
||||||
}
|
}
|
||||||
|
|||||||
52
internal/formats/syftjson/model/package_test.go
Normal file
52
internal/formats/syftjson/model/package_test.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestUnmarshalPackage(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
p *Package
|
||||||
|
packageData []byte
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Package.UnmarshalJSON will unmarshal blank json",
|
||||||
|
p: &Package{},
|
||||||
|
packageData: []byte(`{}`),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Package.UnmarshalJSON unmarshals PackageBasicData",
|
||||||
|
p: &Package{},
|
||||||
|
packageData: []byte(`{
|
||||||
|
"id": "8b594519bc23da50",
|
||||||
|
"name": "gopkg.in/square/go-jose.v2",
|
||||||
|
"version": "v2.6.0",
|
||||||
|
"type": "go-module",
|
||||||
|
"foundBy": "go-module-binary-cataloger",
|
||||||
|
"locations": [
|
||||||
|
{
|
||||||
|
"path": "/Users/hal/go/bin/syft"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"licenses": [],
|
||||||
|
"language": "go",
|
||||||
|
"cpes": [],
|
||||||
|
"purl": "pkg:golang/gopkg.in/square/go-jose.v2@v2.6.0",
|
||||||
|
"metadataType": "GolangBinMetadata",
|
||||||
|
"metadata": {
|
||||||
|
"goCompiledVersion": "go1.18",
|
||||||
|
"architecture": "amd64",
|
||||||
|
"h1Digest": "h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI="
|
||||||
|
}
|
||||||
|
}`),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
err := test.p.UnmarshalJSON(test.packageData)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not unmarshal packageData: %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user