github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/common/spdxhelpers/external_refs_test.go (about)

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