-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserver_test.go
98 lines (82 loc) · 1.91 KB
/
server_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
// Copyright (C) 2017 Kale Blankenship. All rights reserved.
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details
package tftp // import "pack.ag/tftp"
import "testing"
func TestNewServer(t *testing.T) {
t.Parallel()
cases := []struct {
name string
addr string
opts []ServerOpt
expectedAddrStr string
expectedNet string
expectedRetransmit int
expectedError error
}{
{
name: "default",
addr: "",
expectedNet: "udp",
expectedRetransmit: 10,
},
{
name: "net udp6",
addr: "",
opts: []ServerOpt{
ServerNet("udp6"),
},
expectedNet: "udp6",
expectedRetransmit: 10,
},
{
name: "net, invalid",
addr: "",
opts: []ServerOpt{
ServerNet("tcp"),
},
expectedError: ErrInvalidNetwork,
},
{
name: "retransmit, valid",
addr: "",
opts: []ServerOpt{
ServerRetransmit(2),
},
expectedNet: "udp",
expectedRetransmit: 2,
},
{
name: "retransmit, invalid",
addr: "",
opts: []ServerOpt{
ServerRetransmit(-1),
},
expectedError: ErrInvalidRetransmit,
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
server, err := NewServer(c.addr, c.opts...)
// Error
if err != c.expectedError {
t.Errorf("expected %#v to be %#v", err, c.expectedError)
}
if err != nil {
return // Skip remaining test if error, avoid nil dereference
}
// Addr
if server.addrStr != c.expectedAddrStr {
t.Errorf("expected addr to be %q, but it was %q", c.expectedAddrStr, server.addrStr)
}
// Net
if server.net != c.expectedNet {
t.Errorf("expected net to be %q, but it was %q", c.expectedNet, server.net)
}
// Retransmit
if server.retransmit != c.expectedRetransmit {
t.Errorf("expected retransmit to be %d, but it was %d", c.expectedRetransmit, server.retransmit)
}
})
}
}