forked from badoux/checkmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckmail_test.go
58 lines (52 loc) · 1.68 KB
/
checkmail_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
package checkmail_test
import (
"testing"
"github.com/badoux/checkmail"
)
var (
samples = []struct {
mail string
format bool
account bool //host+user
}{
{mail: "[email protected]", format: true, account: true},
{mail: "[email protected]", format: true, account: false},
{mail: " [email protected]", format: false, account: false},
{mail: "[email protected] ", format: false, account: false},
{mail: "[email protected]", format: true, account: false},
{mail: "[email protected]", format: true, account: false},
{mail: "@gmail.com", format: false, account: false},
{mail: "test@[email protected]", format: false, account: false},
{mail: "test [email protected]", format: false, account: false},
{mail: " [email protected]", format: false, account: false},
{mail: "test@wrong domain.com", format: false, account: false},
{mail: "é&ààà@gmail.com", format: false, account: false},
{mail: "[email protected]", format: true, account: false},
{mail: "[email protected]", format: true, account: false},
}
)
func TestValidateHost(t *testing.T) {
for _, s := range samples {
if !s.format {
continue
}
err := checkmail.ValidateHost(s.mail)
if err != nil && s.account == true {
t.Errorf(`"%s" => unexpected error: "%v"`, s.mail, err)
}
if err == nil && s.account == false {
t.Errorf(`"%s" => expected error`, s.mail)
}
}
}
func TestValidateFormat(t *testing.T) {
for _, s := range samples {
err := checkmail.ValidateFormat(s.mail)
if err != nil && s.format == true {
t.Errorf(`"%s" => unexpected error: "%v"`, s.mail, err)
}
if err == nil && s.format == false {
t.Errorf(`"%s" => expected error`, s.mail)
}
}
}