-
Notifications
You must be signed in to change notification settings - Fork 1
/
panitizer_test.go
49 lines (45 loc) · 1.38 KB
/
panitizer_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
package panitizer_test
import (
"testing"
"github.com/NickPresta/panitizer"
)
func TestMaskCreditCardNumber(t *testing.T) {
creditCardTests := []struct {
in string
expected string
}{
{"4242 4242 4242 4242", "**** **** **** 4242"},
{"4242 4242 4242 4242", "**** **** **** 4242"},
{"4242-4242-4242-4242", "****-****-****-4242"},
{"42-42 42-42 42-42 42-42", "**-** **-** **-** *2-42"},
{"4242424242424242", "************4242"},
{"4242.4242.4242.4242", "4242.4242.4242.4242"},
{"4242x4242x4242x4242", "4242x4242x4242x4242"},
{"4242 4242 4242 4242\n\nhello\n\nhey", "**** **** **** 4242\n\nhello\n\nhey"},
{"4242 4242 4242 4242 4242 4242", "**** **** **** 4242 4242 4242"},
{"foo", "foo"},
{"morethanfour", "morethanfour"},
{"four", "four"},
}
for _, tt := range creditCardTests {
if actual := panitizer.Replace(tt.in); tt.expected != actual {
t.Errorf("Expected %q given %q but got %q", tt.expected, tt.in, actual)
}
}
}
func TestContainsPAN(t *testing.T) {
creditCardTests := []struct {
in string
expected bool
}{
{"4242 4242 4242 4242", true},
{"42-42 42-42 42-42 42-42", true},
{"4242.4242.4242.4242", false},
{"morethanfour", false},
}
for _, tt := range creditCardTests {
if actual := panitizer.ContainsPAN(tt.in); tt.expected != actual {
t.Errorf("Expected %v given %q but got %v", tt.expected, tt.in, actual)
}
}
}