-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
85 lines (70 loc) · 1.51 KB
/
util_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package aferosteps
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMustNoError(t *testing.T) {
t.Parallel()
t.Run("error", func(t *testing.T) {
t.Parallel()
assert.Panics(t, func() {
mustNoError(errors.New("error"))
})
})
t.Run("no error", func(t *testing.T) {
t.Parallel()
assert.NotPanics(t, func() {
mustNoError(nil)
})
})
}
func TestFileContentRegexp(t *testing.T) {
t.Parallel()
testCases := []struct {
scenario string
content string
expected string
}{
{
scenario: "plain text",
content: "hello world",
expected: "hello world",
},
{
scenario: "regexp",
content: `
[config]
uuid = "<regexp:\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/>"
salt = "<regexp:^[a-f0-9]{32}$/>"
`,
expected: `
\[config\]
uuid = "\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b"
salt = "^[a-f0-9]{32}$"
`,
},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()
actual := fileContentRegexp(tc.content)
assert.Equal(t, tc.expected, actual)
})
}
}
func TestFileContentRegexp_Match(t *testing.T) {
t.Parallel()
expected := `
[config]
uuid = "<regexp:\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/>"
salt = "<regexp:[a-f0-9]{32}/>"
`
content := `
[config]
uuid = "3223cbf8-292f-4829-9a85-9d9f9de675aa"
salt = "5d41402abc4b2a76b9719d911017c592"
`
assert.Regexp(t, fileContentRegexp(expected), content)
}