-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic_runner_mock.go
658 lines (540 loc) · 24 KB
/
logic_runner_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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
package testutils
// 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"
mm_insolar "github.com/insolar/insolar/insolar"
)
// LogicRunnerMock implements insolar.LogicRunner
type LogicRunnerMock struct {
t minimock.Tester
funcAddUnwantedResponse func(ctx context.Context, msg mm_insolar.Message) (err error)
inspectFuncAddUnwantedResponse func(ctx context.Context, msg mm_insolar.Message)
afterAddUnwantedResponseCounter uint64
beforeAddUnwantedResponseCounter uint64
AddUnwantedResponseMock mLogicRunnerMockAddUnwantedResponse
funcLRI func()
inspectFuncLRI func()
afterLRICounter uint64
beforeLRICounter uint64
LRIMock mLogicRunnerMockLRI
funcOnPulse func(ctx context.Context, p1 mm_insolar.Pulse, p2 mm_insolar.Pulse) (err error)
inspectFuncOnPulse func(ctx context.Context, p1 mm_insolar.Pulse, p2 mm_insolar.Pulse)
afterOnPulseCounter uint64
beforeOnPulseCounter uint64
OnPulseMock mLogicRunnerMockOnPulse
}
// NewLogicRunnerMock returns a mock for insolar.LogicRunner
func NewLogicRunnerMock(t minimock.Tester) *LogicRunnerMock {
m := &LogicRunnerMock{t: t}
if controller, ok := t.(minimock.MockController); ok {
controller.RegisterMocker(m)
}
m.AddUnwantedResponseMock = mLogicRunnerMockAddUnwantedResponse{mock: m}
m.AddUnwantedResponseMock.callArgs = []*LogicRunnerMockAddUnwantedResponseParams{}
m.LRIMock = mLogicRunnerMockLRI{mock: m}
m.OnPulseMock = mLogicRunnerMockOnPulse{mock: m}
m.OnPulseMock.callArgs = []*LogicRunnerMockOnPulseParams{}
return m
}
type mLogicRunnerMockAddUnwantedResponse struct {
mock *LogicRunnerMock
defaultExpectation *LogicRunnerMockAddUnwantedResponseExpectation
expectations []*LogicRunnerMockAddUnwantedResponseExpectation
callArgs []*LogicRunnerMockAddUnwantedResponseParams
mutex sync.RWMutex
}
// LogicRunnerMockAddUnwantedResponseExpectation specifies expectation struct of the LogicRunner.AddUnwantedResponse
type LogicRunnerMockAddUnwantedResponseExpectation struct {
mock *LogicRunnerMock
params *LogicRunnerMockAddUnwantedResponseParams
results *LogicRunnerMockAddUnwantedResponseResults
Counter uint64
}
// LogicRunnerMockAddUnwantedResponseParams contains parameters of the LogicRunner.AddUnwantedResponse
type LogicRunnerMockAddUnwantedResponseParams struct {
ctx context.Context
msg mm_insolar.Message
}
// LogicRunnerMockAddUnwantedResponseResults contains results of the LogicRunner.AddUnwantedResponse
type LogicRunnerMockAddUnwantedResponseResults struct {
err error
}
// Expect sets up expected params for LogicRunner.AddUnwantedResponse
func (mmAddUnwantedResponse *mLogicRunnerMockAddUnwantedResponse) Expect(ctx context.Context, msg mm_insolar.Message) *mLogicRunnerMockAddUnwantedResponse {
if mmAddUnwantedResponse.mock.funcAddUnwantedResponse != nil {
mmAddUnwantedResponse.mock.t.Fatalf("LogicRunnerMock.AddUnwantedResponse mock is already set by Set")
}
if mmAddUnwantedResponse.defaultExpectation == nil {
mmAddUnwantedResponse.defaultExpectation = &LogicRunnerMockAddUnwantedResponseExpectation{}
}
mmAddUnwantedResponse.defaultExpectation.params = &LogicRunnerMockAddUnwantedResponseParams{ctx, msg}
for _, e := range mmAddUnwantedResponse.expectations {
if minimock.Equal(e.params, mmAddUnwantedResponse.defaultExpectation.params) {
mmAddUnwantedResponse.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmAddUnwantedResponse.defaultExpectation.params)
}
}
return mmAddUnwantedResponse
}
// Inspect accepts an inspector function that has same arguments as the LogicRunner.AddUnwantedResponse
func (mmAddUnwantedResponse *mLogicRunnerMockAddUnwantedResponse) Inspect(f func(ctx context.Context, msg mm_insolar.Message)) *mLogicRunnerMockAddUnwantedResponse {
if mmAddUnwantedResponse.mock.inspectFuncAddUnwantedResponse != nil {
mmAddUnwantedResponse.mock.t.Fatalf("Inspect function is already set for LogicRunnerMock.AddUnwantedResponse")
}
mmAddUnwantedResponse.mock.inspectFuncAddUnwantedResponse = f
return mmAddUnwantedResponse
}
// Return sets up results that will be returned by LogicRunner.AddUnwantedResponse
func (mmAddUnwantedResponse *mLogicRunnerMockAddUnwantedResponse) Return(err error) *LogicRunnerMock {
if mmAddUnwantedResponse.mock.funcAddUnwantedResponse != nil {
mmAddUnwantedResponse.mock.t.Fatalf("LogicRunnerMock.AddUnwantedResponse mock is already set by Set")
}
if mmAddUnwantedResponse.defaultExpectation == nil {
mmAddUnwantedResponse.defaultExpectation = &LogicRunnerMockAddUnwantedResponseExpectation{mock: mmAddUnwantedResponse.mock}
}
mmAddUnwantedResponse.defaultExpectation.results = &LogicRunnerMockAddUnwantedResponseResults{err}
return mmAddUnwantedResponse.mock
}
//Set uses given function f to mock the LogicRunner.AddUnwantedResponse method
func (mmAddUnwantedResponse *mLogicRunnerMockAddUnwantedResponse) Set(f func(ctx context.Context, msg mm_insolar.Message) (err error)) *LogicRunnerMock {
if mmAddUnwantedResponse.defaultExpectation != nil {
mmAddUnwantedResponse.mock.t.Fatalf("Default expectation is already set for the LogicRunner.AddUnwantedResponse method")
}
if len(mmAddUnwantedResponse.expectations) > 0 {
mmAddUnwantedResponse.mock.t.Fatalf("Some expectations are already set for the LogicRunner.AddUnwantedResponse method")
}
mmAddUnwantedResponse.mock.funcAddUnwantedResponse = f
return mmAddUnwantedResponse.mock
}
// When sets expectation for the LogicRunner.AddUnwantedResponse which will trigger the result defined by the following
// Then helper
func (mmAddUnwantedResponse *mLogicRunnerMockAddUnwantedResponse) When(ctx context.Context, msg mm_insolar.Message) *LogicRunnerMockAddUnwantedResponseExpectation {
if mmAddUnwantedResponse.mock.funcAddUnwantedResponse != nil {
mmAddUnwantedResponse.mock.t.Fatalf("LogicRunnerMock.AddUnwantedResponse mock is already set by Set")
}
expectation := &LogicRunnerMockAddUnwantedResponseExpectation{
mock: mmAddUnwantedResponse.mock,
params: &LogicRunnerMockAddUnwantedResponseParams{ctx, msg},
}
mmAddUnwantedResponse.expectations = append(mmAddUnwantedResponse.expectations, expectation)
return expectation
}
// Then sets up LogicRunner.AddUnwantedResponse return parameters for the expectation previously defined by the When method
func (e *LogicRunnerMockAddUnwantedResponseExpectation) Then(err error) *LogicRunnerMock {
e.results = &LogicRunnerMockAddUnwantedResponseResults{err}
return e.mock
}
// AddUnwantedResponse implements insolar.LogicRunner
func (mmAddUnwantedResponse *LogicRunnerMock) AddUnwantedResponse(ctx context.Context, msg mm_insolar.Message) (err error) {
mm_atomic.AddUint64(&mmAddUnwantedResponse.beforeAddUnwantedResponseCounter, 1)
defer mm_atomic.AddUint64(&mmAddUnwantedResponse.afterAddUnwantedResponseCounter, 1)
if mmAddUnwantedResponse.inspectFuncAddUnwantedResponse != nil {
mmAddUnwantedResponse.inspectFuncAddUnwantedResponse(ctx, msg)
}
params := &LogicRunnerMockAddUnwantedResponseParams{ctx, msg}
// Record call args
mmAddUnwantedResponse.AddUnwantedResponseMock.mutex.Lock()
mmAddUnwantedResponse.AddUnwantedResponseMock.callArgs = append(mmAddUnwantedResponse.AddUnwantedResponseMock.callArgs, params)
mmAddUnwantedResponse.AddUnwantedResponseMock.mutex.Unlock()
for _, e := range mmAddUnwantedResponse.AddUnwantedResponseMock.expectations {
if minimock.Equal(e.params, params) {
mm_atomic.AddUint64(&e.Counter, 1)
return e.results.err
}
}
if mmAddUnwantedResponse.AddUnwantedResponseMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmAddUnwantedResponse.AddUnwantedResponseMock.defaultExpectation.Counter, 1)
want := mmAddUnwantedResponse.AddUnwantedResponseMock.defaultExpectation.params
got := LogicRunnerMockAddUnwantedResponseParams{ctx, msg}
if want != nil && !minimock.Equal(*want, got) {
mmAddUnwantedResponse.t.Errorf("LogicRunnerMock.AddUnwantedResponse got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got))
}
results := mmAddUnwantedResponse.AddUnwantedResponseMock.defaultExpectation.results
if results == nil {
mmAddUnwantedResponse.t.Fatal("No results are set for the LogicRunnerMock.AddUnwantedResponse")
}
return (*results).err
}
if mmAddUnwantedResponse.funcAddUnwantedResponse != nil {
return mmAddUnwantedResponse.funcAddUnwantedResponse(ctx, msg)
}
mmAddUnwantedResponse.t.Fatalf("Unexpected call to LogicRunnerMock.AddUnwantedResponse. %v %v", ctx, msg)
return
}
// AddUnwantedResponseAfterCounter returns a count of finished LogicRunnerMock.AddUnwantedResponse invocations
func (mmAddUnwantedResponse *LogicRunnerMock) AddUnwantedResponseAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmAddUnwantedResponse.afterAddUnwantedResponseCounter)
}
// AddUnwantedResponseBeforeCounter returns a count of LogicRunnerMock.AddUnwantedResponse invocations
func (mmAddUnwantedResponse *LogicRunnerMock) AddUnwantedResponseBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmAddUnwantedResponse.beforeAddUnwantedResponseCounter)
}
// Calls returns a list of arguments used in each call to LogicRunnerMock.AddUnwantedResponse.
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
func (mmAddUnwantedResponse *mLogicRunnerMockAddUnwantedResponse) Calls() []*LogicRunnerMockAddUnwantedResponseParams {
mmAddUnwantedResponse.mutex.RLock()
argCopy := make([]*LogicRunnerMockAddUnwantedResponseParams, len(mmAddUnwantedResponse.callArgs))
copy(argCopy, mmAddUnwantedResponse.callArgs)
mmAddUnwantedResponse.mutex.RUnlock()
return argCopy
}
// MinimockAddUnwantedResponseDone returns true if the count of the AddUnwantedResponse invocations corresponds
// the number of defined expectations
func (m *LogicRunnerMock) MinimockAddUnwantedResponseDone() bool {
for _, e := range m.AddUnwantedResponseMock.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.AddUnwantedResponseMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterAddUnwantedResponseCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcAddUnwantedResponse != nil && mm_atomic.LoadUint64(&m.afterAddUnwantedResponseCounter) < 1 {
return false
}
return true
}
// MinimockAddUnwantedResponseInspect logs each unmet expectation
func (m *LogicRunnerMock) MinimockAddUnwantedResponseInspect() {
for _, e := range m.AddUnwantedResponseMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Errorf("Expected call to LogicRunnerMock.AddUnwantedResponse with params: %#v", *e.params)
}
}
// if default expectation was set then invocations count should be greater than zero
if m.AddUnwantedResponseMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterAddUnwantedResponseCounter) < 1 {
if m.AddUnwantedResponseMock.defaultExpectation.params == nil {
m.t.Error("Expected call to LogicRunnerMock.AddUnwantedResponse")
} else {
m.t.Errorf("Expected call to LogicRunnerMock.AddUnwantedResponse with params: %#v", *m.AddUnwantedResponseMock.defaultExpectation.params)
}
}
// if func was set then invocations count should be greater than zero
if m.funcAddUnwantedResponse != nil && mm_atomic.LoadUint64(&m.afterAddUnwantedResponseCounter) < 1 {
m.t.Error("Expected call to LogicRunnerMock.AddUnwantedResponse")
}
}
type mLogicRunnerMockLRI struct {
mock *LogicRunnerMock
defaultExpectation *LogicRunnerMockLRIExpectation
expectations []*LogicRunnerMockLRIExpectation
}
// LogicRunnerMockLRIExpectation specifies expectation struct of the LogicRunner.LRI
type LogicRunnerMockLRIExpectation struct {
mock *LogicRunnerMock
Counter uint64
}
// Expect sets up expected params for LogicRunner.LRI
func (mmLRI *mLogicRunnerMockLRI) Expect() *mLogicRunnerMockLRI {
if mmLRI.mock.funcLRI != nil {
mmLRI.mock.t.Fatalf("LogicRunnerMock.LRI mock is already set by Set")
}
if mmLRI.defaultExpectation == nil {
mmLRI.defaultExpectation = &LogicRunnerMockLRIExpectation{}
}
return mmLRI
}
// Inspect accepts an inspector function that has same arguments as the LogicRunner.LRI
func (mmLRI *mLogicRunnerMockLRI) Inspect(f func()) *mLogicRunnerMockLRI {
if mmLRI.mock.inspectFuncLRI != nil {
mmLRI.mock.t.Fatalf("Inspect function is already set for LogicRunnerMock.LRI")
}
mmLRI.mock.inspectFuncLRI = f
return mmLRI
}
// Return sets up results that will be returned by LogicRunner.LRI
func (mmLRI *mLogicRunnerMockLRI) Return() *LogicRunnerMock {
if mmLRI.mock.funcLRI != nil {
mmLRI.mock.t.Fatalf("LogicRunnerMock.LRI mock is already set by Set")
}
if mmLRI.defaultExpectation == nil {
mmLRI.defaultExpectation = &LogicRunnerMockLRIExpectation{mock: mmLRI.mock}
}
return mmLRI.mock
}
//Set uses given function f to mock the LogicRunner.LRI method
func (mmLRI *mLogicRunnerMockLRI) Set(f func()) *LogicRunnerMock {
if mmLRI.defaultExpectation != nil {
mmLRI.mock.t.Fatalf("Default expectation is already set for the LogicRunner.LRI method")
}
if len(mmLRI.expectations) > 0 {
mmLRI.mock.t.Fatalf("Some expectations are already set for the LogicRunner.LRI method")
}
mmLRI.mock.funcLRI = f
return mmLRI.mock
}
// LRI implements insolar.LogicRunner
func (mmLRI *LogicRunnerMock) LRI() {
mm_atomic.AddUint64(&mmLRI.beforeLRICounter, 1)
defer mm_atomic.AddUint64(&mmLRI.afterLRICounter, 1)
if mmLRI.inspectFuncLRI != nil {
mmLRI.inspectFuncLRI()
}
if mmLRI.LRIMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmLRI.LRIMock.defaultExpectation.Counter, 1)
return
}
if mmLRI.funcLRI != nil {
mmLRI.funcLRI()
return
}
mmLRI.t.Fatalf("Unexpected call to LogicRunnerMock.LRI.")
}
// LRIAfterCounter returns a count of finished LogicRunnerMock.LRI invocations
func (mmLRI *LogicRunnerMock) LRIAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmLRI.afterLRICounter)
}
// LRIBeforeCounter returns a count of LogicRunnerMock.LRI invocations
func (mmLRI *LogicRunnerMock) LRIBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmLRI.beforeLRICounter)
}
// MinimockLRIDone returns true if the count of the LRI invocations corresponds
// the number of defined expectations
func (m *LogicRunnerMock) MinimockLRIDone() bool {
for _, e := range m.LRIMock.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.LRIMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterLRICounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcLRI != nil && mm_atomic.LoadUint64(&m.afterLRICounter) < 1 {
return false
}
return true
}
// MinimockLRIInspect logs each unmet expectation
func (m *LogicRunnerMock) MinimockLRIInspect() {
for _, e := range m.LRIMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Error("Expected call to LogicRunnerMock.LRI")
}
}
// if default expectation was set then invocations count should be greater than zero
if m.LRIMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterLRICounter) < 1 {
m.t.Error("Expected call to LogicRunnerMock.LRI")
}
// if func was set then invocations count should be greater than zero
if m.funcLRI != nil && mm_atomic.LoadUint64(&m.afterLRICounter) < 1 {
m.t.Error("Expected call to LogicRunnerMock.LRI")
}
}
type mLogicRunnerMockOnPulse struct {
mock *LogicRunnerMock
defaultExpectation *LogicRunnerMockOnPulseExpectation
expectations []*LogicRunnerMockOnPulseExpectation
callArgs []*LogicRunnerMockOnPulseParams
mutex sync.RWMutex
}
// LogicRunnerMockOnPulseExpectation specifies expectation struct of the LogicRunner.OnPulse
type LogicRunnerMockOnPulseExpectation struct {
mock *LogicRunnerMock
params *LogicRunnerMockOnPulseParams
results *LogicRunnerMockOnPulseResults
Counter uint64
}
// LogicRunnerMockOnPulseParams contains parameters of the LogicRunner.OnPulse
type LogicRunnerMockOnPulseParams struct {
ctx context.Context
p1 mm_insolar.Pulse
p2 mm_insolar.Pulse
}
// LogicRunnerMockOnPulseResults contains results of the LogicRunner.OnPulse
type LogicRunnerMockOnPulseResults struct {
err error
}
// Expect sets up expected params for LogicRunner.OnPulse
func (mmOnPulse *mLogicRunnerMockOnPulse) Expect(ctx context.Context, p1 mm_insolar.Pulse, p2 mm_insolar.Pulse) *mLogicRunnerMockOnPulse {
if mmOnPulse.mock.funcOnPulse != nil {
mmOnPulse.mock.t.Fatalf("LogicRunnerMock.OnPulse mock is already set by Set")
}
if mmOnPulse.defaultExpectation == nil {
mmOnPulse.defaultExpectation = &LogicRunnerMockOnPulseExpectation{}
}
mmOnPulse.defaultExpectation.params = &LogicRunnerMockOnPulseParams{ctx, p1, p2}
for _, e := range mmOnPulse.expectations {
if minimock.Equal(e.params, mmOnPulse.defaultExpectation.params) {
mmOnPulse.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmOnPulse.defaultExpectation.params)
}
}
return mmOnPulse
}
// Inspect accepts an inspector function that has same arguments as the LogicRunner.OnPulse
func (mmOnPulse *mLogicRunnerMockOnPulse) Inspect(f func(ctx context.Context, p1 mm_insolar.Pulse, p2 mm_insolar.Pulse)) *mLogicRunnerMockOnPulse {
if mmOnPulse.mock.inspectFuncOnPulse != nil {
mmOnPulse.mock.t.Fatalf("Inspect function is already set for LogicRunnerMock.OnPulse")
}
mmOnPulse.mock.inspectFuncOnPulse = f
return mmOnPulse
}
// Return sets up results that will be returned by LogicRunner.OnPulse
func (mmOnPulse *mLogicRunnerMockOnPulse) Return(err error) *LogicRunnerMock {
if mmOnPulse.mock.funcOnPulse != nil {
mmOnPulse.mock.t.Fatalf("LogicRunnerMock.OnPulse mock is already set by Set")
}
if mmOnPulse.defaultExpectation == nil {
mmOnPulse.defaultExpectation = &LogicRunnerMockOnPulseExpectation{mock: mmOnPulse.mock}
}
mmOnPulse.defaultExpectation.results = &LogicRunnerMockOnPulseResults{err}
return mmOnPulse.mock
}
//Set uses given function f to mock the LogicRunner.OnPulse method
func (mmOnPulse *mLogicRunnerMockOnPulse) Set(f func(ctx context.Context, p1 mm_insolar.Pulse, p2 mm_insolar.Pulse) (err error)) *LogicRunnerMock {
if mmOnPulse.defaultExpectation != nil {
mmOnPulse.mock.t.Fatalf("Default expectation is already set for the LogicRunner.OnPulse method")
}
if len(mmOnPulse.expectations) > 0 {
mmOnPulse.mock.t.Fatalf("Some expectations are already set for the LogicRunner.OnPulse method")
}
mmOnPulse.mock.funcOnPulse = f
return mmOnPulse.mock
}
// When sets expectation for the LogicRunner.OnPulse which will trigger the result defined by the following
// Then helper
func (mmOnPulse *mLogicRunnerMockOnPulse) When(ctx context.Context, p1 mm_insolar.Pulse, p2 mm_insolar.Pulse) *LogicRunnerMockOnPulseExpectation {
if mmOnPulse.mock.funcOnPulse != nil {
mmOnPulse.mock.t.Fatalf("LogicRunnerMock.OnPulse mock is already set by Set")
}
expectation := &LogicRunnerMockOnPulseExpectation{
mock: mmOnPulse.mock,
params: &LogicRunnerMockOnPulseParams{ctx, p1, p2},
}
mmOnPulse.expectations = append(mmOnPulse.expectations, expectation)
return expectation
}
// Then sets up LogicRunner.OnPulse return parameters for the expectation previously defined by the When method
func (e *LogicRunnerMockOnPulseExpectation) Then(err error) *LogicRunnerMock {
e.results = &LogicRunnerMockOnPulseResults{err}
return e.mock
}
// OnPulse implements insolar.LogicRunner
func (mmOnPulse *LogicRunnerMock) OnPulse(ctx context.Context, p1 mm_insolar.Pulse, p2 mm_insolar.Pulse) (err error) {
mm_atomic.AddUint64(&mmOnPulse.beforeOnPulseCounter, 1)
defer mm_atomic.AddUint64(&mmOnPulse.afterOnPulseCounter, 1)
if mmOnPulse.inspectFuncOnPulse != nil {
mmOnPulse.inspectFuncOnPulse(ctx, p1, p2)
}
params := &LogicRunnerMockOnPulseParams{ctx, p1, p2}
// Record call args
mmOnPulse.OnPulseMock.mutex.Lock()
mmOnPulse.OnPulseMock.callArgs = append(mmOnPulse.OnPulseMock.callArgs, params)
mmOnPulse.OnPulseMock.mutex.Unlock()
for _, e := range mmOnPulse.OnPulseMock.expectations {
if minimock.Equal(e.params, params) {
mm_atomic.AddUint64(&e.Counter, 1)
return e.results.err
}
}
if mmOnPulse.OnPulseMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmOnPulse.OnPulseMock.defaultExpectation.Counter, 1)
want := mmOnPulse.OnPulseMock.defaultExpectation.params
got := LogicRunnerMockOnPulseParams{ctx, p1, p2}
if want != nil && !minimock.Equal(*want, got) {
mmOnPulse.t.Errorf("LogicRunnerMock.OnPulse got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got))
}
results := mmOnPulse.OnPulseMock.defaultExpectation.results
if results == nil {
mmOnPulse.t.Fatal("No results are set for the LogicRunnerMock.OnPulse")
}
return (*results).err
}
if mmOnPulse.funcOnPulse != nil {
return mmOnPulse.funcOnPulse(ctx, p1, p2)
}
mmOnPulse.t.Fatalf("Unexpected call to LogicRunnerMock.OnPulse. %v %v %v", ctx, p1, p2)
return
}
// OnPulseAfterCounter returns a count of finished LogicRunnerMock.OnPulse invocations
func (mmOnPulse *LogicRunnerMock) OnPulseAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmOnPulse.afterOnPulseCounter)
}
// OnPulseBeforeCounter returns a count of LogicRunnerMock.OnPulse invocations
func (mmOnPulse *LogicRunnerMock) OnPulseBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmOnPulse.beforeOnPulseCounter)
}
// Calls returns a list of arguments used in each call to LogicRunnerMock.OnPulse.
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
func (mmOnPulse *mLogicRunnerMockOnPulse) Calls() []*LogicRunnerMockOnPulseParams {
mmOnPulse.mutex.RLock()
argCopy := make([]*LogicRunnerMockOnPulseParams, len(mmOnPulse.callArgs))
copy(argCopy, mmOnPulse.callArgs)
mmOnPulse.mutex.RUnlock()
return argCopy
}
// MinimockOnPulseDone returns true if the count of the OnPulse invocations corresponds
// the number of defined expectations
func (m *LogicRunnerMock) MinimockOnPulseDone() bool {
for _, e := range m.OnPulseMock.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.OnPulseMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterOnPulseCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcOnPulse != nil && mm_atomic.LoadUint64(&m.afterOnPulseCounter) < 1 {
return false
}
return true
}
// MinimockOnPulseInspect logs each unmet expectation
func (m *LogicRunnerMock) MinimockOnPulseInspect() {
for _, e := range m.OnPulseMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Errorf("Expected call to LogicRunnerMock.OnPulse with params: %#v", *e.params)
}
}
// if default expectation was set then invocations count should be greater than zero
if m.OnPulseMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterOnPulseCounter) < 1 {
if m.OnPulseMock.defaultExpectation.params == nil {
m.t.Error("Expected call to LogicRunnerMock.OnPulse")
} else {
m.t.Errorf("Expected call to LogicRunnerMock.OnPulse with params: %#v", *m.OnPulseMock.defaultExpectation.params)
}
}
// if func was set then invocations count should be greater than zero
if m.funcOnPulse != nil && mm_atomic.LoadUint64(&m.afterOnPulseCounter) < 1 {
m.t.Error("Expected call to LogicRunnerMock.OnPulse")
}
}
// MinimockFinish checks that all mocked methods have been called the expected number of times
func (m *LogicRunnerMock) MinimockFinish() {
if !m.minimockDone() {
m.MinimockAddUnwantedResponseInspect()
m.MinimockLRIInspect()
m.MinimockOnPulseInspect()
m.t.FailNow()
}
}
// MinimockWait waits for all mocked methods to be called the expected number of times
func (m *LogicRunnerMock) 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 *LogicRunnerMock) minimockDone() bool {
done := true
return done &&
m.MinimockAddUnwantedResponseDone() &&
m.MinimockLRIDone() &&
m.MinimockOnPulseDone()
}