cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.29.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/config/aggregate_test.go

68lines · modecode

1package config
2
3import (
4 "errors"
5 "fmt"
6 "testing"
7
8 "github.com/stretchr/testify/require"
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: "{{nil}}",
44 Keep: []string{"foo"},
45 },
46 err: errors.New(`template: regexp:1:125: executing "regexp" at <nil>: nil is not a command`),
47 },
48 {
49 conf: AggregateSettings{
50 Name: ".+",
51 Keep: []string{"foo"},
52 Severity: "foo",
53 },
54 err: errors.New("unknown severity: foo"),
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