-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsmtp_test.go
68 lines (63 loc) · 1.43 KB
/
smtp_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
package main
import (
"testing"
)
func TestNormalizeAddress(t *testing.T) {
goodAddrs := []struct {
rfc5322 string
name string
addr string
}{
{"Foo Bar <[email protected]>", "Foo Bar", "[email protected]"},
{"Bar <[email protected]>", "Bar", "[email protected]"},
{"[email protected]", "", "[email protected]"},
{"user@localhost", "", "user@localhost"},
{"<[email protected]>", "", "[email protected]"},
}
for _, addr := range goodAddrs {
addrObj, err := normalizeAddress(addr.rfc5322)
if err != nil {
t.Fatalf("Failed to parse valid RFC5322 string %s: %v", addr.rfc5322, err)
}
if addrObj.Name != addr.name {
t.Fatal("Name mismatch")
}
if addrObj.Address != addr.addr {
t.Fatal("Address mismatch")
}
}
}
func TestAddressParse(t *testing.T) {
/* No errors on good addresses */
addrs := []struct {
addr string
domain string
}{
{"[email protected]", "google.com"},
{"[email protected]", "grrransford.org"},
{"Foo Bar <[email protected]>", "bar.info"},
}
for _, tcase := range addrs {
_, err := getDomainFromAddress(tcase.addr)
if err != nil {
t.Fatalf("Failed to parse valid RFC5322 address %s: %v", tcase.addr, err)
}
}
/* Errors on bad addresses */
badAddrs := []string{
"foo",
"<foo>",
"foo.com",
"@foot.com",
"@bar",
"foo@",
"bl@h@[email protected]",
"",
}
for _, badaddr := range badAddrs {
_, err := getDomainFromAddress(badaddr)
if err == nil {
t.Fatal("err is nil; shoul be non-nil")
}
}
}