-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_test.go
106 lines (100 loc) · 3.13 KB
/
config_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package srsmilter
import (
"testing"
)
func toDomainSlice(in []string) (out []Domain) {
for _, i := range in {
out = append(out, ToDomain(i))
}
return
}
func TestConfiguration_HasLocalDomain(t *testing.T) {
tests := []struct {
name string
local []Domain
arg string
want bool
}{
{"empty1", toDomainSlice([]string{}), "", false},
{"empty2", toDomainSlice([]string{"example.com"}), "", false},
{"bogus1", toDomainSlice([]string{"example.com"}), "bogus domain", false},
{"single", toDomainSlice([]string{"example.com"}), "example.com", true},
{"multiple1", toDomainSlice([]string{"example.com", "example.net", "example.org"}), "example.com", true},
{"multiple2", toDomainSlice([]string{"example.com", "example.net", "example.org"}), "example.net", true},
{"multiple3", toDomainSlice([]string{"example.com", "example.net", "example.org"}), "example.org", true},
{"multiple4", toDomainSlice([]string{"example.com", "example.net", "example.org"}), "example.biz", false},
{"idna1", toDomainSlice([]string{"näkkileipä.example.com", "example.net", "example.org"}), "xn--nkkileip-0zah.example.com", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := Configuration{
LocalDomains: tt.local,
}
c.Setup()
if got := c.IsLocalDomain(tt.arg); got != tt.want {
t.Errorf("IsLocalDomain() = %v, want %v", got, tt.want)
}
})
}
}
func TestDomain_String(t *testing.T) {
tests := []struct {
name string
d Domain
want string
}{
{"bogus", ToDomain("bogus domain ü"), "bogus domain ü"},
{"simple", ToDomain("example.net"), "example.net"},
{"idna", ToDomain("näkkileipä.example.net"), "xn--nkkileip-0zah.example.net"},
{"ascii", ToDomain("xn--nkkileip-0zah.example.net"), "xn--nkkileip-0zah.example.net"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.d.String(); got != tt.want {
t.Errorf("String() = %v, want %v", got, tt.want)
}
})
}
}
func TestDomain_Unicode(t *testing.T) {
tests := []struct {
name string
d Domain
want string
}{
{"bogus", ToDomain("bogus domain ü"), "bogus domain ü"},
{"simple", ToDomain("example.net"), "example.net"},
{"idna", ToDomain("näkkileipä.example.net"), "näkkileipä.example.net"},
{"ascii", ToDomain("xn--nkkileip-0zah.example.net"), "näkkileipä.example.net"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.d.Unicode(); got != tt.want {
t.Errorf("Unicode() = %v, want %v", got, tt.want)
}
})
}
}
func Test_emailWithoutExtension(t *testing.T) {
type args struct {
local string
asciiDomain string
}
tests := []struct {
name string
args args
want string
}{
{"empty", args{"", ""}, "@"},
{"without", args{"local", "example.com"}, "[email protected]"},
{"with", args{"local+hi", "example.com"}, "[email protected]"},
{"double", args{"local+hi+ho", "example.com"}, "[email protected]"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := emailWithoutExtension(tt.args.local, tt.args.asciiDomain); got != tt.want {
t.Errorf("emailWithoutExtension() = %v, want %v", got, tt.want)
}
})
}
}