Skip to content

Commit

Permalink
fix(sbom): use package UIDs for uniqueness (#7042)
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 authored Jun 28, 2024
1 parent edc556b commit 14d71ba
Show file tree
Hide file tree
Showing 11 changed files with 1,483 additions and 131 deletions.
69 changes: 69 additions & 0 deletions integration/convert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//go:build integration

package integration

import (
"path/filepath"
"testing"

"github.com/aquasecurity/trivy/pkg/types"
)

func TestConvert(t *testing.T) {
type args struct {
input string
format string
scanners string
}
tests := []struct {
name string
args args
golden string
override OverrideFunc
}{
{
name: "npm",
args: args{
input: "testdata/npm.json.golden",
format: "cyclonedx",
},
golden: "testdata/npm-cyclonedx.json.golden",
},
{
name: "npm without package UID",
args: args{
input: "testdata/fixtures/convert/npm.json.golden",
format: "cyclonedx",
},
golden: "testdata/npm-cyclonedx.json.golden",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
osArgs := []string{
"convert",
"--cache-dir",
t.TempDir(),
"-q",
"--format",
tt.args.format,
}

// Set up the output file
outputFile := filepath.Join(t.TempDir(), "output.json")
if *update {
outputFile = tt.golden
}

osArgs = append(osArgs, "--output", outputFile)
osArgs = append(osArgs, tt.args.input)

// Run "trivy convert"
runTest(t, osArgs, tt.golden, outputFile, types.Format(tt.args.format), runOptions{
fakeUUID: "3ff14136-e09f-4df9-80ea-%012d",
})
})
}

}
Loading

0 comments on commit 14d71ba

Please sign in to comment.