Skip to content

Commit

Permalink
Test for lower level enrichment functions
Browse files Browse the repository at this point in the history
  • Loading branch information
garethr committed May 1, 2023
1 parent 412d61a commit 41742ea
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/enrich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"net/http"
"testing"

"github.com/snyk/parlay/ecosystems/packages"

cdx "github.com/CycloneDX/cyclonedx-go"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -90,6 +92,36 @@ func TestEnrichSBOMWithoutLicense(t *testing.T) {
assert.Equal(t, len(components), calls[`GET =~^https://packages.ecosyste.ms/api/v1/registries`])
}

func TestEnrichDescription(t *testing.T) {
component := cdx.Component{
Type: cdx.ComponentTypeLibrary,
Name: "cyclonedx-go",
Version: "v0.3.0",
}
desc := "description"
pack := packages.Package{
Description: &desc,
}
component = enrichDescription(component, &pack)
assert.Equal(t, "description", component.Description)
}

func TestEnrichLicense(t *testing.T) {
component := cdx.Component{
Type: cdx.ComponentTypeLibrary,
Name: "cyclonedx-go",
Version: "v0.3.0",
}
pack := packages.Package{
NormalizedLicenses: []string{"BSD-3-Clause"},
}
component = enrichLicense(component, &pack)
licenses := *component.Licenses

comp := cdx.LicenseChoice(cdx.LicenseChoice{Expression: "BSD-3-Clause"})
assert.Equal(t, comp, licenses[0])
}

func TestEnrichBlankSBOM(t *testing.T) {
bom := new(cdx.BOM)
bom = EnrichSBOM(bom)
Expand Down

0 comments on commit 41742ea

Please sign in to comment.