-
Notifications
You must be signed in to change notification settings - Fork 1
/
email_test.go
92 lines (86 loc) · 1.62 KB
/
email_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
86
87
88
89
90
91
92
package anonymize_test
import (
"strings"
"testing"
"github.com/emmanuelay/anonymize"
)
func TestAnonymizeEmail(t *testing.T) {
tests := []struct {
got string
want string
anonRune rune
}{
{
got: "emmanuel@somedomain.com",
want: "e*******@s*********.com",
},
{
got: "this.is.incorrect@domain@domain.com",
want: "t***.i*.i********@d*****@d*****.com",
},
{
got: " ",
want: "",
},
{
got: "e@f.com",
want: "*@*.com",
},
{
got: "@do.com",
want: "@d*.com",
},
{
got: "@.",
want: "@.",
},
{
got: "@",
want: "@",
},
{
got: ".",
want: ".",
},
{
got: "a@domain.com",
want: "*@d*****.com",
},
{
got: "al@domain.com",
want: "a*@d*****.com",
},
{
got: "emmanuel.my.last.name@some.domain.sub.domain.com",
want: "e*******.m*.l***.n***@s***.d*****.s**.d*****.com",
},
{
got: "regular.name@domain-something.com",
want: "r******.n***@d*****-s********.com",
},
{
got: "regular.name@alfa-beta-gamma-delta.com",
want: "r******.n***@a***-b***-g****-d****.com",
},
{
got: "Luke.SkyWalker@McDonalds.com",
want: "L***.S**W*****@M*D******.com",
},
{
got: "jane.doe@gmail.com",
want: "j•••.d••@g••••.com",
anonRune: '•',
},
}
for _, test := range tests {
var result string
if test.anonRune > 0 {
result = anonymize.EmailWithCustomRune(test.got, test.anonRune)
} else {
result = anonymize.Email(test.got)
}
if !strings.EqualFold(test.want, result) {
t.Errorf("Incorrect result for '%v': got '%v', want '%v'", test.got, result, test.want)
}
}
}