github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/format/common/cyclonedxhelpers/publisher_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_encodePublisher(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 apk",
    25  			input: pkg.Package{
    26  				Metadata: pkg.ApkDBEntry{
    27  					Maintainer: "auth",
    28  				},
    29  			},
    30  			expected: "auth",
    31  		},
    32  		{
    33  			name: "from rpm",
    34  			input: pkg.Package{
    35  				Metadata: pkg.RpmDBEntry{
    36  					Vendor: "auth",
    37  				},
    38  			},
    39  			expected: "auth",
    40  		},
    41  		{
    42  			name: "from dpkg",
    43  			input: pkg.Package{
    44  				Metadata: pkg.DpkgDBEntry{
    45  					Maintainer: "auth",
    46  				},
    47  			},
    48  			expected: "auth",
    49  		},
    50  		{
    51  			// note: since this is an optional field, no value is preferred over NONE or NOASSERTION
    52  			name: "empty",
    53  			input: pkg.Package{
    54  				Metadata: pkg.NpmPackage{
    55  					Author: "",
    56  				},
    57  			},
    58  			expected: "",
    59  		},
    60  	}
    61  	for _, test := range tests {
    62  		t.Run(test.name, func(t *testing.T) {
    63  			assert.Equal(t, test.expected, encodePublisher(test.input))
    64  		})
    65  	}
    66  }