github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/cmd/syft/internal/commands/scan_test.go (about) 1 package commands 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/anchore/syft/cmd/syft/internal/options" 9 ) 10 11 func Test_scanOptions_validateLegacyOptionsNotUsed(t *testing.T) { 12 tests := []struct { 13 name string 14 cfg string 15 wantErr assert.ErrorAssertionFunc 16 }{ 17 { 18 name: "no config file", 19 }, 20 { 21 name: "config file with no legacy options", 22 cfg: "test-fixtures/scan-configs/no-legacy-options.yaml", 23 }, 24 { 25 name: "config file with default image pull source legacy option", 26 cfg: "test-fixtures/scan-configs/with-default-pull-source.yaml", 27 wantErr: assertErrorContains("source.image.default-pull-source"), 28 }, 29 { 30 name: "config file with exclude-binary-overlap-by-ownership legacy option", 31 cfg: "test-fixtures/scan-configs/with-exclude-binary-overlap-by-ownership.yaml", 32 wantErr: assertErrorContains("package.exclude-binary-overlap-by-ownership"), 33 }, 34 { 35 name: "config file with file string legacy option", 36 cfg: "test-fixtures/scan-configs/with-file-string.yaml", 37 wantErr: assertErrorContains("outputs"), 38 }, 39 { 40 name: "config file with file section", 41 cfg: "test-fixtures/scan-configs/with-file-section.yaml", 42 }, 43 { 44 name: "config file with base-path legacy option", 45 cfg: "test-fixtures/scan-configs/with-base-path.yaml", 46 wantErr: assertErrorContains("source.base-path"), 47 }, 48 } 49 for _, tt := range tests { 50 t.Run(tt.name, func(t *testing.T) { 51 if tt.wantErr == nil { 52 tt.wantErr = assert.NoError 53 } 54 o := &scanOptions{ 55 Config: options.Config{ConfigFile: tt.cfg}, 56 } 57 tt.wantErr(t, o.validateLegacyOptionsNotUsed()) 58 }) 59 } 60 } 61 62 func assertErrorContains(contains string) assert.ErrorAssertionFunc { 63 return func(t assert.TestingT, err error, i ...interface{}) bool { 64 return assert.ErrorContains(t, err, contains, i...) 65 } 66 }