|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/golang/dep/internal/gps" |
| 7 | +) |
| 8 | + |
| 9 | +func TestInvalidEnsureFlagCombinations(t *testing.T) { |
| 10 | + ec := &ensureCommand{ |
| 11 | + update: true, |
| 12 | + add: true, |
| 13 | + } |
| 14 | + |
| 15 | + if err := ec.validateFlags(); err == nil { |
| 16 | + t.Error("-add and -update together should fail validation") |
| 17 | + } |
| 18 | + |
| 19 | + ec.vendorOnly, ec.add = true, false |
| 20 | + if err := ec.validateFlags(); err == nil { |
| 21 | + t.Error("-vendor-only with -update should fail validation") |
| 22 | + } |
| 23 | + |
| 24 | + ec.add, ec.update = true, false |
| 25 | + if err := ec.validateFlags(); err == nil { |
| 26 | + t.Error("-vendor-only with -add should fail validation") |
| 27 | + } |
| 28 | + |
| 29 | + ec.noVendor, ec.add = true, false |
| 30 | + if err := ec.validateFlags(); err == nil { |
| 31 | + t.Error("-vendor-only with -no-vendor should fail validation") |
| 32 | + } |
| 33 | + ec.noVendor = false |
| 34 | + |
| 35 | + // Also verify that the plain ensure path takes no args. This is a shady |
| 36 | + // test, as lots of other things COULD return errors, and we don't check |
| 37 | + // anything other than the error being non-nil. For now, it works well |
| 38 | + // because a panic will quickly result if the initial arg length validation |
| 39 | + // checks are incorrectly handled. |
| 40 | + if err := ec.runDefault(nil, []string{"foo"}, nil, nil, gps.SolveParameters{}); err == nil { |
| 41 | + t.Errorf("no args to plain ensure with -vendor-only") |
| 42 | + } |
| 43 | + ec.vendorOnly = false |
| 44 | + if err := ec.runDefault(nil, []string{"foo"}, nil, nil, gps.SolveParameters{}); err == nil { |
| 45 | + t.Errorf("no args to plain ensure") |
| 46 | + } |
| 47 | +} |
0 commit comments