github.com/anchore/syft@v1.38.2/syft/pkg/rpm_test.go (about)

     1  package pkg
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/go-test/deep"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestRpmMetadata_FileOwner(t *testing.T) {
    12  	tests := []struct {
    13  		metadata RpmDBEntry
    14  		expected []string
    15  	}{
    16  		{
    17  			metadata: RpmDBEntry{
    18  				Files: []RpmFileRecord{
    19  					{Path: "/somewhere"},
    20  					{Path: "/else"},
    21  				},
    22  			},
    23  			expected: []string{
    24  				"/else",
    25  				"/somewhere",
    26  			},
    27  		},
    28  		{
    29  			metadata: RpmDBEntry{
    30  				Files: []RpmFileRecord{
    31  					{Path: "/somewhere"},
    32  					{Path: ""},
    33  				},
    34  			},
    35  			expected: []string{
    36  				"/somewhere",
    37  			},
    38  		},
    39  	}
    40  
    41  	for _, test := range tests {
    42  		t.Run(strings.Join(test.expected, ","), func(t *testing.T) {
    43  			actual := test.metadata.OwnedFiles()
    44  			for _, d := range deep.Equal(test.expected, actual) {
    45  				t.Errorf("diff: %+v", d)
    46  			}
    47  		})
    48  	}
    49  }
    50  
    51  func TestRpmSignature_String(t *testing.T) {
    52  	tests := []struct {
    53  		name      string
    54  		signature RpmSignature
    55  		expected  string
    56  	}{
    57  		{
    58  			name: "standard signature",
    59  			signature: RpmSignature{
    60  				PublicKeyAlgorithm: "RSA",
    61  				HashAlgorithm:      "SHA256",
    62  				Created:            "Mon May 16 12:32:55 2022",
    63  				IssuerKeyID:        "702d426d350d275d",
    64  			},
    65  			expected: "RSA/SHA256, Mon May 16 12:32:55 2022, Key ID 702d426d350d275d",
    66  		},
    67  		{
    68  			name: "empty fields",
    69  			signature: RpmSignature{
    70  				PublicKeyAlgorithm: "",
    71  				HashAlgorithm:      "",
    72  				Created:            "",
    73  				IssuerKeyID:        "",
    74  			},
    75  			expected: "",
    76  		},
    77  		{
    78  			name: "partial empty fields",
    79  			signature: RpmSignature{
    80  				PublicKeyAlgorithm: "RSA",
    81  				HashAlgorithm:      "",
    82  				Created:            "Mon May 16 12:32:55 2022",
    83  				IssuerKeyID:        "",
    84  			},
    85  			expected: "RSA/, Mon May 16 12:32:55 2022, Key ID ",
    86  		},
    87  	}
    88  
    89  	for _, tt := range tests {
    90  		t.Run(tt.name, func(t *testing.T) {
    91  			result := tt.signature.String()
    92  			assert.Equal(t, tt.expected, result)
    93  		})
    94  	}
    95  }