cloudflare/pint

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.81.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

internal/config/aggregate_test.go

81lines · 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 err error
14 conf AggregateSettings
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 conf: AggregateSettings{
58 Name: ".+",
59 Strip: []string{"bar"},
60 },
61 },
62 {
63 conf: AggregateSettings{
64 Name: ".+",
65 Keep: []string{"foo"},
66 Severity: "warning",
67 },
68 },
69 }
70
71 for _, tc := range testCases {
72 t.Run(fmt.Sprintf("%v", tc.conf), func(t *testing.T) {
73 err := tc.conf.validate()
74 if err == nil || tc.err == nil {
75 require.Equal(t, err, tc.err)
76 } else {
77 require.EqualError(t, err, tc.err.Error())
78 }
79 })
80 }
81}
82