|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestGetComplete(t *testing.T) { |
| 8 | + streams, in, out, errs := NewTestIOStreams() |
| 9 | + setNoColor(true) |
| 10 | + |
| 11 | + f, err := NewTestFactory(nil) |
| 12 | + if err != nil { |
| 13 | + t.Errorf("error creating new test factory: %s", err) |
| 14 | + return |
| 15 | + } |
| 16 | + |
| 17 | + cases := []struct { |
| 18 | + args []string |
| 19 | + path string |
| 20 | + refs []string |
| 21 | + err string |
| 22 | + }{ |
| 23 | + {[]string{}, "", []string{}, ""}, |
| 24 | + {[]string{"one arg"}, "", []string{"one arg"}, ""}, |
| 25 | + {[]string{"commit", "peer/ds"}, "commit", []string{"peer/ds"}, ""}, |
| 26 | + {[]string{"peer/ds_two", "peer/ds"}, "", []string{"peer/ds_two", "peer/ds"}, ""}, |
| 27 | + {[]string{"foo", "peer/ds"}, "", []string{"foo", "peer/ds"}, ""}, |
| 28 | + {[]string{"structure"}, "structure", []string{}, ""}, |
| 29 | + } |
| 30 | + |
| 31 | + for i, c := range cases { |
| 32 | + opt := &GetOptions{ |
| 33 | + IOStreams: streams, |
| 34 | + } |
| 35 | + |
| 36 | + opt.Complete(f, c.args) |
| 37 | + |
| 38 | + if c.err != errs.String() { |
| 39 | + t.Errorf("case %d, error mismatch. Expected: '%s', Got: '%s'", i, c.err, errs.String()) |
| 40 | + ioReset(in, out, errs) |
| 41 | + continue |
| 42 | + } |
| 43 | + |
| 44 | + if !testSliceEqual(c.refs, opt.Refs) { |
| 45 | + t.Errorf("case %d, opt.Refs not set correctly. Expected: '%s', Got: '%s'", i, c.refs, opt.Refs) |
| 46 | + ioReset(in, out, errs) |
| 47 | + continue |
| 48 | + } |
| 49 | + |
| 50 | + if c.path != opt.Path { |
| 51 | + t.Errorf("case %d, opt.Path not set correctly. Expected: '%s', Got: '%s'", i, c.path, opt.Path) |
| 52 | + ioReset(in, out, errs) |
| 53 | + continue |
| 54 | + } |
| 55 | + |
| 56 | + if opt.DatasetRequests == nil { |
| 57 | + t.Errorf("case %d, opt.DatasetRequests not set.", i) |
| 58 | + ioReset(in, out, errs) |
| 59 | + continue |
| 60 | + } |
| 61 | + ioReset(in, out, errs) |
| 62 | + } |
| 63 | +} |
0 commit comments