(t *testing.T)
| 178 | } |
| 179 | |
| 180 | func TestDelegateDiffModes(t *testing.T) { |
| 181 | tests := []struct { |
| 182 | name string |
| 183 | args []string |
| 184 | wantTo string |
| 185 | wantErr string |
| 186 | }{ |
| 187 | {name: "workspace"}, |
| 188 | {name: "default target", args: []string{"--from", "main"}, wantTo: "HEAD"}, |
| 189 | {name: "explicit target", args: []string{"--from", "main", "--to", "feature"}, wantTo: "feature"}, |
| 190 | {name: "commit", args: []string{"--commit", "abc123"}}, |
| 191 | {name: "missing base", args: []string{"--to", "HEAD"}, wantErr: "--from is required when --to is specified"}, |
| 192 | {name: "conflicting shorthand", args: []string{"--from", "main", "--commit", "abc123"}, wantErr: "only one review mode allowed"}, |
| 193 | {name: "conflicting range", args: []string{"--from", "main", "--to", "HEAD", "--commit", "abc123"}, wantErr: "only one review mode allowed"}, |
| 194 | } |
| 195 | for _, test := range tests { |
| 196 | t.Run(test.name, func(t *testing.T) { |
| 197 | var opts delegateOptions |
| 198 | cmd := &cobra.Command{Use: "delegate"} |
| 199 | registerDelegateFlags(cmd, &opts) |
| 200 | if err := cmd.ParseFlags(test.args); err != nil { |
| 201 | t.Fatal(err) |
| 202 | } |
| 203 | err := validateDelegateOptions(&opts) |
| 204 | if test.wantErr != "" { |
| 205 | if err == nil || !strings.Contains(err.Error(), test.wantErr) { |
| 206 | t.Fatalf("error = %v, want %q", err, test.wantErr) |
| 207 | } |
| 208 | return |
| 209 | } |
| 210 | if err != nil { |
| 211 | t.Fatal(err) |
| 212 | } |
| 213 | if opts.to != test.wantTo { |
| 214 | t.Fatalf("to = %q, want %q", opts.to, test.wantTo) |
| 215 | } |
| 216 | }) |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | func TestParseReviewFlags_ToWithoutFrom(t *testing.T) { |
| 221 | _, err := parseReviewFlags([]string{"--to", "dev"}) |
nothing calls this directly
no test coverage detected