(t *testing.T)
| 69 | } |
| 70 | |
| 71 | func TestCleanCmd_ArgsValidation(t *testing.T) { |
| 72 | // Cleanup. |
| 73 | dirs.RemoveAllForTest() |
| 74 | |
| 75 | tests := []struct { |
| 76 | name string |
| 77 | all bool |
| 78 | args []string |
| 79 | expectError bool |
| 80 | }{ |
| 81 | { |
| 82 | name: "no_targets_without_all_should_fail", |
| 83 | all: false, |
| 84 | args: []string{}, |
| 85 | expectError: true, |
| 86 | }, |
| 87 | { |
| 88 | name: "targets_without_all_should_succeed", |
| 89 | all: false, |
| 90 | args: []string{"x264@stable"}, |
| 91 | expectError: false, |
| 92 | }, |
| 93 | { |
| 94 | name: "all_without_targets_should_succeed", |
| 95 | all: true, |
| 96 | args: []string{}, |
| 97 | expectError: false, |
| 98 | }, |
| 99 | { |
| 100 | name: "all_with_targets_should_fail", |
| 101 | all: true, |
| 102 | args: []string{"x264@stable"}, |
| 103 | expectError: true, |
| 104 | }, |
| 105 | } |
| 106 | |
| 107 | for _, test := range tests { |
| 108 | t.Run(test.name, func(t *testing.T) { |
| 109 | clean := cleanCmd{} |
| 110 | cmd := clean.Command(configs.NewCeler()) |
| 111 | |
| 112 | if err := cmd.Flags().Set("all", expr.If(test.all, "true", "false")); err != nil { |
| 113 | t.Fatalf("failed to set --all flag: %v", err) |
| 114 | } |
| 115 | |
| 116 | err := cmd.Args(cmd, test.args) |
| 117 | if test.expectError && err == nil { |
| 118 | t.Fatal("expected args validation error") |
| 119 | } |
| 120 | if !test.expectError && err != nil { |
| 121 | t.Fatalf("expected args validation success, got: %v", err) |
| 122 | } |
| 123 | }) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | func TestCleanCmd_ValidateTargets(t *testing.T) { |
| 128 | // Cleanup. |
nothing calls this directly
no test coverage detected