-
Notifications
You must be signed in to change notification settings - Fork 0
/
jet_releaser_mock.go
484 lines (396 loc) · 17.2 KB
/
jet_releaser_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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
package executor
// 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"
"github.com/insolar/insolar/insolar"
)
// JetReleaserMock implements JetReleaser
type JetReleaserMock struct {
t minimock.Tester
funcCloseAllUntil func(ctx context.Context, pulse insolar.PulseNumber)
inspectFuncCloseAllUntil func(ctx context.Context, pulse insolar.PulseNumber)
afterCloseAllUntilCounter uint64
beforeCloseAllUntilCounter uint64
CloseAllUntilMock mJetReleaserMockCloseAllUntil
funcUnlock func(ctx context.Context, pulse insolar.PulseNumber, jetID insolar.JetID) (err error)
inspectFuncUnlock func(ctx context.Context, pulse insolar.PulseNumber, jetID insolar.JetID)
afterUnlockCounter uint64
beforeUnlockCounter uint64
UnlockMock mJetReleaserMockUnlock
}
// NewJetReleaserMock returns a mock for JetReleaser
func NewJetReleaserMock(t minimock.Tester) *JetReleaserMock {
m := &JetReleaserMock{t: t}
if controller, ok := t.(minimock.MockController); ok {
controller.RegisterMocker(m)
}
m.CloseAllUntilMock = mJetReleaserMockCloseAllUntil{mock: m}
m.CloseAllUntilMock.callArgs = []*JetReleaserMockCloseAllUntilParams{}
m.UnlockMock = mJetReleaserMockUnlock{mock: m}
m.UnlockMock.callArgs = []*JetReleaserMockUnlockParams{}
return m
}
type mJetReleaserMockCloseAllUntil struct {
mock *JetReleaserMock
defaultExpectation *JetReleaserMockCloseAllUntilExpectation
expectations []*JetReleaserMockCloseAllUntilExpectation
callArgs []*JetReleaserMockCloseAllUntilParams
mutex sync.RWMutex
}
// JetReleaserMockCloseAllUntilExpectation specifies expectation struct of the JetReleaser.CloseAllUntil
type JetReleaserMockCloseAllUntilExpectation struct {
mock *JetReleaserMock
params *JetReleaserMockCloseAllUntilParams
Counter uint64
}
// JetReleaserMockCloseAllUntilParams contains parameters of the JetReleaser.CloseAllUntil
type JetReleaserMockCloseAllUntilParams struct {
ctx context.Context
pulse insolar.PulseNumber
}
// Expect sets up expected params for JetReleaser.CloseAllUntil
func (mmCloseAllUntil *mJetReleaserMockCloseAllUntil) Expect(ctx context.Context, pulse insolar.PulseNumber) *mJetReleaserMockCloseAllUntil {
if mmCloseAllUntil.mock.funcCloseAllUntil != nil {
mmCloseAllUntil.mock.t.Fatalf("JetReleaserMock.CloseAllUntil mock is already set by Set")
}
if mmCloseAllUntil.defaultExpectation == nil {
mmCloseAllUntil.defaultExpectation = &JetReleaserMockCloseAllUntilExpectation{}
}
mmCloseAllUntil.defaultExpectation.params = &JetReleaserMockCloseAllUntilParams{ctx, pulse}
for _, e := range mmCloseAllUntil.expectations {
if minimock.Equal(e.params, mmCloseAllUntil.defaultExpectation.params) {
mmCloseAllUntil.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmCloseAllUntil.defaultExpectation.params)
}
}
return mmCloseAllUntil
}
// Inspect accepts an inspector function that has same arguments as the JetReleaser.CloseAllUntil
func (mmCloseAllUntil *mJetReleaserMockCloseAllUntil) Inspect(f func(ctx context.Context, pulse insolar.PulseNumber)) *mJetReleaserMockCloseAllUntil {
if mmCloseAllUntil.mock.inspectFuncCloseAllUntil != nil {
mmCloseAllUntil.mock.t.Fatalf("Inspect function is already set for JetReleaserMock.CloseAllUntil")
}
mmCloseAllUntil.mock.inspectFuncCloseAllUntil = f
return mmCloseAllUntil
}
// Return sets up results that will be returned by JetReleaser.CloseAllUntil
func (mmCloseAllUntil *mJetReleaserMockCloseAllUntil) Return() *JetReleaserMock {
if mmCloseAllUntil.mock.funcCloseAllUntil != nil {
mmCloseAllUntil.mock.t.Fatalf("JetReleaserMock.CloseAllUntil mock is already set by Set")
}
if mmCloseAllUntil.defaultExpectation == nil {
mmCloseAllUntil.defaultExpectation = &JetReleaserMockCloseAllUntilExpectation{mock: mmCloseAllUntil.mock}
}
return mmCloseAllUntil.mock
}
//Set uses given function f to mock the JetReleaser.CloseAllUntil method
func (mmCloseAllUntil *mJetReleaserMockCloseAllUntil) Set(f func(ctx context.Context, pulse insolar.PulseNumber)) *JetReleaserMock {
if mmCloseAllUntil.defaultExpectation != nil {
mmCloseAllUntil.mock.t.Fatalf("Default expectation is already set for the JetReleaser.CloseAllUntil method")
}
if len(mmCloseAllUntil.expectations) > 0 {
mmCloseAllUntil.mock.t.Fatalf("Some expectations are already set for the JetReleaser.CloseAllUntil method")
}
mmCloseAllUntil.mock.funcCloseAllUntil = f
return mmCloseAllUntil.mock
}
// CloseAllUntil implements JetReleaser
func (mmCloseAllUntil *JetReleaserMock) CloseAllUntil(ctx context.Context, pulse insolar.PulseNumber) {
mm_atomic.AddUint64(&mmCloseAllUntil.beforeCloseAllUntilCounter, 1)
defer mm_atomic.AddUint64(&mmCloseAllUntil.afterCloseAllUntilCounter, 1)
if mmCloseAllUntil.inspectFuncCloseAllUntil != nil {
mmCloseAllUntil.inspectFuncCloseAllUntil(ctx, pulse)
}
params := &JetReleaserMockCloseAllUntilParams{ctx, pulse}
// Record call args
mmCloseAllUntil.CloseAllUntilMock.mutex.Lock()
mmCloseAllUntil.CloseAllUntilMock.callArgs = append(mmCloseAllUntil.CloseAllUntilMock.callArgs, params)
mmCloseAllUntil.CloseAllUntilMock.mutex.Unlock()
for _, e := range mmCloseAllUntil.CloseAllUntilMock.expectations {
if minimock.Equal(e.params, params) {
mm_atomic.AddUint64(&e.Counter, 1)
return
}
}
if mmCloseAllUntil.CloseAllUntilMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmCloseAllUntil.CloseAllUntilMock.defaultExpectation.Counter, 1)
want := mmCloseAllUntil.CloseAllUntilMock.defaultExpectation.params
got := JetReleaserMockCloseAllUntilParams{ctx, pulse}
if want != nil && !minimock.Equal(*want, got) {
mmCloseAllUntil.t.Errorf("JetReleaserMock.CloseAllUntil got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got))
}
return
}
if mmCloseAllUntil.funcCloseAllUntil != nil {
mmCloseAllUntil.funcCloseAllUntil(ctx, pulse)
return
}
mmCloseAllUntil.t.Fatalf("Unexpected call to JetReleaserMock.CloseAllUntil. %v %v", ctx, pulse)
}
// CloseAllUntilAfterCounter returns a count of finished JetReleaserMock.CloseAllUntil invocations
func (mmCloseAllUntil *JetReleaserMock) CloseAllUntilAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmCloseAllUntil.afterCloseAllUntilCounter)
}
// CloseAllUntilBeforeCounter returns a count of JetReleaserMock.CloseAllUntil invocations
func (mmCloseAllUntil *JetReleaserMock) CloseAllUntilBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmCloseAllUntil.beforeCloseAllUntilCounter)
}
// Calls returns a list of arguments used in each call to JetReleaserMock.CloseAllUntil.
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
func (mmCloseAllUntil *mJetReleaserMockCloseAllUntil) Calls() []*JetReleaserMockCloseAllUntilParams {
mmCloseAllUntil.mutex.RLock()
argCopy := make([]*JetReleaserMockCloseAllUntilParams, len(mmCloseAllUntil.callArgs))
copy(argCopy, mmCloseAllUntil.callArgs)
mmCloseAllUntil.mutex.RUnlock()
return argCopy
}
// MinimockCloseAllUntilDone returns true if the count of the CloseAllUntil invocations corresponds
// the number of defined expectations
func (m *JetReleaserMock) MinimockCloseAllUntilDone() bool {
for _, e := range m.CloseAllUntilMock.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.CloseAllUntilMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterCloseAllUntilCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcCloseAllUntil != nil && mm_atomic.LoadUint64(&m.afterCloseAllUntilCounter) < 1 {
return false
}
return true
}
// MinimockCloseAllUntilInspect logs each unmet expectation
func (m *JetReleaserMock) MinimockCloseAllUntilInspect() {
for _, e := range m.CloseAllUntilMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Errorf("Expected call to JetReleaserMock.CloseAllUntil with params: %#v", *e.params)
}
}
// if default expectation was set then invocations count should be greater than zero
if m.CloseAllUntilMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterCloseAllUntilCounter) < 1 {
if m.CloseAllUntilMock.defaultExpectation.params == nil {
m.t.Error("Expected call to JetReleaserMock.CloseAllUntil")
} else {
m.t.Errorf("Expected call to JetReleaserMock.CloseAllUntil with params: %#v", *m.CloseAllUntilMock.defaultExpectation.params)
}
}
// if func was set then invocations count should be greater than zero
if m.funcCloseAllUntil != nil && mm_atomic.LoadUint64(&m.afterCloseAllUntilCounter) < 1 {
m.t.Error("Expected call to JetReleaserMock.CloseAllUntil")
}
}
type mJetReleaserMockUnlock struct {
mock *JetReleaserMock
defaultExpectation *JetReleaserMockUnlockExpectation
expectations []*JetReleaserMockUnlockExpectation
callArgs []*JetReleaserMockUnlockParams
mutex sync.RWMutex
}
// JetReleaserMockUnlockExpectation specifies expectation struct of the JetReleaser.Unlock
type JetReleaserMockUnlockExpectation struct {
mock *JetReleaserMock
params *JetReleaserMockUnlockParams
results *JetReleaserMockUnlockResults
Counter uint64
}
// JetReleaserMockUnlockParams contains parameters of the JetReleaser.Unlock
type JetReleaserMockUnlockParams struct {
ctx context.Context
pulse insolar.PulseNumber
jetID insolar.JetID
}
// JetReleaserMockUnlockResults contains results of the JetReleaser.Unlock
type JetReleaserMockUnlockResults struct {
err error
}
// Expect sets up expected params for JetReleaser.Unlock
func (mmUnlock *mJetReleaserMockUnlock) Expect(ctx context.Context, pulse insolar.PulseNumber, jetID insolar.JetID) *mJetReleaserMockUnlock {
if mmUnlock.mock.funcUnlock != nil {
mmUnlock.mock.t.Fatalf("JetReleaserMock.Unlock mock is already set by Set")
}
if mmUnlock.defaultExpectation == nil {
mmUnlock.defaultExpectation = &JetReleaserMockUnlockExpectation{}
}
mmUnlock.defaultExpectation.params = &JetReleaserMockUnlockParams{ctx, pulse, jetID}
for _, e := range mmUnlock.expectations {
if minimock.Equal(e.params, mmUnlock.defaultExpectation.params) {
mmUnlock.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmUnlock.defaultExpectation.params)
}
}
return mmUnlock
}
// Inspect accepts an inspector function that has same arguments as the JetReleaser.Unlock
func (mmUnlock *mJetReleaserMockUnlock) Inspect(f func(ctx context.Context, pulse insolar.PulseNumber, jetID insolar.JetID)) *mJetReleaserMockUnlock {
if mmUnlock.mock.inspectFuncUnlock != nil {
mmUnlock.mock.t.Fatalf("Inspect function is already set for JetReleaserMock.Unlock")
}
mmUnlock.mock.inspectFuncUnlock = f
return mmUnlock
}
// Return sets up results that will be returned by JetReleaser.Unlock
func (mmUnlock *mJetReleaserMockUnlock) Return(err error) *JetReleaserMock {
if mmUnlock.mock.funcUnlock != nil {
mmUnlock.mock.t.Fatalf("JetReleaserMock.Unlock mock is already set by Set")
}
if mmUnlock.defaultExpectation == nil {
mmUnlock.defaultExpectation = &JetReleaserMockUnlockExpectation{mock: mmUnlock.mock}
}
mmUnlock.defaultExpectation.results = &JetReleaserMockUnlockResults{err}
return mmUnlock.mock
}
//Set uses given function f to mock the JetReleaser.Unlock method
func (mmUnlock *mJetReleaserMockUnlock) Set(f func(ctx context.Context, pulse insolar.PulseNumber, jetID insolar.JetID) (err error)) *JetReleaserMock {
if mmUnlock.defaultExpectation != nil {
mmUnlock.mock.t.Fatalf("Default expectation is already set for the JetReleaser.Unlock method")
}
if len(mmUnlock.expectations) > 0 {
mmUnlock.mock.t.Fatalf("Some expectations are already set for the JetReleaser.Unlock method")
}
mmUnlock.mock.funcUnlock = f
return mmUnlock.mock
}
// When sets expectation for the JetReleaser.Unlock which will trigger the result defined by the following
// Then helper
func (mmUnlock *mJetReleaserMockUnlock) When(ctx context.Context, pulse insolar.PulseNumber, jetID insolar.JetID) *JetReleaserMockUnlockExpectation {
if mmUnlock.mock.funcUnlock != nil {
mmUnlock.mock.t.Fatalf("JetReleaserMock.Unlock mock is already set by Set")
}
expectation := &JetReleaserMockUnlockExpectation{
mock: mmUnlock.mock,
params: &JetReleaserMockUnlockParams{ctx, pulse, jetID},
}
mmUnlock.expectations = append(mmUnlock.expectations, expectation)
return expectation
}
// Then sets up JetReleaser.Unlock return parameters for the expectation previously defined by the When method
func (e *JetReleaserMockUnlockExpectation) Then(err error) *JetReleaserMock {
e.results = &JetReleaserMockUnlockResults{err}
return e.mock
}
// Unlock implements JetReleaser
func (mmUnlock *JetReleaserMock) Unlock(ctx context.Context, pulse insolar.PulseNumber, jetID insolar.JetID) (err error) {
mm_atomic.AddUint64(&mmUnlock.beforeUnlockCounter, 1)
defer mm_atomic.AddUint64(&mmUnlock.afterUnlockCounter, 1)
if mmUnlock.inspectFuncUnlock != nil {
mmUnlock.inspectFuncUnlock(ctx, pulse, jetID)
}
params := &JetReleaserMockUnlockParams{ctx, pulse, jetID}
// Record call args
mmUnlock.UnlockMock.mutex.Lock()
mmUnlock.UnlockMock.callArgs = append(mmUnlock.UnlockMock.callArgs, params)
mmUnlock.UnlockMock.mutex.Unlock()
for _, e := range mmUnlock.UnlockMock.expectations {
if minimock.Equal(e.params, params) {
mm_atomic.AddUint64(&e.Counter, 1)
return e.results.err
}
}
if mmUnlock.UnlockMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmUnlock.UnlockMock.defaultExpectation.Counter, 1)
want := mmUnlock.UnlockMock.defaultExpectation.params
got := JetReleaserMockUnlockParams{ctx, pulse, jetID}
if want != nil && !minimock.Equal(*want, got) {
mmUnlock.t.Errorf("JetReleaserMock.Unlock got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got))
}
results := mmUnlock.UnlockMock.defaultExpectation.results
if results == nil {
mmUnlock.t.Fatal("No results are set for the JetReleaserMock.Unlock")
}
return (*results).err
}
if mmUnlock.funcUnlock != nil {
return mmUnlock.funcUnlock(ctx, pulse, jetID)
}
mmUnlock.t.Fatalf("Unexpected call to JetReleaserMock.Unlock. %v %v %v", ctx, pulse, jetID)
return
}
// UnlockAfterCounter returns a count of finished JetReleaserMock.Unlock invocations
func (mmUnlock *JetReleaserMock) UnlockAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmUnlock.afterUnlockCounter)
}
// UnlockBeforeCounter returns a count of JetReleaserMock.Unlock invocations
func (mmUnlock *JetReleaserMock) UnlockBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmUnlock.beforeUnlockCounter)
}
// Calls returns a list of arguments used in each call to JetReleaserMock.Unlock.
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
func (mmUnlock *mJetReleaserMockUnlock) Calls() []*JetReleaserMockUnlockParams {
mmUnlock.mutex.RLock()
argCopy := make([]*JetReleaserMockUnlockParams, len(mmUnlock.callArgs))
copy(argCopy, mmUnlock.callArgs)
mmUnlock.mutex.RUnlock()
return argCopy
}
// MinimockUnlockDone returns true if the count of the Unlock invocations corresponds
// the number of defined expectations
func (m *JetReleaserMock) MinimockUnlockDone() bool {
for _, e := range m.UnlockMock.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.UnlockMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterUnlockCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcUnlock != nil && mm_atomic.LoadUint64(&m.afterUnlockCounter) < 1 {
return false
}
return true
}
// MinimockUnlockInspect logs each unmet expectation
func (m *JetReleaserMock) MinimockUnlockInspect() {
for _, e := range m.UnlockMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Errorf("Expected call to JetReleaserMock.Unlock with params: %#v", *e.params)
}
}
// if default expectation was set then invocations count should be greater than zero
if m.UnlockMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterUnlockCounter) < 1 {
if m.UnlockMock.defaultExpectation.params == nil {
m.t.Error("Expected call to JetReleaserMock.Unlock")
} else {
m.t.Errorf("Expected call to JetReleaserMock.Unlock with params: %#v", *m.UnlockMock.defaultExpectation.params)
}
}
// if func was set then invocations count should be greater than zero
if m.funcUnlock != nil && mm_atomic.LoadUint64(&m.afterUnlockCounter) < 1 {
m.t.Error("Expected call to JetReleaserMock.Unlock")
}
}
// MinimockFinish checks that all mocked methods have been called the expected number of times
func (m *JetReleaserMock) MinimockFinish() {
if !m.minimockDone() {
m.MinimockCloseAllUntilInspect()
m.MinimockUnlockInspect()
m.t.FailNow()
}
}
// MinimockWait waits for all mocked methods to be called the expected number of times
func (m *JetReleaserMock) 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 *JetReleaserMock) minimockDone() bool {
done := true
return done &&
m.MinimockCloseAllUntilDone() &&
m.MinimockUnlockDone()
}