-
Notifications
You must be signed in to change notification settings - Fork 1
/
domain_test.go
72 lines (66 loc) · 1.17 KB
/
domain_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
package anonymize_test
import (
"strings"
"testing"
"github.com/emmanuelay/anonymize"
)
func TestAnonymizeDomain(t *testing.T) {
tests := []struct {
got string
want string
anonRune rune
}{
{
got: "www.somedomain.com",
want: "www.s*********.com",
},
{
got: " ",
want: "",
},
{
got: "f.com",
want: "*.com",
},
{
got: "do.com",
want: "d*.com",
},
{
got: "www.this-should-work.com",
want: "www.t***-s*****-w***.com",
},
{
got: "www.this-should-work.com/some/path",
want: "www.t***-s*****-w***.com/some/path",
},
{
got: "w**",
want: "w**",
},
{
got: "words.com",
want: "w****.com",
},
{
got: "domain.com",
want: "d*****.com",
},
{
got: "www.domain.com",
want: "www.d•••••.com",
anonRune: '•',
},
}
for _, test := range tests {
var result string
if test.anonRune > 0 {
result = anonymize.DomainWithCustomRune(test.got, test.anonRune)
} else {
result = anonymize.Domain(test.got)
}
if !strings.EqualFold(test.want, result) {
t.Errorf("Incorrect result for '%v': got '%v', want '%v'", test.got, result, test.want)
}
}
}