Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MetadataType in artifacts #108

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check failure on line 11 in pkg/apis/softwarecomposition/syfttypes_test.go

View workflow job for this annotation

GitHub Actions / pr-created / test / Create cross-platform build

pattern testdata/artifact.json: no matching files found

Check failure on line 11 in pkg/apis/softwarecomposition/syfttypes_test.go

View workflow job for this annotation

GitHub Actions / pr-merged / docker-build

pattern testdata/artifact.json: no matching files found
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
Loading