(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func TestFlagDefaultValidation(t *testing.T) { |
| 11 | cmd := &Command{ |
| 12 | Name: "foo", |
| 13 | Flags: []Flag{ |
| 14 | &Int64Flag{ |
| 15 | Name: "if", |
| 16 | Value: 2, // this value should fail validation |
| 17 | Validator: func(i int64) error { |
| 18 | if (i >= 3 && i <= 10) || (i >= 20 && i <= 24) { |
| 19 | return nil |
| 20 | } |
| 21 | return fmt.Errorf("Value %d not in range [3,10] or [20,24]", i) |
| 22 | }, |
| 23 | ValidateDefaults: true, |
| 24 | }, |
| 25 | }, |
| 26 | } |
| 27 | |
| 28 | r := require.New(t) |
| 29 | |
| 30 | // this is a simple call to test PreParse failure before |
| 31 | // parsing has been done |
| 32 | r.Error(cmd.Set("if", "11")) |
| 33 | |
| 34 | // Default value of flag is 2 which should fail validation |
| 35 | err := cmd.Run(buildTestContext(t), []string{"foo", "--if", "5"}) |
| 36 | r.Error(err) |
| 37 | } |
| 38 | |
| 39 | func TestBoolInverseFlagDefaultValidation(t *testing.T) { |
| 40 | cmd := &Command{ |
nothing calls this directly
no test coverage detected