-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_descriptor_mock.go
563 lines (435 loc) · 15.4 KB
/
code_descriptor_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
package testutils
/*
DO NOT EDIT!
This code was generated automatically using github.com/gojuno/minimock v1.9
The original interface "CodeDescriptor" can be found in github.com/insolar/insolar/core
*/
import (
"sync/atomic"
"time"
"github.com/gojuno/minimock"
core "github.com/insolar/insolar/core"
)
//CodeDescriptorMock implements github.com/insolar/insolar/core.CodeDescriptor
type CodeDescriptorMock struct {
t minimock.Tester
CodeFunc func() (r []byte, r1 error)
CodeCounter uint64
CodePreCounter uint64
CodeMock mCodeDescriptorMockCode
MachineTypeFunc func() (r core.MachineType)
MachineTypeCounter uint64
MachineTypePreCounter uint64
MachineTypeMock mCodeDescriptorMockMachineType
RefFunc func() (r *core.RecordRef)
RefCounter uint64
RefPreCounter uint64
RefMock mCodeDescriptorMockRef
}
//NewCodeDescriptorMock returns a mock for github.com/insolar/insolar/core.CodeDescriptor
func NewCodeDescriptorMock(t minimock.Tester) *CodeDescriptorMock {
m := &CodeDescriptorMock{t: t}
if controller, ok := t.(minimock.MockController); ok {
controller.RegisterMocker(m)
}
m.CodeMock = mCodeDescriptorMockCode{mock: m}
m.MachineTypeMock = mCodeDescriptorMockMachineType{mock: m}
m.RefMock = mCodeDescriptorMockRef{mock: m}
return m
}
type mCodeDescriptorMockCode struct {
mock *CodeDescriptorMock
mainExpectation *CodeDescriptorMockCodeExpectation
expectationSeries []*CodeDescriptorMockCodeExpectation
}
type CodeDescriptorMockCodeExpectation struct {
result *CodeDescriptorMockCodeResult
}
type CodeDescriptorMockCodeResult struct {
r []byte
r1 error
}
//Expect specifies that invocation of CodeDescriptor.Code is expected from 1 to Infinity times
func (m *mCodeDescriptorMockCode) Expect() *mCodeDescriptorMockCode {
m.mock.CodeFunc = nil
m.expectationSeries = nil
if m.mainExpectation == nil {
m.mainExpectation = &CodeDescriptorMockCodeExpectation{}
}
return m
}
//Return specifies results of invocation of CodeDescriptor.Code
func (m *mCodeDescriptorMockCode) Return(r []byte, r1 error) *CodeDescriptorMock {
m.mock.CodeFunc = nil
m.expectationSeries = nil
if m.mainExpectation == nil {
m.mainExpectation = &CodeDescriptorMockCodeExpectation{}
}
m.mainExpectation.result = &CodeDescriptorMockCodeResult{r, r1}
return m.mock
}
//ExpectOnce specifies that invocation of CodeDescriptor.Code is expected once
func (m *mCodeDescriptorMockCode) ExpectOnce() *CodeDescriptorMockCodeExpectation {
m.mock.CodeFunc = nil
m.mainExpectation = nil
expectation := &CodeDescriptorMockCodeExpectation{}
m.expectationSeries = append(m.expectationSeries, expectation)
return expectation
}
func (e *CodeDescriptorMockCodeExpectation) Return(r []byte, r1 error) {
e.result = &CodeDescriptorMockCodeResult{r, r1}
}
//Set uses given function f as a mock of CodeDescriptor.Code method
func (m *mCodeDescriptorMockCode) Set(f func() (r []byte, r1 error)) *CodeDescriptorMock {
m.mainExpectation = nil
m.expectationSeries = nil
m.mock.CodeFunc = f
return m.mock
}
//Code implements github.com/insolar/insolar/core.CodeDescriptor interface
func (m *CodeDescriptorMock) Code() (r []byte, r1 error) {
counter := atomic.AddUint64(&m.CodePreCounter, 1)
defer atomic.AddUint64(&m.CodeCounter, 1)
if len(m.CodeMock.expectationSeries) > 0 {
if counter > uint64(len(m.CodeMock.expectationSeries)) {
m.t.Fatalf("Unexpected call to CodeDescriptorMock.Code.")
return
}
result := m.CodeMock.expectationSeries[counter-1].result
if result == nil {
m.t.Fatal("No results are set for the CodeDescriptorMock.Code")
return
}
r = result.r
r1 = result.r1
return
}
if m.CodeMock.mainExpectation != nil {
result := m.CodeMock.mainExpectation.result
if result == nil {
m.t.Fatal("No results are set for the CodeDescriptorMock.Code")
}
r = result.r
r1 = result.r1
return
}
if m.CodeFunc == nil {
m.t.Fatalf("Unexpected call to CodeDescriptorMock.Code.")
return
}
return m.CodeFunc()
}
//CodeMinimockCounter returns a count of CodeDescriptorMock.CodeFunc invocations
func (m *CodeDescriptorMock) CodeMinimockCounter() uint64 {
return atomic.LoadUint64(&m.CodeCounter)
}
//CodeMinimockPreCounter returns the value of CodeDescriptorMock.Code invocations
func (m *CodeDescriptorMock) CodeMinimockPreCounter() uint64 {
return atomic.LoadUint64(&m.CodePreCounter)
}
//CodeFinished returns true if mock invocations count is ok
func (m *CodeDescriptorMock) CodeFinished() bool {
// if expectation series were set then invocations count should be equal to expectations count
if len(m.CodeMock.expectationSeries) > 0 {
return atomic.LoadUint64(&m.CodeCounter) == uint64(len(m.CodeMock.expectationSeries))
}
// if main expectation was set then invocations count should be greater than zero
if m.CodeMock.mainExpectation != nil {
return atomic.LoadUint64(&m.CodeCounter) > 0
}
// if func was set then invocations count should be greater than zero
if m.CodeFunc != nil {
return atomic.LoadUint64(&m.CodeCounter) > 0
}
return true
}
type mCodeDescriptorMockMachineType struct {
mock *CodeDescriptorMock
mainExpectation *CodeDescriptorMockMachineTypeExpectation
expectationSeries []*CodeDescriptorMockMachineTypeExpectation
}
type CodeDescriptorMockMachineTypeExpectation struct {
result *CodeDescriptorMockMachineTypeResult
}
type CodeDescriptorMockMachineTypeResult struct {
r core.MachineType
}
//Expect specifies that invocation of CodeDescriptor.MachineType is expected from 1 to Infinity times
func (m *mCodeDescriptorMockMachineType) Expect() *mCodeDescriptorMockMachineType {
m.mock.MachineTypeFunc = nil
m.expectationSeries = nil
if m.mainExpectation == nil {
m.mainExpectation = &CodeDescriptorMockMachineTypeExpectation{}
}
return m
}
//Return specifies results of invocation of CodeDescriptor.MachineType
func (m *mCodeDescriptorMockMachineType) Return(r core.MachineType) *CodeDescriptorMock {
m.mock.MachineTypeFunc = nil
m.expectationSeries = nil
if m.mainExpectation == nil {
m.mainExpectation = &CodeDescriptorMockMachineTypeExpectation{}
}
m.mainExpectation.result = &CodeDescriptorMockMachineTypeResult{r}
return m.mock
}
//ExpectOnce specifies that invocation of CodeDescriptor.MachineType is expected once
func (m *mCodeDescriptorMockMachineType) ExpectOnce() *CodeDescriptorMockMachineTypeExpectation {
m.mock.MachineTypeFunc = nil
m.mainExpectation = nil
expectation := &CodeDescriptorMockMachineTypeExpectation{}
m.expectationSeries = append(m.expectationSeries, expectation)
return expectation
}
func (e *CodeDescriptorMockMachineTypeExpectation) Return(r core.MachineType) {
e.result = &CodeDescriptorMockMachineTypeResult{r}
}
//Set uses given function f as a mock of CodeDescriptor.MachineType method
func (m *mCodeDescriptorMockMachineType) Set(f func() (r core.MachineType)) *CodeDescriptorMock {
m.mainExpectation = nil
m.expectationSeries = nil
m.mock.MachineTypeFunc = f
return m.mock
}
//MachineType implements github.com/insolar/insolar/core.CodeDescriptor interface
func (m *CodeDescriptorMock) MachineType() (r core.MachineType) {
counter := atomic.AddUint64(&m.MachineTypePreCounter, 1)
defer atomic.AddUint64(&m.MachineTypeCounter, 1)
if len(m.MachineTypeMock.expectationSeries) > 0 {
if counter > uint64(len(m.MachineTypeMock.expectationSeries)) {
m.t.Fatalf("Unexpected call to CodeDescriptorMock.MachineType.")
return
}
result := m.MachineTypeMock.expectationSeries[counter-1].result
if result == nil {
m.t.Fatal("No results are set for the CodeDescriptorMock.MachineType")
return
}
r = result.r
return
}
if m.MachineTypeMock.mainExpectation != nil {
result := m.MachineTypeMock.mainExpectation.result
if result == nil {
m.t.Fatal("No results are set for the CodeDescriptorMock.MachineType")
}
r = result.r
return
}
if m.MachineTypeFunc == nil {
m.t.Fatalf("Unexpected call to CodeDescriptorMock.MachineType.")
return
}
return m.MachineTypeFunc()
}
//MachineTypeMinimockCounter returns a count of CodeDescriptorMock.MachineTypeFunc invocations
func (m *CodeDescriptorMock) MachineTypeMinimockCounter() uint64 {
return atomic.LoadUint64(&m.MachineTypeCounter)
}
//MachineTypeMinimockPreCounter returns the value of CodeDescriptorMock.MachineType invocations
func (m *CodeDescriptorMock) MachineTypeMinimockPreCounter() uint64 {
return atomic.LoadUint64(&m.MachineTypePreCounter)
}
//MachineTypeFinished returns true if mock invocations count is ok
func (m *CodeDescriptorMock) MachineTypeFinished() bool {
// if expectation series were set then invocations count should be equal to expectations count
if len(m.MachineTypeMock.expectationSeries) > 0 {
return atomic.LoadUint64(&m.MachineTypeCounter) == uint64(len(m.MachineTypeMock.expectationSeries))
}
// if main expectation was set then invocations count should be greater than zero
if m.MachineTypeMock.mainExpectation != nil {
return atomic.LoadUint64(&m.MachineTypeCounter) > 0
}
// if func was set then invocations count should be greater than zero
if m.MachineTypeFunc != nil {
return atomic.LoadUint64(&m.MachineTypeCounter) > 0
}
return true
}
type mCodeDescriptorMockRef struct {
mock *CodeDescriptorMock
mainExpectation *CodeDescriptorMockRefExpectation
expectationSeries []*CodeDescriptorMockRefExpectation
}
type CodeDescriptorMockRefExpectation struct {
result *CodeDescriptorMockRefResult
}
type CodeDescriptorMockRefResult struct {
r *core.RecordRef
}
//Expect specifies that invocation of CodeDescriptor.Ref is expected from 1 to Infinity times
func (m *mCodeDescriptorMockRef) Expect() *mCodeDescriptorMockRef {
m.mock.RefFunc = nil
m.expectationSeries = nil
if m.mainExpectation == nil {
m.mainExpectation = &CodeDescriptorMockRefExpectation{}
}
return m
}
//Return specifies results of invocation of CodeDescriptor.Ref
func (m *mCodeDescriptorMockRef) Return(r *core.RecordRef) *CodeDescriptorMock {
m.mock.RefFunc = nil
m.expectationSeries = nil
if m.mainExpectation == nil {
m.mainExpectation = &CodeDescriptorMockRefExpectation{}
}
m.mainExpectation.result = &CodeDescriptorMockRefResult{r}
return m.mock
}
//ExpectOnce specifies that invocation of CodeDescriptor.Ref is expected once
func (m *mCodeDescriptorMockRef) ExpectOnce() *CodeDescriptorMockRefExpectation {
m.mock.RefFunc = nil
m.mainExpectation = nil
expectation := &CodeDescriptorMockRefExpectation{}
m.expectationSeries = append(m.expectationSeries, expectation)
return expectation
}
func (e *CodeDescriptorMockRefExpectation) Return(r *core.RecordRef) {
e.result = &CodeDescriptorMockRefResult{r}
}
//Set uses given function f as a mock of CodeDescriptor.Ref method
func (m *mCodeDescriptorMockRef) Set(f func() (r *core.RecordRef)) *CodeDescriptorMock {
m.mainExpectation = nil
m.expectationSeries = nil
m.mock.RefFunc = f
return m.mock
}
//Ref implements github.com/insolar/insolar/core.CodeDescriptor interface
func (m *CodeDescriptorMock) Ref() (r *core.RecordRef) {
counter := atomic.AddUint64(&m.RefPreCounter, 1)
defer atomic.AddUint64(&m.RefCounter, 1)
if len(m.RefMock.expectationSeries) > 0 {
if counter > uint64(len(m.RefMock.expectationSeries)) {
m.t.Fatalf("Unexpected call to CodeDescriptorMock.Ref.")
return
}
result := m.RefMock.expectationSeries[counter-1].result
if result == nil {
m.t.Fatal("No results are set for the CodeDescriptorMock.Ref")
return
}
r = result.r
return
}
if m.RefMock.mainExpectation != nil {
result := m.RefMock.mainExpectation.result
if result == nil {
m.t.Fatal("No results are set for the CodeDescriptorMock.Ref")
}
r = result.r
return
}
if m.RefFunc == nil {
m.t.Fatalf("Unexpected call to CodeDescriptorMock.Ref.")
return
}
return m.RefFunc()
}
//RefMinimockCounter returns a count of CodeDescriptorMock.RefFunc invocations
func (m *CodeDescriptorMock) RefMinimockCounter() uint64 {
return atomic.LoadUint64(&m.RefCounter)
}
//RefMinimockPreCounter returns the value of CodeDescriptorMock.Ref invocations
func (m *CodeDescriptorMock) RefMinimockPreCounter() uint64 {
return atomic.LoadUint64(&m.RefPreCounter)
}
//RefFinished returns true if mock invocations count is ok
func (m *CodeDescriptorMock) RefFinished() bool {
// if expectation series were set then invocations count should be equal to expectations count
if len(m.RefMock.expectationSeries) > 0 {
return atomic.LoadUint64(&m.RefCounter) == uint64(len(m.RefMock.expectationSeries))
}
// if main expectation was set then invocations count should be greater than zero
if m.RefMock.mainExpectation != nil {
return atomic.LoadUint64(&m.RefCounter) > 0
}
// if func was set then invocations count should be greater than zero
if m.RefFunc != nil {
return atomic.LoadUint64(&m.RefCounter) > 0
}
return true
}
//ValidateCallCounters checks that all mocked methods of the interface have been called at least once
//Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller
func (m *CodeDescriptorMock) ValidateCallCounters() {
if !m.CodeFinished() {
m.t.Fatal("Expected call to CodeDescriptorMock.Code")
}
if !m.MachineTypeFinished() {
m.t.Fatal("Expected call to CodeDescriptorMock.MachineType")
}
if !m.RefFinished() {
m.t.Fatal("Expected call to CodeDescriptorMock.Ref")
}
}
//CheckMocksCalled checks that all mocked methods of the interface have been called at least once
//Deprecated: please use MinimockFinish method or use Finish method of minimock.Controller
func (m *CodeDescriptorMock) CheckMocksCalled() {
m.Finish()
}
//Finish checks that all mocked methods of the interface have been called at least once
//Deprecated: please use MinimockFinish or use Finish method of minimock.Controller
func (m *CodeDescriptorMock) Finish() {
m.MinimockFinish()
}
//MinimockFinish checks that all mocked methods of the interface have been called at least once
func (m *CodeDescriptorMock) MinimockFinish() {
if !m.CodeFinished() {
m.t.Fatal("Expected call to CodeDescriptorMock.Code")
}
if !m.MachineTypeFinished() {
m.t.Fatal("Expected call to CodeDescriptorMock.MachineType")
}
if !m.RefFinished() {
m.t.Fatal("Expected call to CodeDescriptorMock.Ref")
}
}
//Wait waits for all mocked methods to be called at least once
//Deprecated: please use MinimockWait or use Wait method of minimock.Controller
func (m *CodeDescriptorMock) Wait(timeout time.Duration) {
m.MinimockWait(timeout)
}
//MinimockWait waits for all mocked methods to be called at least once
//this method is called by minimock.Controller
func (m *CodeDescriptorMock) MinimockWait(timeout time.Duration) {
timeoutCh := time.After(timeout)
for {
ok := true
ok = ok && m.CodeFinished()
ok = ok && m.MachineTypeFinished()
ok = ok && m.RefFinished()
if ok {
return
}
select {
case <-timeoutCh:
if !m.CodeFinished() {
m.t.Error("Expected call to CodeDescriptorMock.Code")
}
if !m.MachineTypeFinished() {
m.t.Error("Expected call to CodeDescriptorMock.MachineType")
}
if !m.RefFinished() {
m.t.Error("Expected call to CodeDescriptorMock.Ref")
}
m.t.Fatalf("Some mocks were not called on time: %s", timeout)
return
default:
time.Sleep(time.Millisecond)
}
}
}
//AllMocksCalled returns true if all mocked methods were called before the execution of AllMocksCalled,
//it can be used with assert/require, i.e. assert.True(mock.AllMocksCalled())
func (m *CodeDescriptorMock) AllMocksCalled() bool {
if !m.CodeFinished() {
return false
}
if !m.MachineTypeFinished() {
return false
}
if !m.RefFinished() {
return false
}
return true
}