github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/format/common/cyclonedxhelpers/description_test.go (about) 1 package cyclonedxhelpers 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/anchore/syft/syft/pkg" 9 ) 10 11 func Test_encodeDescription(t *testing.T) { 12 tests := []struct { 13 name string 14 input pkg.Package 15 expected string 16 }{ 17 { 18 // note: since this is an optional field, no value is preferred over NONE or NOASSERTION 19 name: "no metadata", 20 input: pkg.Package{}, 21 expected: "", 22 }, 23 { 24 name: "from apk", 25 input: pkg.Package{ 26 Metadata: pkg.ApkDBEntry{ 27 Description: "a description!", 28 }, 29 }, 30 expected: "a description!", 31 }, 32 { 33 name: "from npm", 34 input: pkg.Package{ 35 Metadata: pkg.NpmPackage{ 36 Description: "a description!", 37 }, 38 }, 39 expected: "a description!", 40 }, 41 { 42 // note: since this is an optional field, no value is preferred over NONE or NOASSERTION 43 name: "empty", 44 input: pkg.Package{ 45 Metadata: pkg.NpmPackage{ 46 Homepage: "", 47 }, 48 }, 49 expected: "", 50 }, 51 } 52 for _, test := range tests { 53 t.Run(test.name, func(t *testing.T) { 54 assert.Equal(t, test.expected, encodeDescription(test.input)) 55 }) 56 } 57 }