-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdocker_test.go
77 lines (67 loc) · 1.84 KB
/
mdocker_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
package mdocker_test
import (
"testing"
"github.com/fsouza/go-dockerclient"
"github.com/mistifyio/mistify-agent-docker"
"github.com/mistifyio/mistify-agent/rpc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
)
type MDockerTestSuite struct {
APITestSuite
}
func TestMDockerTestSuite(t *testing.T) {
suite.Run(t, new(MDockerTestSuite))
}
func (s *MDockerTestSuite) TestNew() {
tests := []struct {
description string
endpoint string
tlsCertPath string
expectedErr bool
}{
{"missing endpoint",
"", "", true},
{"bad endpoint",
"unix:///dev/null", "", true},
{"valid endpoint",
"unix:///var/run/docker.sock", "", false},
{"bad tls path",
"unix:///var/run/docker.sock", "/dev/null", true},
}
for _, test := range tests {
msg := testMsgFunc(test.description)
md, err := mdocker.New(test.endpoint, s.ImageService, test.tlsCertPath)
if test.expectedErr {
s.Error(err, msg("should fail"))
s.Nil(md, msg("failure shouldn't return a client"))
} else {
s.NoError(err, msg("should succeed"))
s.NotNil(md, msg("success should return a client"))
}
}
}
func (s *MDockerTestSuite) TestRequestOpts() {
var listOpts docker.ListContainersOptions
request := &rpc.ContainerRequest{
Opts: docker.ListContainersOptions{
Limit: 5,
},
}
s.NoError(s.MDocker.RequestOpts(request, &listOpts))
s.True(assert.ObjectsAreEqualValues(request.Opts, listOpts))
var saveOpts docker.CommitContainerOptions
request = &rpc.ContainerRequest{
Opts: docker.CommitContainerOptions{
Author: "asdf",
},
}
s.NoError(s.MDocker.RequestOpts(request, &saveOpts))
s.True(assert.ObjectsAreEqualValues(request.Opts, saveOpts))
}
func (s *MDockerTestSuite) TestGetInfo() {
request := &struct{}{}
response := &docker.DockerInfo{}
s.NoError(s.Client.Do("MDocker.GetInfo", request, response))
s.NotEmpty(response.ID)
}