-
Notifications
You must be signed in to change notification settings - Fork 4
/
email_matcher_test.go
90 lines (82 loc) · 1.33 KB
/
email_matcher_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
package gomatch
import (
"testing"
"github.com/stretchr/testify/assert"
)
var emailMatcherTests = []struct {
desc string
v interface{}
ok bool
errMsg string
}{
{
"Should match email",
"joe.doe@gmail.com",
true,
"",
},
{
"Should match email with IP",
"joe.doe@192.168.1.5",
true,
"",
},
{
"Should match email with hostname without dot",
"joe.doe@somehostname",
true,
"",
},
{
"Should not match email with underscore",
"joe.doe@my_mail.com",
false,
"expected email",
},
{
"Should not match without hostname",
"joe.doe@",
false,
"expected email",
},
{
"Should not match without @",
"joe.doe[at]gmail.com",
false,
"expected email",
},
{
"Should not match user/box name",
"@gmail.com",
false,
"expected email",
},
{
"Should not match number",
1234,
false,
"expected email",
},
{
"Should not match slice",
[]interface{}{"a", "b"},
false,
"expected email",
},
}
func TestEmailMatcher(t *testing.T) {
pattern := "@pattern@"
for _, tt := range emailMatcherTests {
m := NewEmailMatcher(pattern)
assert.True(t, m.CanMatch(pattern), "expected to support pattern")
t.Logf(tt.desc)
ok, err := m.Match(pattern, tt.v)
if tt.ok {
assert.True(t, ok)
assert.Nil(t, err)
} else {
assert.False(t, ok)
assert.EqualError(t, err, tt.errMsg)
}
}
}