Skip to content

Commit d152360

Browse files
GabinFqtValentin Rejaunier
authored andcommitted
fix(cli): address scans test review
1 parent 7ad504d commit d152360

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

pkg/cli/cmd/scans_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/spf13/cobra"
99
)
1010

11-
func TestResolveScanKindsUsesDefaultScanKinds(t *testing.T) {
12-
cmd := newScansTestCommand()
11+
func TestResolveKinds_Defaults(t *testing.T) {
12+
cmd := newTestCommand(t)
1313

1414
got := resolveScanKinds(cmd)
1515

@@ -18,8 +18,8 @@ func TestResolveScanKindsUsesDefaultScanKinds(t *testing.T) {
1818
}
1919
}
2020

21-
func TestResolveScanKindsAllKindsDisablesKindFilter(t *testing.T) {
22-
cmd := newScansTestCommand()
21+
func TestResolveKinds_AllKinds(t *testing.T) {
22+
cmd := newTestCommand(t)
2323
if err := cmd.Flags().Set("all-kinds", "true"); err != nil {
2424
t.Fatalf("failed to set all-kinds flag: %v", err)
2525
}
@@ -34,8 +34,8 @@ func TestResolveScanKindsAllKindsDisablesKindFilter(t *testing.T) {
3434
}
3535
}
3636

37-
func TestResolveScanKindsKindOverridesAllKinds(t *testing.T) {
38-
cmd := newScansTestCommand()
37+
func TestResolveKinds_KindOverrides(t *testing.T) {
38+
cmd := newTestCommand(t)
3939
if err := cmd.Flags().Set("all-kinds", "true"); err != nil {
4040
t.Fatalf("failed to set all-kinds flag: %v", err)
4141
}
@@ -51,7 +51,16 @@ func TestResolveScanKindsKindOverridesAllKinds(t *testing.T) {
5151
}
5252
}
5353

54-
func newScansTestCommand() *cobra.Command {
54+
func newTestCommand(t *testing.T) *cobra.Command {
55+
t.Helper()
56+
57+
prevKinds := scanKinds
58+
prevAllKinds := scanListAllKinds
59+
t.Cleanup(func() {
60+
scanKinds = prevKinds
61+
scanListAllKinds = prevAllKinds
62+
})
63+
5564
scanKinds = []string{}
5665
scanListAllKinds = false
5766

0 commit comments

Comments
 (0)