github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/cmd/syft/internal/options/source_test.go (about)

     1  package options
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_fileSource_PostLoad(t *testing.T) {
    10  	tests := []struct {
    11  		name    string
    12  		cfg     fileSource
    13  		assert  func(t *testing.T, cfg fileSource)
    14  		wantErr assert.ErrorAssertionFunc
    15  	}{
    16  		{
    17  			name: "deduplicate digests",
    18  			cfg: fileSource{
    19  				Digests: []string{"sha1", "sha1"},
    20  			},
    21  			assert: func(t *testing.T, cfg fileSource) {
    22  				assert.Equal(t, []string{"sha1"}, cfg.Digests)
    23  			},
    24  		},
    25  	}
    26  	for _, tt := range tests {
    27  		t.Run(tt.name, func(t *testing.T) {
    28  			if tt.wantErr == nil {
    29  				tt.wantErr = assert.NoError
    30  			}
    31  			tt.wantErr(t, tt.cfg.PostLoad())
    32  			if tt.assert != nil {
    33  				tt.assert(t, tt.cfg)
    34  			}
    35  		})
    36  	}
    37  }