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/aggregate_test.go

62lines · modecode

1package config
2
3import (
4 "errors"
5 "fmt"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9)
10
11func TestAggregateSettings(t *testing.T) {
12 type testCaseT struct {
13 conf AggregateSettings
14 err error
15 }
16
17 testCases := []testCaseT{
18 {
19 conf: AggregateSettings{},
20 err: errors.New("empty name regex"),
21 },
22 {
23 conf: AggregateSettings{
24 Name: "foo",
25 },
26 err: errors.New("must specify keep or strip list"),
27 },
28 {
29 conf: AggregateSettings{
30 Name: ".+",
31 Keep: []string{"foo"},
32 },
33 },
34 {
35 conf: AggregateSettings{
36 Name: ".+++",
37 Keep: []string{"foo"},
38 },
39 err: errors.New("error parsing regexp: invalid nested repetition operator: `++`"),
40 },
41 {
42 conf: AggregateSettings{
43 Name: ".+",
44 Keep: []string{"foo"},
45 Severity: "foo",
46 },
47 err: errors.New("unknown severity: foo"),
48 },
49 }
50
51 for _, tc := range testCases {
52 t.Run(fmt.Sprintf("%v", tc.conf), func(t *testing.T) {
53 assert := assert.New(t)
54 err := tc.conf.validate()
55 if err == nil || tc.err == nil {
56 assert.Equal(err, tc.err)
57 } else {
58 assert.EqualError(err, tc.err.Error())
59 }
60 })
61 }
62}
63