cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/checks_test.go
52lines · modecode
| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/stretchr/testify/assert" |
| 9 | ) |
| 10 | |
| 11 | func TestChecksSettings(t *testing.T) { |
| 12 | type testCaseT struct { |
| 13 | conf Checks |
| 14 | err error |
| 15 | } |
| 16 | |
| 17 | testCases := []testCaseT{ |
| 18 | { |
| 19 | conf: Checks{}, |
| 20 | }, |
| 21 | { |
| 22 | conf: Checks{ |
| 23 | Enabled: []string{"foo"}, |
| 24 | }, |
| 25 | err: errors.New("unknown check name foo"), |
| 26 | }, |
| 27 | { |
| 28 | conf: Checks{ |
| 29 | Disabled: []string{"foo"}, |
| 30 | }, |
| 31 | err: errors.New("unknown check name foo"), |
| 32 | }, |
| 33 | { |
| 34 | conf: Checks{ |
| 35 | Enabled: []string{"promql/syntax"}, |
| 36 | Disabled: []string{"promql/syntax"}, |
| 37 | }, |
| 38 | }, |
| 39 | } |
| 40 | |
| 41 | for _, tc := range testCases { |
| 42 | t.Run(fmt.Sprintf("%v", tc.conf), func(t *testing.T) { |
| 43 | assert := assert.New(t) |
| 44 | err := tc.conf.validate() |
| 45 | if err == nil || tc.err == nil { |
| 46 | assert.Equal(err, tc.err) |
| 47 | } else { |
| 48 | assert.EqualError(err, tc.err.Error()) |
| 49 | } |
| 50 | }) |
| 51 | } |
| 52 | } |