/
dockerclient.go
287 lines (267 loc) · 8.83 KB
/
dockerclient.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mocks
import (
"context"
"github.com/docker/docker/api/types"
"github.com/swisscom/korp/docker_utils"
"io"
"sync"
)
var (
lockDockerClientMockClose sync.RWMutex
lockDockerClientMockContainerList sync.RWMutex
lockDockerClientMockImagePull sync.RWMutex
lockDockerClientMockImagePush sync.RWMutex
lockDockerClientMockImageTag sync.RWMutex
)
// Ensure, that DockerClientMock does implement DockerClient.
// If this is not the case, regenerate this file with moq.
var _ docker_utils.DockerClient = &DockerClientMock{}
// DockerClientMock is a mock implementation of DockerClient.
//
// func TestSomethingThatUsesDockerClient(t *testing.T) {
//
// // make and configure a mocked DockerClient
// mockedDockerClient := &DockerClientMock{
// CloseFunc: func() error {
// panic("mock out the Close method")
// },
// ContainerListFunc: func(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) {
// panic("mock out the ContainerList method")
// },
// ImagePullFunc: func(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error) {
// panic("mock out the ImagePull method")
// },
// ImagePushFunc: func(ctx context.Context, image string, options types.ImagePushOptions) (io.ReadCloser, error) {
// panic("mock out the ImagePush method")
// },
// ImageTagFunc: func(ctx context.Context, source string, target string) error {
// panic("mock out the ImageTag method")
// },
// }
//
// // use mockedDockerClient in code that requires DockerClient
// // and then make assertions.
//
// }
type DockerClientMock struct {
// CloseFunc mocks the Close method.
CloseFunc func() error
// ContainerListFunc mocks the ContainerList method.
ContainerListFunc func(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
// ImagePullFunc mocks the ImagePull method.
ImagePullFunc func(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error)
// ImagePushFunc mocks the ImagePush method.
ImagePushFunc func(ctx context.Context, image string, options types.ImagePushOptions) (io.ReadCloser, error)
// ImageTagFunc mocks the ImageTag method.
ImageTagFunc func(ctx context.Context, source string, target string) error
// calls tracks calls to the methods.
calls struct {
// Close holds details about calls to the Close method.
Close []struct {
}
// ContainerList holds details about calls to the ContainerList method.
ContainerList []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Options is the options argument value.
Options types.ContainerListOptions
}
// ImagePull holds details about calls to the ImagePull method.
ImagePull []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// RefStr is the refStr argument value.
RefStr string
// Options is the options argument value.
Options types.ImagePullOptions
}
// ImagePush holds details about calls to the ImagePush method.
ImagePush []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Image is the image argument value.
Image string
// Options is the options argument value.
Options types.ImagePushOptions
}
// ImageTag holds details about calls to the ImageTag method.
ImageTag []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Source is the source argument value.
Source string
// Target is the target argument value.
Target string
}
}
}
// Close calls CloseFunc.
func (mock *DockerClientMock) Close() error {
if mock.CloseFunc == nil {
panic("DockerClientMock.CloseFunc: method is nil but DockerClient.Close was just called")
}
callInfo := struct {
}{}
lockDockerClientMockClose.Lock()
mock.calls.Close = append(mock.calls.Close, callInfo)
lockDockerClientMockClose.Unlock()
return mock.CloseFunc()
}
// CloseCalls gets all the calls that were made to Close.
// Check the length with:
// len(mockedDockerClient.CloseCalls())
func (mock *DockerClientMock) CloseCalls() []struct {
} {
var calls []struct {
}
lockDockerClientMockClose.RLock()
calls = mock.calls.Close
lockDockerClientMockClose.RUnlock()
return calls
}
// ContainerList calls ContainerListFunc.
func (mock *DockerClientMock) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) {
if mock.ContainerListFunc == nil {
panic("DockerClientMock.ContainerListFunc: method is nil but DockerClient.ContainerList was just called")
}
callInfo := struct {
Ctx context.Context
Options types.ContainerListOptions
}{
Ctx: ctx,
Options: options,
}
lockDockerClientMockContainerList.Lock()
mock.calls.ContainerList = append(mock.calls.ContainerList, callInfo)
lockDockerClientMockContainerList.Unlock()
return mock.ContainerListFunc(ctx, options)
}
// ContainerListCalls gets all the calls that were made to ContainerList.
// Check the length with:
// len(mockedDockerClient.ContainerListCalls())
func (mock *DockerClientMock) ContainerListCalls() []struct {
Ctx context.Context
Options types.ContainerListOptions
} {
var calls []struct {
Ctx context.Context
Options types.ContainerListOptions
}
lockDockerClientMockContainerList.RLock()
calls = mock.calls.ContainerList
lockDockerClientMockContainerList.RUnlock()
return calls
}
// ImagePull calls ImagePullFunc.
func (mock *DockerClientMock) ImagePull(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error) {
if mock.ImagePullFunc == nil {
panic("DockerClientMock.ImagePullFunc: method is nil but DockerClient.ImagePull was just called")
}
callInfo := struct {
Ctx context.Context
RefStr string
Options types.ImagePullOptions
}{
Ctx: ctx,
RefStr: refStr,
Options: options,
}
lockDockerClientMockImagePull.Lock()
mock.calls.ImagePull = append(mock.calls.ImagePull, callInfo)
lockDockerClientMockImagePull.Unlock()
return mock.ImagePullFunc(ctx, refStr, options)
}
// ImagePullCalls gets all the calls that were made to ImagePull.
// Check the length with:
// len(mockedDockerClient.ImagePullCalls())
func (mock *DockerClientMock) ImagePullCalls() []struct {
Ctx context.Context
RefStr string
Options types.ImagePullOptions
} {
var calls []struct {
Ctx context.Context
RefStr string
Options types.ImagePullOptions
}
lockDockerClientMockImagePull.RLock()
calls = mock.calls.ImagePull
lockDockerClientMockImagePull.RUnlock()
return calls
}
// ImagePush calls ImagePushFunc.
func (mock *DockerClientMock) ImagePush(ctx context.Context, image string, options types.ImagePushOptions) (io.ReadCloser, error) {
if mock.ImagePushFunc == nil {
panic("DockerClientMock.ImagePushFunc: method is nil but DockerClient.ImagePush was just called")
}
callInfo := struct {
Ctx context.Context
Image string
Options types.ImagePushOptions
}{
Ctx: ctx,
Image: image,
Options: options,
}
lockDockerClientMockImagePush.Lock()
mock.calls.ImagePush = append(mock.calls.ImagePush, callInfo)
lockDockerClientMockImagePush.Unlock()
return mock.ImagePushFunc(ctx, image, options)
}
// ImagePushCalls gets all the calls that were made to ImagePush.
// Check the length with:
// len(mockedDockerClient.ImagePushCalls())
func (mock *DockerClientMock) ImagePushCalls() []struct {
Ctx context.Context
Image string
Options types.ImagePushOptions
} {
var calls []struct {
Ctx context.Context
Image string
Options types.ImagePushOptions
}
lockDockerClientMockImagePush.RLock()
calls = mock.calls.ImagePush
lockDockerClientMockImagePush.RUnlock()
return calls
}
// ImageTag calls ImageTagFunc.
func (mock *DockerClientMock) ImageTag(ctx context.Context, source string, target string) error {
if mock.ImageTagFunc == nil {
panic("DockerClientMock.ImageTagFunc: method is nil but DockerClient.ImageTag was just called")
}
callInfo := struct {
Ctx context.Context
Source string
Target string
}{
Ctx: ctx,
Source: source,
Target: target,
}
lockDockerClientMockImageTag.Lock()
mock.calls.ImageTag = append(mock.calls.ImageTag, callInfo)
lockDockerClientMockImageTag.Unlock()
return mock.ImageTagFunc(ctx, source, target)
}
// ImageTagCalls gets all the calls that were made to ImageTag.
// Check the length with:
// len(mockedDockerClient.ImageTagCalls())
func (mock *DockerClientMock) ImageTagCalls() []struct {
Ctx context.Context
Source string
Target string
} {
var calls []struct {
Ctx context.Context
Source string
Target string
}
lockDockerClientMockImageTag.RLock()
calls = mock.calls.ImageTag
lockDockerClientMockImageTag.RUnlock()
return calls
}