github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/common/cyclonedxhelpers/publisher_test.go (about) 1 package cyclonedxhelpers 2 3 import ( 4 "testing" 5 6 "github.com/nextlinux/gosbom/gosbom/pkg" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func Test_encodePublisher(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 Maintainer: "auth", 27 }, 28 }, 29 expected: "auth", 30 }, 31 { 32 name: "from rpm", 33 input: pkg.Package{ 34 Metadata: pkg.RpmMetadata{ 35 Vendor: "auth", 36 }, 37 }, 38 expected: "auth", 39 }, 40 { 41 name: "from dpkg", 42 input: pkg.Package{ 43 Metadata: pkg.DpkgMetadata{ 44 Maintainer: "auth", 45 }, 46 }, 47 expected: "auth", 48 }, 49 { 50 // note: since this is an optional field, no value is preferred over NONE or NOASSERTION 51 name: "empty", 52 input: pkg.Package{ 53 Metadata: pkg.NpmPackageJSONMetadata{ 54 Author: "", 55 }, 56 }, 57 expected: "", 58 }, 59 } 60 for _, test := range tests { 61 t.Run(test.name, func(t *testing.T) { 62 assert.Equal(t, test.expected, encodePublisher(test.input)) 63 }) 64 } 65 }