forked from mailgun/mailgun-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_validation_test.go
41 lines (34 loc) · 955 Bytes
/
email_validation_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
package mailgun
import (
"testing"
"github.com/facebookgo/ensure"
)
func TestEmailValidation(t *testing.T) {
reqEnv(t, "MG_PUBLIC_API_KEY")
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
ev, err := mg.ValidateEmail("[email protected]")
ensure.Nil(t, err)
ensure.True(t, ev.IsValid)
ensure.True(t, ev.Parts.DisplayName == "")
ensure.DeepEqual(t, ev.Parts.LocalPart, "foo")
ensure.DeepEqual(t, ev.Parts.Domain, "mailgun.com")
}
func TestParseAddresses(t *testing.T) {
reqEnv(t, "MG_PUBLIC_API_KEY")
mg, err := NewMailgunFromEnv()
ensure.Nil(t, err)
addressesThatParsed, unparsableAddresses, err := mg.ParseAddresses(
"Alice <[email protected]>",
"example.com")
ensure.Nil(t, err)
hittest := map[string]bool{
"Alice <[email protected]>": true,
"[email protected]": true,
}
for _, a := range addressesThatParsed {
ensure.True(t, hittest[a])
}
ensure.True(t, len(unparsableAddresses) == 1)
}