github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/formats/common/spdxhelpers/originator_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_Originator(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 gem", 24 input: pkg.Package{ 25 Metadata: pkg.GemMetadata{ 26 Authors: []string{ 27 "auth1", 28 "auth2", 29 }, 30 }, 31 }, 32 expected: "Person: auth1", 33 }, 34 { 35 name: "from npm", 36 input: pkg.Package{ 37 Metadata: pkg.NpmPackageJSONMetadata{ 38 Author: "auth", 39 }, 40 }, 41 expected: "Person: auth", 42 }, 43 { 44 name: "from apk", 45 input: pkg.Package{ 46 Metadata: pkg.ApkMetadata{ 47 Maintainer: "auth", 48 }, 49 }, 50 expected: "Person: auth", 51 }, 52 { 53 name: "from python - just name", 54 input: pkg.Package{ 55 Metadata: pkg.PythonPackageMetadata{ 56 Author: "auth", 57 }, 58 }, 59 expected: "Person: auth", 60 }, 61 { 62 name: "from python - just email", 63 input: pkg.Package{ 64 Metadata: pkg.PythonPackageMetadata{ 65 AuthorEmail: "auth@auth.gov", 66 }, 67 }, 68 expected: "Person: auth@auth.gov", 69 }, 70 { 71 name: "from python - both name and email", 72 input: pkg.Package{ 73 Metadata: pkg.PythonPackageMetadata{ 74 Author: "auth", 75 AuthorEmail: "auth@auth.gov", 76 }, 77 }, 78 expected: "Person: auth (auth@auth.gov)", 79 }, 80 { 81 name: "from rpm", 82 input: pkg.Package{ 83 Metadata: pkg.RpmMetadata{ 84 Vendor: "auth", 85 }, 86 }, 87 expected: "Organization: auth", 88 }, 89 { 90 name: "from dpkg", 91 input: pkg.Package{ 92 Metadata: pkg.DpkgMetadata{ 93 Maintainer: "auth", 94 }, 95 }, 96 expected: "Person: auth", 97 }, 98 { 99 // note: since this is an optional field, no value is preferred over NONE or NOASSERTION 100 name: "empty", 101 input: pkg.Package{ 102 Metadata: pkg.NpmPackageJSONMetadata{ 103 Author: "", 104 }, 105 }, 106 expected: "", 107 }, 108 } 109 for _, test := range tests { 110 t.Run(test.name, func(t *testing.T) { 111 typ, value := Originator(test.input) 112 if typ != "" { 113 value = typ + ": " + value 114 } 115 assert.Equal(t, test.expected, value) 116 }) 117 } 118 }