MCPcopy Create free account
hub / github.com/alibaba/open-code-review / TestDelegateDiffModes

Function TestDelegateDiffModes

cmd/opencodereview/flags_test.go:180–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func 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
220func TestParseReviewFlags_ToWithoutFrom(t *testing.T) {
221 _, err := parseReviewFlags([]string{"--to", "dev"})

Callers

nothing calls this directly

Calls 4

registerDelegateFlagsFunction · 0.85
validateDelegateOptionsFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected