github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/format/common/spdxhelpers/originator_test.go (about)

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