-
Notifications
You must be signed in to change notification settings - Fork 1
/
ports_test.go
74 lines (64 loc) · 1.55 KB
/
ports_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
package dockertest
import (
"github.com/docker/go-connections/nat"
. "gopkg.in/check.v1"
)
type TestPorts struct{}
var _ = Suite(&TestPorts{})
func (s *TestPorts) TestNewPorts(c *C) {
ports := NewPorts()
c.Assert(ports, DeepEquals, &Ports{Specs: []*Port{}})
}
func (s *TestPorts) TestPortPort(c *C) {
port := &Port{
Protocol: ProtocolUDP,
Private: 5555,
}
expected, err := nat.NewPort(string(ProtocolUDP), "5555")
np, err := port.Port()
c.Assert(err, IsNil)
c.Assert(np, Equals, expected)
port = &Port{
Private: 5555,
}
_, err = port.Port()
c.Assert(err, ErrorMatches, "Protocol not specified")
}
func (s *TestPorts) TestPortBinding(c *C) {
port := &Port{
Protocol: ProtocolUDP,
Address: "1.2.3.4",
Public: 1234,
}
c.Assert(port.Binding(), DeepEquals, nat.PortBinding{HostIP: "1.2.3.4", HostPort: "1234"})
port = &Port{
Protocol: ProtocolUDP,
Public: 1234,
}
c.Assert(port.Binding(), DeepEquals, nat.PortBinding{HostIP: "0.0.0.0", HostPort: "1234"})
}
func (s *TestPorts) TestPortsAdd(c *C) {
ports := NewPorts()
port := &Port{
Protocol: ProtocolUDP,
Address: "1.2.3.4",
Public: 1234,
}
ports.Add(port)
c.Assert(ports.Specs, DeepEquals, []*Port{port})
}
func (s *TestPorts) TestPortsBindings(c *C) {
ports := NewPorts()
port := &Port{
Protocol: ProtocolUDP,
Address: "1.2.3.4",
Public: 1234,
Private: 4567,
}
ports.Add(port)
bindings, err := ports.Bindings()
c.Assert(err, IsNil)
mapping := nat.PortMap{}
mapping["4567/udp"] = []nat.PortBinding{port.Binding()}
c.Assert(bindings, DeepEquals, mapping)
}