github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/common/spdxhelpers/download_location_test.go (about) 1 package spdxhelpers 2 3 import ( 4 "testing" 5 6 "github.com/nextlinux/gosbom/gosbom/pkg" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func Test_DownloadLocation(t *testing.T) { 11 tests := []struct { 12 name string 13 input pkg.Package 14 expected string 15 }{ 16 { 17 name: "no metadata", 18 input: pkg.Package{}, 19 expected: NOASSERTION, 20 }, 21 { 22 name: "from apk", 23 input: pkg.Package{ 24 Metadata: pkg.ApkMetadata{ 25 URL: "http://a-place.gov", 26 }, 27 }, 28 expected: "http://a-place.gov", 29 }, 30 { 31 name: "from npm", 32 input: pkg.Package{ 33 Metadata: pkg.NpmPackageJSONMetadata{ 34 URL: "http://a-place.gov", 35 }, 36 }, 37 expected: "http://a-place.gov", 38 }, 39 { 40 name: "empty", 41 input: pkg.Package{ 42 Metadata: pkg.NpmPackageJSONMetadata{ 43 URL: "", 44 }, 45 }, 46 expected: NONE, 47 }, 48 } 49 for _, test := range tests { 50 t.Run(test.name, func(t *testing.T) { 51 assert.Equal(t, test.expected, DownloadLocation(test.input)) 52 }) 53 } 54 }