cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/annotation_test.go
72lines · modecode
| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/stretchr/testify/require" |
| 9 | ) |
| 10 | |
| 11 | func TestAnnotationSettings(t *testing.T) { |
| 12 | type testCaseT struct { |
| 13 | conf AnnotationSettings |
| 14 | err error |
| 15 | } |
| 16 | |
| 17 | testCases := []testCaseT{ |
| 18 | { |
| 19 | conf: AnnotationSettings{ |
| 20 | Key: "summary", |
| 21 | }, |
| 22 | }, |
| 23 | { |
| 24 | conf: AnnotationSettings{}, |
| 25 | err: errors.New("annotation key cannot be empty"), |
| 26 | }, |
| 27 | { |
| 28 | conf: AnnotationSettings{ |
| 29 | Key: ".++", |
| 30 | }, |
| 31 | err: errors.New("error parsing regexp: invalid nested repetition operator: `++`"), |
| 32 | }, |
| 33 | { |
| 34 | conf: AnnotationSettings{ |
| 35 | Key: ".+", |
| 36 | Value: ".++", |
| 37 | }, |
| 38 | err: errors.New("error parsing regexp: invalid nested repetition operator: `++`"), |
| 39 | }, |
| 40 | { |
| 41 | conf: AnnotationSettings{ |
| 42 | Key: "{{nil}}", |
| 43 | }, |
| 44 | err: errors.New(`template: regexp:1:125: executing "regexp" at <nil>: nil is not a command`), |
| 45 | }, |
| 46 | { |
| 47 | conf: AnnotationSettings{ |
| 48 | Key: ".+", |
| 49 | Value: "{{nil}}", |
| 50 | }, |
| 51 | err: errors.New(`template: regexp:1:125: executing "regexp" at <nil>: nil is not a command`), |
| 52 | }, |
| 53 | { |
| 54 | conf: AnnotationSettings{ |
| 55 | Key: ".+", |
| 56 | Severity: "foo", |
| 57 | }, |
| 58 | err: errors.New("unknown severity: foo"), |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | for _, tc := range testCases { |
| 63 | t.Run(fmt.Sprintf("%v", tc.conf), func(t *testing.T) { |
| 64 | err := tc.conf.validate() |
| 65 | if err == nil || tc.err == nil { |
| 66 | require.Equal(t, err, tc.err) |
| 67 | } else { |
| 68 | require.EqualError(t, err, tc.err.Error()) |
| 69 | } |
| 70 | }) |
| 71 | } |
| 72 | } |
| 73 | |