-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_fetcher_mock.go
452 lines (364 loc) · 15.4 KB
/
request_fetcher_mock.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
package logicrunner
// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT.
import (
"context"
"sync"
mm_atomic "sync/atomic"
mm_time "time"
"github.com/gojuno/minimock"
)
// RequestFetcherMock implements RequestFetcher
type RequestFetcherMock struct {
t minimock.Tester
funcAbort func(ctx context.Context)
inspectFuncAbort func(ctx context.Context)
afterAbortCounter uint64
beforeAbortCounter uint64
AbortMock mRequestFetcherMockAbort
funcFetchPendings func(ctx context.Context)
inspectFuncFetchPendings func(ctx context.Context)
afterFetchPendingsCounter uint64
beforeFetchPendingsCounter uint64
FetchPendingsMock mRequestFetcherMockFetchPendings
}
// NewRequestFetcherMock returns a mock for RequestFetcher
func NewRequestFetcherMock(t minimock.Tester) *RequestFetcherMock {
m := &RequestFetcherMock{t: t}
if controller, ok := t.(minimock.MockController); ok {
controller.RegisterMocker(m)
}
m.AbortMock = mRequestFetcherMockAbort{mock: m}
m.AbortMock.callArgs = []*RequestFetcherMockAbortParams{}
m.FetchPendingsMock = mRequestFetcherMockFetchPendings{mock: m}
m.FetchPendingsMock.callArgs = []*RequestFetcherMockFetchPendingsParams{}
return m
}
type mRequestFetcherMockAbort struct {
mock *RequestFetcherMock
defaultExpectation *RequestFetcherMockAbortExpectation
expectations []*RequestFetcherMockAbortExpectation
callArgs []*RequestFetcherMockAbortParams
mutex sync.RWMutex
}
// RequestFetcherMockAbortExpectation specifies expectation struct of the RequestFetcher.Abort
type RequestFetcherMockAbortExpectation struct {
mock *RequestFetcherMock
params *RequestFetcherMockAbortParams
Counter uint64
}
// RequestFetcherMockAbortParams contains parameters of the RequestFetcher.Abort
type RequestFetcherMockAbortParams struct {
ctx context.Context
}
// Expect sets up expected params for RequestFetcher.Abort
func (mmAbort *mRequestFetcherMockAbort) Expect(ctx context.Context) *mRequestFetcherMockAbort {
if mmAbort.mock.funcAbort != nil {
mmAbort.mock.t.Fatalf("RequestFetcherMock.Abort mock is already set by Set")
}
if mmAbort.defaultExpectation == nil {
mmAbort.defaultExpectation = &RequestFetcherMockAbortExpectation{}
}
mmAbort.defaultExpectation.params = &RequestFetcherMockAbortParams{ctx}
for _, e := range mmAbort.expectations {
if minimock.Equal(e.params, mmAbort.defaultExpectation.params) {
mmAbort.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmAbort.defaultExpectation.params)
}
}
return mmAbort
}
// Inspect accepts an inspector function that has same arguments as the RequestFetcher.Abort
func (mmAbort *mRequestFetcherMockAbort) Inspect(f func(ctx context.Context)) *mRequestFetcherMockAbort {
if mmAbort.mock.inspectFuncAbort != nil {
mmAbort.mock.t.Fatalf("Inspect function is already set for RequestFetcherMock.Abort")
}
mmAbort.mock.inspectFuncAbort = f
return mmAbort
}
// Return sets up results that will be returned by RequestFetcher.Abort
func (mmAbort *mRequestFetcherMockAbort) Return() *RequestFetcherMock {
if mmAbort.mock.funcAbort != nil {
mmAbort.mock.t.Fatalf("RequestFetcherMock.Abort mock is already set by Set")
}
if mmAbort.defaultExpectation == nil {
mmAbort.defaultExpectation = &RequestFetcherMockAbortExpectation{mock: mmAbort.mock}
}
return mmAbort.mock
}
//Set uses given function f to mock the RequestFetcher.Abort method
func (mmAbort *mRequestFetcherMockAbort) Set(f func(ctx context.Context)) *RequestFetcherMock {
if mmAbort.defaultExpectation != nil {
mmAbort.mock.t.Fatalf("Default expectation is already set for the RequestFetcher.Abort method")
}
if len(mmAbort.expectations) > 0 {
mmAbort.mock.t.Fatalf("Some expectations are already set for the RequestFetcher.Abort method")
}
mmAbort.mock.funcAbort = f
return mmAbort.mock
}
// Abort implements RequestFetcher
func (mmAbort *RequestFetcherMock) Abort(ctx context.Context) {
mm_atomic.AddUint64(&mmAbort.beforeAbortCounter, 1)
defer mm_atomic.AddUint64(&mmAbort.afterAbortCounter, 1)
if mmAbort.inspectFuncAbort != nil {
mmAbort.inspectFuncAbort(ctx)
}
params := &RequestFetcherMockAbortParams{ctx}
// Record call args
mmAbort.AbortMock.mutex.Lock()
mmAbort.AbortMock.callArgs = append(mmAbort.AbortMock.callArgs, params)
mmAbort.AbortMock.mutex.Unlock()
for _, e := range mmAbort.AbortMock.expectations {
if minimock.Equal(e.params, params) {
mm_atomic.AddUint64(&e.Counter, 1)
return
}
}
if mmAbort.AbortMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmAbort.AbortMock.defaultExpectation.Counter, 1)
want := mmAbort.AbortMock.defaultExpectation.params
got := RequestFetcherMockAbortParams{ctx}
if want != nil && !minimock.Equal(*want, got) {
mmAbort.t.Errorf("RequestFetcherMock.Abort got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got))
}
return
}
if mmAbort.funcAbort != nil {
mmAbort.funcAbort(ctx)
return
}
mmAbort.t.Fatalf("Unexpected call to RequestFetcherMock.Abort. %v", ctx)
}
// AbortAfterCounter returns a count of finished RequestFetcherMock.Abort invocations
func (mmAbort *RequestFetcherMock) AbortAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmAbort.afterAbortCounter)
}
// AbortBeforeCounter returns a count of RequestFetcherMock.Abort invocations
func (mmAbort *RequestFetcherMock) AbortBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmAbort.beforeAbortCounter)
}
// Calls returns a list of arguments used in each call to RequestFetcherMock.Abort.
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
func (mmAbort *mRequestFetcherMockAbort) Calls() []*RequestFetcherMockAbortParams {
mmAbort.mutex.RLock()
argCopy := make([]*RequestFetcherMockAbortParams, len(mmAbort.callArgs))
copy(argCopy, mmAbort.callArgs)
mmAbort.mutex.RUnlock()
return argCopy
}
// MinimockAbortDone returns true if the count of the Abort invocations corresponds
// the number of defined expectations
func (m *RequestFetcherMock) MinimockAbortDone() bool {
for _, e := range m.AbortMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
return false
}
}
// if default expectation was set then invocations count should be greater than zero
if m.AbortMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterAbortCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcAbort != nil && mm_atomic.LoadUint64(&m.afterAbortCounter) < 1 {
return false
}
return true
}
// MinimockAbortInspect logs each unmet expectation
func (m *RequestFetcherMock) MinimockAbortInspect() {
for _, e := range m.AbortMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Errorf("Expected call to RequestFetcherMock.Abort with params: %#v", *e.params)
}
}
// if default expectation was set then invocations count should be greater than zero
if m.AbortMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterAbortCounter) < 1 {
if m.AbortMock.defaultExpectation.params == nil {
m.t.Error("Expected call to RequestFetcherMock.Abort")
} else {
m.t.Errorf("Expected call to RequestFetcherMock.Abort with params: %#v", *m.AbortMock.defaultExpectation.params)
}
}
// if func was set then invocations count should be greater than zero
if m.funcAbort != nil && mm_atomic.LoadUint64(&m.afterAbortCounter) < 1 {
m.t.Error("Expected call to RequestFetcherMock.Abort")
}
}
type mRequestFetcherMockFetchPendings struct {
mock *RequestFetcherMock
defaultExpectation *RequestFetcherMockFetchPendingsExpectation
expectations []*RequestFetcherMockFetchPendingsExpectation
callArgs []*RequestFetcherMockFetchPendingsParams
mutex sync.RWMutex
}
// RequestFetcherMockFetchPendingsExpectation specifies expectation struct of the RequestFetcher.FetchPendings
type RequestFetcherMockFetchPendingsExpectation struct {
mock *RequestFetcherMock
params *RequestFetcherMockFetchPendingsParams
Counter uint64
}
// RequestFetcherMockFetchPendingsParams contains parameters of the RequestFetcher.FetchPendings
type RequestFetcherMockFetchPendingsParams struct {
ctx context.Context
}
// Expect sets up expected params for RequestFetcher.FetchPendings
func (mmFetchPendings *mRequestFetcherMockFetchPendings) Expect(ctx context.Context) *mRequestFetcherMockFetchPendings {
if mmFetchPendings.mock.funcFetchPendings != nil {
mmFetchPendings.mock.t.Fatalf("RequestFetcherMock.FetchPendings mock is already set by Set")
}
if mmFetchPendings.defaultExpectation == nil {
mmFetchPendings.defaultExpectation = &RequestFetcherMockFetchPendingsExpectation{}
}
mmFetchPendings.defaultExpectation.params = &RequestFetcherMockFetchPendingsParams{ctx}
for _, e := range mmFetchPendings.expectations {
if minimock.Equal(e.params, mmFetchPendings.defaultExpectation.params) {
mmFetchPendings.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmFetchPendings.defaultExpectation.params)
}
}
return mmFetchPendings
}
// Inspect accepts an inspector function that has same arguments as the RequestFetcher.FetchPendings
func (mmFetchPendings *mRequestFetcherMockFetchPendings) Inspect(f func(ctx context.Context)) *mRequestFetcherMockFetchPendings {
if mmFetchPendings.mock.inspectFuncFetchPendings != nil {
mmFetchPendings.mock.t.Fatalf("Inspect function is already set for RequestFetcherMock.FetchPendings")
}
mmFetchPendings.mock.inspectFuncFetchPendings = f
return mmFetchPendings
}
// Return sets up results that will be returned by RequestFetcher.FetchPendings
func (mmFetchPendings *mRequestFetcherMockFetchPendings) Return() *RequestFetcherMock {
if mmFetchPendings.mock.funcFetchPendings != nil {
mmFetchPendings.mock.t.Fatalf("RequestFetcherMock.FetchPendings mock is already set by Set")
}
if mmFetchPendings.defaultExpectation == nil {
mmFetchPendings.defaultExpectation = &RequestFetcherMockFetchPendingsExpectation{mock: mmFetchPendings.mock}
}
return mmFetchPendings.mock
}
//Set uses given function f to mock the RequestFetcher.FetchPendings method
func (mmFetchPendings *mRequestFetcherMockFetchPendings) Set(f func(ctx context.Context)) *RequestFetcherMock {
if mmFetchPendings.defaultExpectation != nil {
mmFetchPendings.mock.t.Fatalf("Default expectation is already set for the RequestFetcher.FetchPendings method")
}
if len(mmFetchPendings.expectations) > 0 {
mmFetchPendings.mock.t.Fatalf("Some expectations are already set for the RequestFetcher.FetchPendings method")
}
mmFetchPendings.mock.funcFetchPendings = f
return mmFetchPendings.mock
}
// FetchPendings implements RequestFetcher
func (mmFetchPendings *RequestFetcherMock) FetchPendings(ctx context.Context) {
mm_atomic.AddUint64(&mmFetchPendings.beforeFetchPendingsCounter, 1)
defer mm_atomic.AddUint64(&mmFetchPendings.afterFetchPendingsCounter, 1)
if mmFetchPendings.inspectFuncFetchPendings != nil {
mmFetchPendings.inspectFuncFetchPendings(ctx)
}
params := &RequestFetcherMockFetchPendingsParams{ctx}
// Record call args
mmFetchPendings.FetchPendingsMock.mutex.Lock()
mmFetchPendings.FetchPendingsMock.callArgs = append(mmFetchPendings.FetchPendingsMock.callArgs, params)
mmFetchPendings.FetchPendingsMock.mutex.Unlock()
for _, e := range mmFetchPendings.FetchPendingsMock.expectations {
if minimock.Equal(e.params, params) {
mm_atomic.AddUint64(&e.Counter, 1)
return
}
}
if mmFetchPendings.FetchPendingsMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmFetchPendings.FetchPendingsMock.defaultExpectation.Counter, 1)
want := mmFetchPendings.FetchPendingsMock.defaultExpectation.params
got := RequestFetcherMockFetchPendingsParams{ctx}
if want != nil && !minimock.Equal(*want, got) {
mmFetchPendings.t.Errorf("RequestFetcherMock.FetchPendings got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got))
}
return
}
if mmFetchPendings.funcFetchPendings != nil {
mmFetchPendings.funcFetchPendings(ctx)
return
}
mmFetchPendings.t.Fatalf("Unexpected call to RequestFetcherMock.FetchPendings. %v", ctx)
}
// FetchPendingsAfterCounter returns a count of finished RequestFetcherMock.FetchPendings invocations
func (mmFetchPendings *RequestFetcherMock) FetchPendingsAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmFetchPendings.afterFetchPendingsCounter)
}
// FetchPendingsBeforeCounter returns a count of RequestFetcherMock.FetchPendings invocations
func (mmFetchPendings *RequestFetcherMock) FetchPendingsBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmFetchPendings.beforeFetchPendingsCounter)
}
// Calls returns a list of arguments used in each call to RequestFetcherMock.FetchPendings.
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
func (mmFetchPendings *mRequestFetcherMockFetchPendings) Calls() []*RequestFetcherMockFetchPendingsParams {
mmFetchPendings.mutex.RLock()
argCopy := make([]*RequestFetcherMockFetchPendingsParams, len(mmFetchPendings.callArgs))
copy(argCopy, mmFetchPendings.callArgs)
mmFetchPendings.mutex.RUnlock()
return argCopy
}
// MinimockFetchPendingsDone returns true if the count of the FetchPendings invocations corresponds
// the number of defined expectations
func (m *RequestFetcherMock) MinimockFetchPendingsDone() bool {
for _, e := range m.FetchPendingsMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
return false
}
}
// if default expectation was set then invocations count should be greater than zero
if m.FetchPendingsMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFetchPendingsCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcFetchPendings != nil && mm_atomic.LoadUint64(&m.afterFetchPendingsCounter) < 1 {
return false
}
return true
}
// MinimockFetchPendingsInspect logs each unmet expectation
func (m *RequestFetcherMock) MinimockFetchPendingsInspect() {
for _, e := range m.FetchPendingsMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Errorf("Expected call to RequestFetcherMock.FetchPendings with params: %#v", *e.params)
}
}
// if default expectation was set then invocations count should be greater than zero
if m.FetchPendingsMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFetchPendingsCounter) < 1 {
if m.FetchPendingsMock.defaultExpectation.params == nil {
m.t.Error("Expected call to RequestFetcherMock.FetchPendings")
} else {
m.t.Errorf("Expected call to RequestFetcherMock.FetchPendings with params: %#v", *m.FetchPendingsMock.defaultExpectation.params)
}
}
// if func was set then invocations count should be greater than zero
if m.funcFetchPendings != nil && mm_atomic.LoadUint64(&m.afterFetchPendingsCounter) < 1 {
m.t.Error("Expected call to RequestFetcherMock.FetchPendings")
}
}
// MinimockFinish checks that all mocked methods have been called the expected number of times
func (m *RequestFetcherMock) MinimockFinish() {
if !m.minimockDone() {
m.MinimockAbortInspect()
m.MinimockFetchPendingsInspect()
m.t.FailNow()
}
}
// MinimockWait waits for all mocked methods to be called the expected number of times
func (m *RequestFetcherMock) MinimockWait(timeout mm_time.Duration) {
timeoutCh := mm_time.After(timeout)
for {
if m.minimockDone() {
return
}
select {
case <-timeoutCh:
m.MinimockFinish()
return
case <-mm_time.After(10 * mm_time.Millisecond):
}
}
}
func (m *RequestFetcherMock) minimockDone() bool {
done := true
return done &&
m.MinimockAbortDone() &&
m.MinimockFetchPendingsDone()
}