github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/common/spdxhelpers/description_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_Description(t *testing.T) { 11 tests := []struct { 12 name string 13 input pkg.Package 14 expected string 15 }{ 16 { 17 // note: since this is an optional field, no value is preferred over NONE or NOASSERTION 18 name: "no metadata", 19 input: pkg.Package{}, 20 expected: "", 21 }, 22 { 23 name: "from apk", 24 input: pkg.Package{ 25 Metadata: pkg.ApkMetadata{ 26 Description: "a description!", 27 }, 28 }, 29 expected: "a description!", 30 }, 31 { 32 name: "from npm", 33 input: pkg.Package{ 34 Metadata: pkg.NpmPackageJSONMetadata{ 35 Description: "a description!", 36 }, 37 }, 38 expected: "a description!", 39 }, 40 { 41 // note: since this is an optional field, no value is preferred over NONE or NOASSERTION 42 name: "empty", 43 input: pkg.Package{ 44 Metadata: pkg.NpmPackageJSONMetadata{ 45 Homepage: "", 46 }, 47 }, 48 expected: "", 49 }, 50 } 51 for _, test := range tests { 52 t.Run(test.name, func(t *testing.T) { 53 assert.Equal(t, test.expected, Description(test.input)) 54 }) 55 } 56 }