Skip to content

Commit

Permalink
Merge pull request #108 from kubescape/fix/metadata-type
Browse files Browse the repository at this point in the history
Fix MetadataType in artifacts
  • Loading branch information
David Wertenteil authored Apr 10, 2024
2 parents d0ee88d + 1a921cf commit 74572f3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/apis/softwarecomposition/syfttypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func unpackPkgMetadata(p *SyftPackage, unpacker packageMetadataUnpacker) error {
ty = "rust-cargo-audit-entry"
}
}
p.MetadataType = ty

typ := packagemetadata.ReflectTypeFromJSONName(ty)
if typ == nil {
Expand Down
41 changes: 41 additions & 0 deletions pkg/apis/softwarecomposition/syfttypes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package softwarecomposition

import (
"testing"

_ "embed"

"github.com/stretchr/testify/assert"
)

//go:embed testdata/artifact.json
var artifact []byte

func TestUpdateSBOMSyft(t *testing.T) {
type args struct {
id string
metadataType string
}
tests := []struct {
name string
input []byte
args args
wantErr bool
}{
{
name: "TestUpdateSBOMSyft",
input: artifact,
args: args{id: "8a49897e59f569c2", metadataType: "dpkg-db-entry"},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := SyftPackage{}
err := c.UnmarshalJSON(tt.input)
assert.NoError(t, err)
assert.Equal(t, c.ID, tt.args.id)
assert.Equal(t, c.MetadataType, tt.args.metadataType)
})
}
}
1 change: 1 addition & 0 deletions pkg/apis/softwarecomposition/v1beta1/syfttypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func unpackPkgMetadata(p *SyftPackage, unpacker packageMetadataUnpacker) error {
ty = "rust-cargo-audit-entry"
}
}
p.MetadataType = ty

typ := packagemetadata.ReflectTypeFromJSONName(ty)
if typ == nil {
Expand Down

0 comments on commit 74572f3

Please sign in to comment.