-
Notifications
You must be signed in to change notification settings - Fork 1
/
service_test.go
60 lines (51 loc) · 1.27 KB
/
service_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
package dockertest
import (
"errors"
"fmt"
"net"
. "gopkg.in/check.v1"
)
type ServiceTest struct{}
var _ = Suite(&ServiceTest{})
func (*ServiceTest) TestNoInput(c *C) {
s := &Service{}
c.Assert(s.Run(), ErrorMatches, ErrInputNotProvided.Error())
}
func (*ServiceTest) TestRunWithPing(c *C) {
dc, err := NewClient()
c.Assert(err, IsNil)
defer dc.docker.Close() // nolint: errcheck
input := NewClientInput(testImage)
input.Ports.Add(&Port{
Private: 80,
Public: RandomPort,
Protocol: ProtocolTCP,
})
svc := dc.Service(input)
svc.Ping = func(input *PingInput) error {
port, err := input.Container.Port(80)
c.Assert(err, IsNil)
for {
con, err := net.Dial(string(port.Protocol), fmt.Sprintf("%s:%d", port.Address, port.Public))
if err != nil {
continue
}
defer con.Close() // nolint: errcheck
return nil
}
}
c.Assert(svc.Run(), IsNil)
c.Assert(svc.Terminate(), IsNil)
}
func (*ServiceTest) TestErrorOnPingCallsTerminate(c *C) {
dc, err := NewClient()
c.Assert(err, IsNil)
defer dc.docker.Close() // nolint: errcheck
input := NewClientInput(testImage)
svc := dc.Service(input)
svc.Ping = func(input *PingInput) error {
return errors.New("some error")
}
c.Assert(svc.Run(), ErrorMatches, "some error")
c.Assert(svc.Terminate(), IsNil)
}