-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_test.go
67 lines (50 loc) · 1.54 KB
/
filter_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
package gold_test
import (
"regexp"
"testing"
. "github.com/mfcochauxlaberge/gold"
"github.com/stretchr/testify/assert"
)
func TestFilterFormatJSON(t *testing.T) {
assert := assert.New(t)
src := []byte(`{"a": [0, "b"]}`)
expected := `{
"a": [
0,
"b"
]
}`
assert.Equal(expected, string(FilterFormatJSON(src)))
// Invalid JSON will make FilterFormatJSON panic.
assert.Panics(func() {
_ = FilterFormatJSON([]byte(`this is invalid`))
})
}
func TestFilterTimeRFC3339(t *testing.T) {
assert := assert.New(t)
src := []byte("The time is 2006-01-02T15:04:05Z07:00!")
expected := "The time is 0000-00-00T00:00:00Z07:00!"
assert.Equal(expected, string(FilterTimeRFC3339(src)))
}
func TestFilterBcryptHashes(t *testing.T) {
assert := assert.New(t)
hash := "$2a$10$aE6OdEySkK3g4HDnvJbFh.VXOW/gO7yDJEBqK/pnezwxjnkOo6kfC"
src := []byte("The hash is " + string(hash) + "!")
expected := "The hash is _HASH_!"
assert.Equal(expected, string(FilterBcryptHashes(src)))
}
func TestFilterUUIDs(t *testing.T) {
assert := assert.New(t)
uuid := "25cef774-e2e6-4c78-ac1d-7b1acf1b28e6"
src := []byte("The uuid is " + string(uuid) + "!")
expected := "The uuid is 00000000-0000-0000-0000-000000000000!"
assert.Equal(expected, string(FilterUUIDs(src)))
}
func TestCustomFilter(t *testing.T) {
assert := assert.New(t)
reg := regexp.MustCompile(`A[0-9]{1}Z`)
filter := CustomFilter(reg, "__CUSTOM__")
src := []byte("The string to be replaced is A4Z!")
expected := "The string to be replaced is __CUSTOM__!"
assert.Equal(expected, string(filter(src)))
}