/
client_moq.go
289 lines (270 loc) · 7.84 KB
/
client_moq.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
288
289
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package client
import (
"context"
"net/http"
"net/url"
"sync"
)
// Ensure, that IClientMock does implement IClient.
// If this is not the case, regenerate this file with moq.
var _ IClient = &IClientMock{}
// IClientMock is a mock implementation of IClient.
//
// func TestSomethingThatUsesIClient(t *testing.T) {
//
// // make and configure a mocked IClient
// mockedIClient := &IClientMock{
// baseURLGetterFunc: func() *url.URL {
// panic("mock out the baseURLGetter method")
// },
// doFunc: func(ctx context.Context, req *http.Request, v interface{}) (*Response, error) {
// panic("mock out the do method")
// },
// dumpHTTPFunc: func(req *http.Request, resp *http.Response) error {
// panic("mock out the dumpHTTP method")
// },
// newRequestFunc: func(method string, path string, body interface{}) (*http.Request, error) {
// panic("mock out the newRequest method")
// },
// postFormFunc: func(ctx context.Context, urlMoqParam string, data url.Values, v interface{}) (*Response, error) {
// panic("mock out the postForm method")
// },
// }
//
// // use mockedIClient in code that requires IClient
// // and then make assertions.
//
// }
type IClientMock struct {
// baseURLGetterFunc mocks the baseURLGetter method.
baseURLGetterFunc func() *url.URL
// doFunc mocks the do method.
doFunc func(ctx context.Context, req *http.Request, v interface{}) (*Response, error)
// dumpHTTPFunc mocks the dumpHTTP method.
dumpHTTPFunc func(req *http.Request, resp *http.Response) error
// newRequestFunc mocks the newRequest method.
newRequestFunc func(method string, path string, body interface{}) (*http.Request, error)
// postFormFunc mocks the postForm method.
postFormFunc func(ctx context.Context, urlMoqParam string, data url.Values, v interface{}) (*Response, error)
// calls tracks calls to the methods.
calls struct {
// baseURLGetter holds details about calls to the baseURLGetter method.
baseURLGetter []struct {
}
// do holds details about calls to the do method.
do []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Req is the req argument value.
Req *http.Request
// V is the v argument value.
V interface{}
}
// dumpHTTP holds details about calls to the dumpHTTP method.
dumpHTTP []struct {
// Req is the req argument value.
Req *http.Request
// Resp is the resp argument value.
Resp *http.Response
}
// newRequest holds details about calls to the newRequest method.
newRequest []struct {
// Method is the method argument value.
Method string
// Path is the path argument value.
Path string
// Body is the body argument value.
Body interface{}
}
// postForm holds details about calls to the postForm method.
postForm []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// UrlMoqParam is the urlMoqParam argument value.
UrlMoqParam string
// Data is the data argument value.
Data url.Values
// V is the v argument value.
V interface{}
}
}
lockbaseURLGetter sync.RWMutex
lockdo sync.RWMutex
lockdumpHTTP sync.RWMutex
locknewRequest sync.RWMutex
lockpostForm sync.RWMutex
}
// baseURLGetter calls baseURLGetterFunc.
func (mock *IClientMock) baseURLGetter() *url.URL {
if mock.baseURLGetterFunc == nil {
panic("IClientMock.baseURLGetterFunc: method is nil but IClient.baseURLGetter was just called")
}
callInfo := struct {
}{}
mock.lockbaseURLGetter.Lock()
mock.calls.baseURLGetter = append(mock.calls.baseURLGetter, callInfo)
mock.lockbaseURLGetter.Unlock()
return mock.baseURLGetterFunc()
}
// baseURLGetterCalls gets all the calls that were made to baseURLGetter.
// Check the length with:
// len(mockedIClient.baseURLGetterCalls())
func (mock *IClientMock) baseURLGetterCalls() []struct {
} {
var calls []struct {
}
mock.lockbaseURLGetter.RLock()
calls = mock.calls.baseURLGetter
mock.lockbaseURLGetter.RUnlock()
return calls
}
// do calls doFunc.
func (mock *IClientMock) do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) {
if mock.doFunc == nil {
panic("IClientMock.doFunc: method is nil but IClient.do was just called")
}
callInfo := struct {
Ctx context.Context
Req *http.Request
V interface{}
}{
Ctx: ctx,
Req: req,
V: v,
}
mock.lockdo.Lock()
mock.calls.do = append(mock.calls.do, callInfo)
mock.lockdo.Unlock()
return mock.doFunc(ctx, req, v)
}
// doCalls gets all the calls that were made to do.
// Check the length with:
// len(mockedIClient.doCalls())
func (mock *IClientMock) doCalls() []struct {
Ctx context.Context
Req *http.Request
V interface{}
} {
var calls []struct {
Ctx context.Context
Req *http.Request
V interface{}
}
mock.lockdo.RLock()
calls = mock.calls.do
mock.lockdo.RUnlock()
return calls
}
// dumpHTTP calls dumpHTTPFunc.
func (mock *IClientMock) dumpHTTP(req *http.Request, resp *http.Response) error {
if mock.dumpHTTPFunc == nil {
panic("IClientMock.dumpHTTPFunc: method is nil but IClient.dumpHTTP was just called")
}
callInfo := struct {
Req *http.Request
Resp *http.Response
}{
Req: req,
Resp: resp,
}
mock.lockdumpHTTP.Lock()
mock.calls.dumpHTTP = append(mock.calls.dumpHTTP, callInfo)
mock.lockdumpHTTP.Unlock()
return mock.dumpHTTPFunc(req, resp)
}
// dumpHTTPCalls gets all the calls that were made to dumpHTTP.
// Check the length with:
// len(mockedIClient.dumpHTTPCalls())
func (mock *IClientMock) dumpHTTPCalls() []struct {
Req *http.Request
Resp *http.Response
} {
var calls []struct {
Req *http.Request
Resp *http.Response
}
mock.lockdumpHTTP.RLock()
calls = mock.calls.dumpHTTP
mock.lockdumpHTTP.RUnlock()
return calls
}
// newRequest calls newRequestFunc.
func (mock *IClientMock) newRequest(method string, path string, body interface{}) (*http.Request, error) {
if mock.newRequestFunc == nil {
panic("IClientMock.newRequestFunc: method is nil but IClient.newRequest was just called")
}
callInfo := struct {
Method string
Path string
Body interface{}
}{
Method: method,
Path: path,
Body: body,
}
mock.locknewRequest.Lock()
mock.calls.newRequest = append(mock.calls.newRequest, callInfo)
mock.locknewRequest.Unlock()
return mock.newRequestFunc(method, path, body)
}
// newRequestCalls gets all the calls that were made to newRequest.
// Check the length with:
// len(mockedIClient.newRequestCalls())
func (mock *IClientMock) newRequestCalls() []struct {
Method string
Path string
Body interface{}
} {
var calls []struct {
Method string
Path string
Body interface{}
}
mock.locknewRequest.RLock()
calls = mock.calls.newRequest
mock.locknewRequest.RUnlock()
return calls
}
// postForm calls postFormFunc.
func (mock *IClientMock) postForm(ctx context.Context, urlMoqParam string, data url.Values, v interface{}) (*Response, error) {
if mock.postFormFunc == nil {
panic("IClientMock.postFormFunc: method is nil but IClient.postForm was just called")
}
callInfo := struct {
Ctx context.Context
UrlMoqParam string
Data url.Values
V interface{}
}{
Ctx: ctx,
UrlMoqParam: urlMoqParam,
Data: data,
V: v,
}
mock.lockpostForm.Lock()
mock.calls.postForm = append(mock.calls.postForm, callInfo)
mock.lockpostForm.Unlock()
return mock.postFormFunc(ctx, urlMoqParam, data, v)
}
// postFormCalls gets all the calls that were made to postForm.
// Check the length with:
// len(mockedIClient.postFormCalls())
func (mock *IClientMock) postFormCalls() []struct {
Ctx context.Context
UrlMoqParam string
Data url.Values
V interface{}
} {
var calls []struct {
Ctx context.Context
UrlMoqParam string
Data url.Values
V interface{}
}
mock.lockpostForm.RLock()
calls = mock.calls.postForm
mock.lockpostForm.RUnlock()
return calls
}