github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/common/cpe/go_test.go (about) 1 package cpe 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestCandidateProductForGo(t *testing.T) { 10 tests := []struct { 11 pkg string 12 expected string 13 }{ 14 { 15 pkg: "github.com/someone/something", 16 expected: "something", 17 }, 18 { 19 pkg: "golang.org/x/xerrors", 20 expected: "x/xerrors", 21 }, 22 { 23 pkg: "gopkg.in/yaml.v2", 24 expected: "yaml.v2", 25 }, 26 { 27 pkg: "place", 28 expected: "", 29 }, 30 { 31 pkg: "place.com/", 32 expected: "", 33 }, 34 { 35 pkg: "place.com/someone-or-thing", 36 expected: "", 37 }, 38 { 39 pkg: "google.golang.org/genproto/googleapis/rpc/status", 40 expected: "genproto", 41 }, 42 { 43 pkg: "github.com/someone/something/long/package/name", 44 expected: "something/long/package/name", 45 }, 46 { 47 pkg: "", 48 expected: "", 49 }, 50 } 51 52 for _, test := range tests { 53 t.Run(test.pkg, func(t *testing.T) { 54 assert.Equal(t, test.expected, candidateProductForGo(test.pkg)) 55 }) 56 } 57 } 58 59 func TestCandidateVendorForGo(t *testing.T) { 60 tests := []struct { 61 pkg string 62 expected string 63 }{ 64 { 65 pkg: "github.com/someone/something", 66 expected: "someone", 67 }, 68 { 69 pkg: "golang.org/x/xerrors", 70 expected: "golang", 71 }, 72 { 73 pkg: "gopkg.in/yaml.v2", 74 expected: "", 75 }, 76 { 77 pkg: "place", 78 expected: "", 79 }, 80 { 81 pkg: "place.com/", 82 expected: "", 83 }, 84 { 85 pkg: "place.com/someone-or-thing", 86 expected: "", 87 }, 88 { 89 pkg: "google.golang.org/genproto/googleapis/rpc/status", 90 expected: "google", 91 }, 92 { 93 pkg: "github.com/someone/something/long/package/name", 94 expected: "someone", 95 }, 96 } 97 98 for _, test := range tests { 99 t.Run(test.pkg, func(t *testing.T) { 100 assert.Equal(t, test.expected, candidateVendorForGo(test.pkg)) 101 }) 102 } 103 }