-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
listener_windows_test.go
100 lines (89 loc) · 1.59 KB
/
listener_windows_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
//go:build windows
// +build windows
package atreugo
import (
"testing"
)
func TestAtreugo_getListener(t *testing.T) { // nolint:funlen
type want struct {
addr string
network string
err bool
}
tests := []struct {
name string
args Config
want want
}{
{
name: "Ok",
args: Config{
Addr: "127.0.0.1:8000",
},
want: want{
addr: "127.0.0.1:8000",
network: "tcp",
err: false,
},
},
{
name: "Reuseport",
args: Config{
Addr: "127.0.0.1:8000",
Network: "tcp4",
Reuseport: true,
},
want: want{
addr: "127.0.0.1:8000",
network: "tcp",
err: false,
},
},
{
name: "Unix",
args: Config{
Addr: "/tmp/test.sock",
Network: "unix",
},
want: want{
err: true,
},
},
{
name: "Error",
args: Config{
Network: "fake",
},
want: want{
err: true,
},
},
}
for _, test := range tests {
tt := test
t.Run(tt.name, func(t *testing.T) {
defer func() {
err := recover()
if tt.want.err && err == nil {
t.Errorf("Panic expected")
} else if !tt.want.err && err != nil {
t.Errorf("Unexpected panic: %v", err)
}
}()
s := New(tt.args)
ln, err := s.getListener()
if err != nil {
panic(err)
}
defer ln.Close()
lnAddress := ln.Addr().String()
if lnAddress != tt.want.addr {
t.Errorf("Listener address: '%s', want '%s'", lnAddress, tt.want.addr)
}
lnNetwork := ln.Addr().Network()
if lnNetwork != tt.want.network {
t.Errorf("Listener network: '%s', want '%s'", lnNetwork, tt.want.network)
}
})
}
}