Skip to content

Commit

Permalink
Add unit test for SBOM.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoogieZork committed Dec 19, 2024
1 parent f7ce72e commit da814d7
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions backend/utilities/plugin_runner/toolbox/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,50 @@ func TestValidInventory(t *testing.T) {
}
}

func TestValidSBOM(t *testing.T) {
actual := lint("sbom", []byte(`{
"success": true,
"truncated": false,
"details": [
[
{"sbom": "foo"}
],
[
{
"bom-ref": "pkg:golang/cloud.google.com/go/[email protected]",
"type": "gomod",
"name": "cloud.google.com/go/datastore",
"version": "1.1.0",
"licenses": [
{
"id": "Apache-2.0",
"name": "Apache-2.0"
}
]
}
]
],
"errors": ["failed to scan"]
}`))
if actual != nil {
t.Fatalf("expected no errors, got %v", actual)
}
}

func TestSBOMMissingValue(t *testing.T) {
actual := lint("sbom", []byte(`{
"success": true,
"truncated": false,
"details": [
[]
],
"errors": ["failed to scan"]
}`))
if !containsValidationError(actual, "/details", "minItems: got 1, want 2") {
t.Fatalf("expected required error, got %v", actual)
}
}

func TestUnknownType(t *testing.T) {
actual := lint("foo", []byte("{}"))
if actual == nil || !strings.Contains(actual.Error(), "unknown plugin type") {
Expand Down

0 comments on commit da814d7

Please sign in to comment.