Skip to content

Commit

Permalink
fix multiple override default inputs
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
  • Loading branch information
wagoodman committed Dec 16, 2023
1 parent 473605c commit 63c23e2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/task/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
35 changes: 34 additions & 1 deletion internal/task/selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
40 changes: 38 additions & 2 deletions test/cli/packages_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 63c23e2

Please sign in to comment.