-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchain_test.go
42 lines (37 loc) · 1.12 KB
/
chain_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
package emailvalidator
import (
"testing"
"github.com/sufimalek/emailvalidator/validators"
)
func TestValidatorChain(t *testing.T) {
chain := NewValidatorChainBuilder().
Add(&validators.SyntaxValidator{}).
Add(&validators.RoleValidator{}).
Add(&validators.MXValidator{}).
Add(&validators.SMTPValidator{}).
Add(validators.NewBanWordsUsernameValidator([]string{"spam", "junk"})).
Add(validators.NewBlackListEmailsValidator([]string{"blacklisted@example.com"})).
Add(&validators.DNSCheckValidator{}).
Add(&validators.RFCValidator{}).
Add(&validators.NoRFCWarningsValidator{}).
// Add(&validators.GravatarValidator{}).
Build()
tests := []struct {
email string
isValid bool
}{
{"admin@example.com", false},
{"user@gmail.com", false},
{"spamuser@example.com", false},
{"blacklisted@example.com", false},
{"invalid@invalid-domain.com", false},
{"user@.com", false},
{"@example.com", false},
{"good@domain.com", true},
}
for _, test := range tests {
if chain.Validate(test.email) != test.isValid {
t.Errorf("expected %v for email %s, got %v", test.isValid, test.email, !test.isValid)
}
}
}