-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig_test.go
66 lines (47 loc) · 1.11 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
package smtpd
import "testing"
func TestWithListener(t *testing.T) {
l := Listener{
Address: "127.0.0.1",
Port: "8025",
Mode: "tls",
}
cfg := &Config{}
_ = WithListener(l)(cfg)
got := cfg.Listeners
if len(got) == 0 {
t.Fatalf("Listener not added to Config")
}
if got[0].Address != l.Address {
t.Errorf("Listener.Address got %s, want %s", got[0].Address, l.Address)
}
if got[0].Port != l.Port {
t.Errorf("Listener.Address got %s, want %s", got[0].Port, l.Port)
}
if got[0].Mode != l.Mode {
t.Errorf("Listener.Address got %s, want %s", got[0].Mode, l.Mode)
}
}
func TestWithListenerError(t *testing.T) {
l := Listener{}
cfg := &Config{}
err := WithListener(l)(cfg)
if err == nil {
t.Errorf("expected an error got none")
}
}
func TestWithListenerDefaultMode(t *testing.T) {
l := Listener{
Address: "127.0.0.1",
Port: "8025",
}
cfg := &Config{}
_ = WithListener(l)(cfg)
got := cfg.Listeners
if len(got) == 0 {
t.Fatalf("Listener not added to Config")
}
if got[0].Mode != "plain" {
t.Errorf("Empty Listener.Mode should default to 'plain', got '%s'", got[0].Mode)
}
}