From 41742eace458e31910a232d2047920f46eff359c Mon Sep 17 00:00:00 2001 From: Gareth Rushgrove Date: Mon, 1 May 2023 07:08:15 +0100 Subject: [PATCH] Test for lower level enrichment functions --- lib/enrich_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/enrich_test.go b/lib/enrich_test.go index 48f7a98..0f1df9c 100644 --- a/lib/enrich_test.go +++ b/lib/enrich_test.go @@ -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" @@ -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)