github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/internal/file/normalize_hashes_test.go (about)

     1  package file
     2  
     3  import (
     4  	"crypto"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestNormalizeHashes(t *testing.T) {
    11  
    12  	tests := []struct {
    13  		name  string
    14  		input []crypto.Hash
    15  		want  []crypto.Hash
    16  	}{
    17  		{
    18  			name: "deduplicate hashes",
    19  			input: []crypto.Hash{
    20  				crypto.SHA1,
    21  				crypto.SHA1,
    22  			},
    23  			want: []crypto.Hash{
    24  				crypto.SHA1,
    25  			},
    26  		},
    27  		{
    28  			name: "sort hashes",
    29  			input: []crypto.Hash{
    30  				crypto.SHA512,
    31  				crypto.SHA1,
    32  			},
    33  			want: []crypto.Hash{
    34  				crypto.SHA1,
    35  				crypto.SHA512,
    36  			},
    37  		},
    38  	}
    39  	for _, tt := range tests {
    40  		t.Run(tt.name, func(t *testing.T) {
    41  			assert.Equal(t, tt.want, NormalizeHashes(tt.input))
    42  		})
    43  	}
    44  }