github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/cpe/merge_cpes_test.go (about) 1 package cpe 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_Merge(t *testing.T) { 10 tests := []struct { 11 name string 12 input [][]CPE 13 expected []CPE 14 }{ 15 { 16 name: "merge, removing duplicates and ordered", 17 input: [][]CPE{ 18 { 19 Must("cpe:2.3:a:*:package:1:*:*:*:*:*:*:*", NVDDictionaryLookupSource), 20 Must("cpe:2.3:a:*:package:1:*:*:*:*:*:*:*", DeclaredSource), 21 Must("cpe:2.3:a:some:package:*:*:*:*:*:*:*:*", GeneratedSource), 22 }, 23 { 24 Must("cpe:2.3:a:some:package:1:*:*:*:*:*:*:*", DeclaredSource), 25 Must("cpe:2.3:a:some:package:*:*:*:*:*:*:*:*", GeneratedSource), 26 }, 27 }, 28 expected: []CPE{ 29 Must("cpe:2.3:a:*:package:1:*:*:*:*:*:*:*", NVDDictionaryLookupSource), 30 Must("cpe:2.3:a:some:package:1:*:*:*:*:*:*:*", DeclaredSource), 31 Must("cpe:2.3:a:*:package:1:*:*:*:*:*:*:*", DeclaredSource), 32 Must("cpe:2.3:a:some:package:*:*:*:*:*:*:*:*", GeneratedSource), 33 }, 34 }, 35 } 36 37 for _, test := range tests { 38 t.Run(test.name, func(t *testing.T) { 39 out := Merge(test.input[0], test.input[1]) 40 assert.Equal(t, test.expected, out) 41 }) 42 } 43 }