diff --git a/internal/task/selection.go b/internal/task/selection.go index d73e2fb60fb7..994db047fd2d 100644 --- a/internal/task/selection.go +++ b/internal/task/selection.go @@ -128,7 +128,7 @@ func selectByExpressions(ts tasks, nodes Expressions) (tasks, Selection) { switch node.Operation { case SetOperation: - finalSet = newSet(selectedTasks...) + finalSet.Add(selectedTasks...) case AddOperation, "": addSet.Add(selectedTasks...) case RemoveOperation: diff --git a/internal/task/selection_test.go b/internal/task/selection_test.go index c5801668cd03..8e6f711d6c73 100644 --- a/internal/task/selection_test.go +++ b/internal/task/selection_test.go @@ -35,7 +35,7 @@ func createDummyTasks() tasks { dummyTask("conan-info-cataloger", "installed", "image", "language", "cpp", "conan"), dummyTask("javascript-package-cataloger", "installed", "image", "language", "javascript", "node"), dummyTask("php-composer-installed-cataloger", "installed", "image", "language", "php", "composer"), - dummyTask("ruby-installed-gemspec-cataloger", "installed", "image", "language", "ruby", "gem"), + dummyTask("ruby-installed-gemspec-cataloger", "installed", "image", "language", "ruby", "gem", "gemspec"), dummyTask("rust-cargo-lock-cataloger", "installed", "image", "language", "rust", "binary"), // language-specific package declared catalogers @@ -380,6 +380,39 @@ func TestSelect(t *testing.T) { Selection: []string{}, }, }, + { + name: "set default with multiple tags", + allTasks: createDummyTasks(), + basis: []string{ + "gemspec", + "python", + }, + expressions: []string{}, + wantNames: []string{ + "ruby-installed-gemspec-cataloger", + "python-installed-package-cataloger", + }, + wantTokens: map[string]TokenSelection{ + "ruby-installed-gemspec-cataloger": newTokenSelection([]string{"gemspec"}, nil), + "python-installed-package-cataloger": newTokenSelection([]string{"python"}, nil), + }, + wantRequest: SelectionRequest{ + Expressions: []Expression{ + { + Operation: SetOperation, + Operand: "gemspec", + Errors: nil, + }, + { + Operation: SetOperation, + Operand: "python", + Errors: nil, + }, + }, + Default: []string{"gemspec", "python"}, + Selection: []string{}, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/test/cli/packages_cmd_test.go b/test/cli/packages_cmd_test.go index 5763ff470a3f..ac3160be35bc 100644 --- a/test/cli/packages_cmd_test.go +++ b/test/cli/packages_cmd_test.go @@ -234,14 +234,50 @@ func TestPackagesCmdFlags(t *testing.T) { }, }, { - name: "catalogers-option", - // This will detect enable python-package-cataloger, python-installed-package-cataloger and ruby-gemspec-cataloger cataloger + name: "legacy-catalogers-option", + // This will detect enable: + // - python-installed-package-cataloger + // - python-package-cataloger + // - ruby-gemspec-cataloger + // - ruby-installed-gemspec-cataloger args: []string{"packages", "-o", "json", "--catalogers", "python,gemspec", coverageImage}, assertions: []traitAssertion{ + assertInOutput("Flag --catalogers has been deprecated, use: override-default-catalogers and select-catalogers"), assertPackageCount(13), assertSuccessfulReturnCode, }, }, + { + name: "select-catalogers-option", + // This will detect enable: + // - python-installed-package-cataloger + // - ruby-installed-gemspec-cataloger + args: []string{"packages", "-o", "json", "--select-catalogers", "python,gemspec", coverageImage}, + assertions: []traitAssertion{ + assertPackageCount(6), + assertSuccessfulReturnCode, + }, + }, + { + name: "override-default-catalogers-option", + // This will detect enable: + // - python-installed-package-cataloger + // - python-package-cataloger + // - ruby-gemspec-cataloger + // - ruby-installed-gemspec-cataloger + args: []string{"packages", "-o", "json", "--override-default-catalogers", "python,gemspec", coverageImage}, + assertions: []traitAssertion{ + assertPackageCount(13), + assertSuccessfulReturnCode, + }, + }, + { + name: "new and old cataloger options are mutually exclusive", + args: []string{"packages", "-o", "json", "--override-default-catalogers", "python", "--catalogers", "gemspec", coverageImage}, + assertions: []traitAssertion{ + assertFailingReturnCode, + }, + }, { name: "override-default-parallelism", args: []string{"packages", "-vvv", "-o", "json", coverageImage},