github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/format/common/spdxhelpers/external_refs_test.go (about)

     1  package spdxhelpers
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/anchore/syft/syft/cpe"
     9  	"github.com/anchore/syft/syft/pkg"
    10  )
    11  
    12  func Test_ExternalRefs(t *testing.T) {
    13  	testCPE := cpe.Must("cpe:2.3:a:name:name:3.2:*:*:*:*:*:*:*")
    14  	tests := []struct {
    15  		name     string
    16  		input    pkg.Package
    17  		expected []ExternalRef
    18  	}{
    19  		{
    20  			name: "cpe + purl",
    21  			input: pkg.Package{
    22  				CPEs: []cpe.CPE{
    23  					testCPE,
    24  				},
    25  				PURL: "a-purl",
    26  			},
    27  			expected: []ExternalRef{
    28  				{
    29  					ReferenceCategory: SecurityReferenceCategory,
    30  					ReferenceLocator:  cpe.String(testCPE),
    31  					ReferenceType:     Cpe23ExternalRefType,
    32  				},
    33  				{
    34  					ReferenceCategory: PackageManagerReferenceCategory,
    35  					ReferenceLocator:  "a-purl",
    36  					ReferenceType:     PurlExternalRefType,
    37  				},
    38  			},
    39  		},
    40  	}
    41  	for _, test := range tests {
    42  		t.Run(test.name, func(t *testing.T) {
    43  			assert.ElementsMatch(t, test.expected, ExternalRefs(test.input))
    44  		})
    45  	}
    46  }