cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/options/call_test.go
68lines · modecode
| 1 | package options_test |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/stretchr/testify/require" |
| 9 | |
| 10 | "github.com/cloudflare/pint/internal/config/options" |
| 11 | ) |
| 12 | |
| 13 | func TestCallSettings(t *testing.T) { |
| 14 | type testCaseT struct { |
| 15 | err error |
| 16 | conf options.CallSettings |
| 17 | } |
| 18 | |
| 19 | testCases := []testCaseT{ |
| 20 | { |
| 21 | conf: options.CallSettings{ |
| 22 | Key: "sum", |
| 23 | Selectors: []options.SelectorSettings{ |
| 24 | { |
| 25 | Key: ".+", |
| 26 | RequiredLabels: []string{"foo"}, |
| 27 | }, |
| 28 | }, |
| 29 | }, |
| 30 | }, |
| 31 | { |
| 32 | conf: options.CallSettings{}, |
| 33 | err: errors.New("call key cannot be empty"), |
| 34 | }, |
| 35 | { |
| 36 | conf: options.CallSettings{ |
| 37 | Key: ".++", |
| 38 | }, |
| 39 | err: errors.New("error parsing regexp: invalid nested repetition operator: `++`"), |
| 40 | }, |
| 41 | { |
| 42 | conf: options.CallSettings{ |
| 43 | Key: ".+", |
| 44 | }, |
| 45 | err: errors.New("you must specific at least one `selector` block"), |
| 46 | }, |
| 47 | { |
| 48 | conf: options.CallSettings{ |
| 49 | Key: ".+", |
| 50 | Selectors: []options.SelectorSettings{ |
| 51 | {}, |
| 52 | }, |
| 53 | }, |
| 54 | err: errors.New("selector key cannot be empty"), |
| 55 | }, |
| 56 | } |
| 57 | |
| 58 | for _, tc := range testCases { |
| 59 | t.Run(fmt.Sprintf("%v", tc.conf), func(t *testing.T) { |
| 60 | err := tc.conf.Validate() |
| 61 | if err == nil || tc.err == nil { |
| 62 | require.Equal(t, err, tc.err) |
| 63 | } else { |
| 64 | require.EqualError(t, err, tc.err.Error()) |
| 65 | } |
| 66 | }) |
| 67 | } |
| 68 | } |
| 69 | |