github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/format/common/cyclonedxhelpers/author_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_encodeAuthor(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 gem", 25 input: pkg.Package{ 26 Metadata: pkg.RubyGemspec{ 27 Authors: []string{ 28 "auth1", 29 "auth2", 30 }, 31 }, 32 }, 33 expected: "auth1,auth2", 34 }, 35 { 36 name: "from npm", 37 input: pkg.Package{ 38 Metadata: pkg.NpmPackage{ 39 Author: "auth", 40 }, 41 }, 42 expected: "auth", 43 }, 44 { 45 name: "from python - just name", 46 input: pkg.Package{ 47 Metadata: pkg.PythonPackage{ 48 Author: "auth", 49 }, 50 }, 51 expected: "auth", 52 }, 53 { 54 name: "from python - just email", 55 input: pkg.Package{ 56 Metadata: pkg.PythonPackage{ 57 AuthorEmail: "auth@auth.gov", 58 }, 59 }, 60 expected: "auth@auth.gov", 61 }, 62 { 63 name: "from python - both name and email", 64 input: pkg.Package{ 65 Metadata: pkg.PythonPackage{ 66 Author: "auth", 67 AuthorEmail: "auth@auth.gov", 68 }, 69 }, 70 expected: "auth <auth@auth.gov>", 71 }, 72 { 73 // note: since this is an optional field, no value is preferred over NONE or NOASSERTION 74 name: "empty", 75 input: pkg.Package{ 76 Metadata: pkg.NpmPackage{ 77 Author: "", 78 }, 79 }, 80 expected: "", 81 }, 82 } 83 for _, test := range tests { 84 t.Run(test.name, func(t *testing.T) { 85 assert.Equal(t, test.expected, encodeAuthor(test.input)) 86 }) 87 } 88 }