cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.13.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/config/annotation_test.go

60lines · modecode

1package config
2
3import (
4 "errors"
5 "fmt"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9)
10
11func 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: ".+",
43 Severity: "foo",
44 },
45 err: errors.New("unknown severity: foo"),
46 },
47 }
48
49 for _, tc := range testCases {
50 t.Run(fmt.Sprintf("%v", tc.conf), func(t *testing.T) {
51 assert := assert.New(t)
52 err := tc.conf.validate()
53 if err == nil || tc.err == nil {
54 assert.Equal(err, tc.err)
55 } else {
56 assert.EqualError(err, tc.err.Error())
57 }
58 })
59 }
60}