-
Notifications
You must be signed in to change notification settings - Fork 1
/
addr_test.go
59 lines (56 loc) · 1.68 KB
/
addr_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
package srsmilter
import (
"net/mail"
"reflect"
"testing"
)
func Test_split(t *testing.T) {
tests := []struct {
name string
email string
wantLocal string
wantDomain Domain
}{
{"empty", "", "", ""},
{"without domain", "root", "root", ""},
{"with domain", "root@localhost", "root", ToDomain("localhost")},
{"with two ats", "root@crazy@localhost", "root@crazy", ToDomain("localhost")},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotLocal, gotDomain := split(tt.email)
if gotLocal != tt.wantLocal {
t.Errorf("split() gotLocal = %v, want %v", gotLocal, tt.wantLocal)
}
if gotDomain != tt.wantDomain {
t.Errorf("split() gotDomain = %v, want %v", gotDomain, tt.wantDomain)
}
})
}
}
func Test_parseAddressList(t *testing.T) {
tests := []struct {
name string
in string
wantList []*mail.Address
wantErr bool
}{
{"empty", "", nil, false},
{"one", "root@localhost", []*mail.Address{{Address: "root@localhost"}}, false},
{"padded", " ,,,root@localhost\n,", []*mail.Address{{Address: "root@localhost"}}, false},
{"two", " ,,,root@localhost\n,[email protected]\r\r\n", []*mail.Address{{Address: "root@localhost"}, {Address: "[email protected]"}}, false},
{"broken", " ,,,root@localhost\n,[email protected]\rbroken\r\n", nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotList, err := parseAddressList(tt.in)
if (err != nil) != tt.wantErr {
t.Errorf("parseAddressList() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(gotList, tt.wantList) {
t.Errorf("parseAddressList() gotList = %v, want %v", gotList, tt.wantList)
}
})
}
}