-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleaner_mock.go
401 lines (323 loc) · 13.2 KB
/
cleaner_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
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"
)
// CleanerMock implements Cleaner
type CleanerMock struct {
t minimock.Tester
funcNotifyAboutPulse func(ctx context.Context, pn insolar.PulseNumber)
inspectFuncNotifyAboutPulse func(ctx context.Context, pn insolar.PulseNumber)
afterNotifyAboutPulseCounter uint64
beforeNotifyAboutPulseCounter uint64
NotifyAboutPulseMock mCleanerMockNotifyAboutPulse
funcStop func()
inspectFuncStop func()
afterStopCounter uint64
beforeStopCounter uint64
StopMock mCleanerMockStop
}
// NewCleanerMock returns a mock for Cleaner
func NewCleanerMock(t minimock.Tester) *CleanerMock {
m := &CleanerMock{t: t}
if controller, ok := t.(minimock.MockController); ok {
controller.RegisterMocker(m)
}
m.NotifyAboutPulseMock = mCleanerMockNotifyAboutPulse{mock: m}
m.NotifyAboutPulseMock.callArgs = []*CleanerMockNotifyAboutPulseParams{}
m.StopMock = mCleanerMockStop{mock: m}
return m
}
type mCleanerMockNotifyAboutPulse struct {
mock *CleanerMock
defaultExpectation *CleanerMockNotifyAboutPulseExpectation
expectations []*CleanerMockNotifyAboutPulseExpectation
callArgs []*CleanerMockNotifyAboutPulseParams
mutex sync.RWMutex
}
// CleanerMockNotifyAboutPulseExpectation specifies expectation struct of the Cleaner.NotifyAboutPulse
type CleanerMockNotifyAboutPulseExpectation struct {
mock *CleanerMock
params *CleanerMockNotifyAboutPulseParams
Counter uint64
}
// CleanerMockNotifyAboutPulseParams contains parameters of the Cleaner.NotifyAboutPulse
type CleanerMockNotifyAboutPulseParams struct {
ctx context.Context
pn insolar.PulseNumber
}
// Expect sets up expected params for Cleaner.NotifyAboutPulse
func (mmNotifyAboutPulse *mCleanerMockNotifyAboutPulse) Expect(ctx context.Context, pn insolar.PulseNumber) *mCleanerMockNotifyAboutPulse {
if mmNotifyAboutPulse.mock.funcNotifyAboutPulse != nil {
mmNotifyAboutPulse.mock.t.Fatalf("CleanerMock.NotifyAboutPulse mock is already set by Set")
}
if mmNotifyAboutPulse.defaultExpectation == nil {
mmNotifyAboutPulse.defaultExpectation = &CleanerMockNotifyAboutPulseExpectation{}
}
mmNotifyAboutPulse.defaultExpectation.params = &CleanerMockNotifyAboutPulseParams{ctx, pn}
for _, e := range mmNotifyAboutPulse.expectations {
if minimock.Equal(e.params, mmNotifyAboutPulse.defaultExpectation.params) {
mmNotifyAboutPulse.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmNotifyAboutPulse.defaultExpectation.params)
}
}
return mmNotifyAboutPulse
}
// Inspect accepts an inspector function that has same arguments as the Cleaner.NotifyAboutPulse
func (mmNotifyAboutPulse *mCleanerMockNotifyAboutPulse) Inspect(f func(ctx context.Context, pn insolar.PulseNumber)) *mCleanerMockNotifyAboutPulse {
if mmNotifyAboutPulse.mock.inspectFuncNotifyAboutPulse != nil {
mmNotifyAboutPulse.mock.t.Fatalf("Inspect function is already set for CleanerMock.NotifyAboutPulse")
}
mmNotifyAboutPulse.mock.inspectFuncNotifyAboutPulse = f
return mmNotifyAboutPulse
}
// Return sets up results that will be returned by Cleaner.NotifyAboutPulse
func (mmNotifyAboutPulse *mCleanerMockNotifyAboutPulse) Return() *CleanerMock {
if mmNotifyAboutPulse.mock.funcNotifyAboutPulse != nil {
mmNotifyAboutPulse.mock.t.Fatalf("CleanerMock.NotifyAboutPulse mock is already set by Set")
}
if mmNotifyAboutPulse.defaultExpectation == nil {
mmNotifyAboutPulse.defaultExpectation = &CleanerMockNotifyAboutPulseExpectation{mock: mmNotifyAboutPulse.mock}
}
return mmNotifyAboutPulse.mock
}
//Set uses given function f to mock the Cleaner.NotifyAboutPulse method
func (mmNotifyAboutPulse *mCleanerMockNotifyAboutPulse) Set(f func(ctx context.Context, pn insolar.PulseNumber)) *CleanerMock {
if mmNotifyAboutPulse.defaultExpectation != nil {
mmNotifyAboutPulse.mock.t.Fatalf("Default expectation is already set for the Cleaner.NotifyAboutPulse method")
}
if len(mmNotifyAboutPulse.expectations) > 0 {
mmNotifyAboutPulse.mock.t.Fatalf("Some expectations are already set for the Cleaner.NotifyAboutPulse method")
}
mmNotifyAboutPulse.mock.funcNotifyAboutPulse = f
return mmNotifyAboutPulse.mock
}
// NotifyAboutPulse implements Cleaner
func (mmNotifyAboutPulse *CleanerMock) NotifyAboutPulse(ctx context.Context, pn insolar.PulseNumber) {
mm_atomic.AddUint64(&mmNotifyAboutPulse.beforeNotifyAboutPulseCounter, 1)
defer mm_atomic.AddUint64(&mmNotifyAboutPulse.afterNotifyAboutPulseCounter, 1)
if mmNotifyAboutPulse.inspectFuncNotifyAboutPulse != nil {
mmNotifyAboutPulse.inspectFuncNotifyAboutPulse(ctx, pn)
}
params := &CleanerMockNotifyAboutPulseParams{ctx, pn}
// Record call args
mmNotifyAboutPulse.NotifyAboutPulseMock.mutex.Lock()
mmNotifyAboutPulse.NotifyAboutPulseMock.callArgs = append(mmNotifyAboutPulse.NotifyAboutPulseMock.callArgs, params)
mmNotifyAboutPulse.NotifyAboutPulseMock.mutex.Unlock()
for _, e := range mmNotifyAboutPulse.NotifyAboutPulseMock.expectations {
if minimock.Equal(e.params, params) {
mm_atomic.AddUint64(&e.Counter, 1)
return
}
}
if mmNotifyAboutPulse.NotifyAboutPulseMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmNotifyAboutPulse.NotifyAboutPulseMock.defaultExpectation.Counter, 1)
want := mmNotifyAboutPulse.NotifyAboutPulseMock.defaultExpectation.params
got := CleanerMockNotifyAboutPulseParams{ctx, pn}
if want != nil && !minimock.Equal(*want, got) {
mmNotifyAboutPulse.t.Errorf("CleanerMock.NotifyAboutPulse got unexpected parameters, want: %#v, got: %#v%s\n", *want, got, minimock.Diff(*want, got))
}
return
}
if mmNotifyAboutPulse.funcNotifyAboutPulse != nil {
mmNotifyAboutPulse.funcNotifyAboutPulse(ctx, pn)
return
}
mmNotifyAboutPulse.t.Fatalf("Unexpected call to CleanerMock.NotifyAboutPulse. %v %v", ctx, pn)
}
// NotifyAboutPulseAfterCounter returns a count of finished CleanerMock.NotifyAboutPulse invocations
func (mmNotifyAboutPulse *CleanerMock) NotifyAboutPulseAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmNotifyAboutPulse.afterNotifyAboutPulseCounter)
}
// NotifyAboutPulseBeforeCounter returns a count of CleanerMock.NotifyAboutPulse invocations
func (mmNotifyAboutPulse *CleanerMock) NotifyAboutPulseBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmNotifyAboutPulse.beforeNotifyAboutPulseCounter)
}
// Calls returns a list of arguments used in each call to CleanerMock.NotifyAboutPulse.
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
func (mmNotifyAboutPulse *mCleanerMockNotifyAboutPulse) Calls() []*CleanerMockNotifyAboutPulseParams {
mmNotifyAboutPulse.mutex.RLock()
argCopy := make([]*CleanerMockNotifyAboutPulseParams, len(mmNotifyAboutPulse.callArgs))
copy(argCopy, mmNotifyAboutPulse.callArgs)
mmNotifyAboutPulse.mutex.RUnlock()
return argCopy
}
// MinimockNotifyAboutPulseDone returns true if the count of the NotifyAboutPulse invocations corresponds
// the number of defined expectations
func (m *CleanerMock) MinimockNotifyAboutPulseDone() bool {
for _, e := range m.NotifyAboutPulseMock.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.NotifyAboutPulseMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNotifyAboutPulseCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcNotifyAboutPulse != nil && mm_atomic.LoadUint64(&m.afterNotifyAboutPulseCounter) < 1 {
return false
}
return true
}
// MinimockNotifyAboutPulseInspect logs each unmet expectation
func (m *CleanerMock) MinimockNotifyAboutPulseInspect() {
for _, e := range m.NotifyAboutPulseMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Errorf("Expected call to CleanerMock.NotifyAboutPulse with params: %#v", *e.params)
}
}
// if default expectation was set then invocations count should be greater than zero
if m.NotifyAboutPulseMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNotifyAboutPulseCounter) < 1 {
if m.NotifyAboutPulseMock.defaultExpectation.params == nil {
m.t.Error("Expected call to CleanerMock.NotifyAboutPulse")
} else {
m.t.Errorf("Expected call to CleanerMock.NotifyAboutPulse with params: %#v", *m.NotifyAboutPulseMock.defaultExpectation.params)
}
}
// if func was set then invocations count should be greater than zero
if m.funcNotifyAboutPulse != nil && mm_atomic.LoadUint64(&m.afterNotifyAboutPulseCounter) < 1 {
m.t.Error("Expected call to CleanerMock.NotifyAboutPulse")
}
}
type mCleanerMockStop struct {
mock *CleanerMock
defaultExpectation *CleanerMockStopExpectation
expectations []*CleanerMockStopExpectation
}
// CleanerMockStopExpectation specifies expectation struct of the Cleaner.Stop
type CleanerMockStopExpectation struct {
mock *CleanerMock
Counter uint64
}
// Expect sets up expected params for Cleaner.Stop
func (mmStop *mCleanerMockStop) Expect() *mCleanerMockStop {
if mmStop.mock.funcStop != nil {
mmStop.mock.t.Fatalf("CleanerMock.Stop mock is already set by Set")
}
if mmStop.defaultExpectation == nil {
mmStop.defaultExpectation = &CleanerMockStopExpectation{}
}
return mmStop
}
// Inspect accepts an inspector function that has same arguments as the Cleaner.Stop
func (mmStop *mCleanerMockStop) Inspect(f func()) *mCleanerMockStop {
if mmStop.mock.inspectFuncStop != nil {
mmStop.mock.t.Fatalf("Inspect function is already set for CleanerMock.Stop")
}
mmStop.mock.inspectFuncStop = f
return mmStop
}
// Return sets up results that will be returned by Cleaner.Stop
func (mmStop *mCleanerMockStop) Return() *CleanerMock {
if mmStop.mock.funcStop != nil {
mmStop.mock.t.Fatalf("CleanerMock.Stop mock is already set by Set")
}
if mmStop.defaultExpectation == nil {
mmStop.defaultExpectation = &CleanerMockStopExpectation{mock: mmStop.mock}
}
return mmStop.mock
}
//Set uses given function f to mock the Cleaner.Stop method
func (mmStop *mCleanerMockStop) Set(f func()) *CleanerMock {
if mmStop.defaultExpectation != nil {
mmStop.mock.t.Fatalf("Default expectation is already set for the Cleaner.Stop method")
}
if len(mmStop.expectations) > 0 {
mmStop.mock.t.Fatalf("Some expectations are already set for the Cleaner.Stop method")
}
mmStop.mock.funcStop = f
return mmStop.mock
}
// Stop implements Cleaner
func (mmStop *CleanerMock) Stop() {
mm_atomic.AddUint64(&mmStop.beforeStopCounter, 1)
defer mm_atomic.AddUint64(&mmStop.afterStopCounter, 1)
if mmStop.inspectFuncStop != nil {
mmStop.inspectFuncStop()
}
if mmStop.StopMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmStop.StopMock.defaultExpectation.Counter, 1)
return
}
if mmStop.funcStop != nil {
mmStop.funcStop()
return
}
mmStop.t.Fatalf("Unexpected call to CleanerMock.Stop.")
}
// StopAfterCounter returns a count of finished CleanerMock.Stop invocations
func (mmStop *CleanerMock) StopAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmStop.afterStopCounter)
}
// StopBeforeCounter returns a count of CleanerMock.Stop invocations
func (mmStop *CleanerMock) StopBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmStop.beforeStopCounter)
}
// MinimockStopDone returns true if the count of the Stop invocations corresponds
// the number of defined expectations
func (m *CleanerMock) MinimockStopDone() bool {
for _, e := range m.StopMock.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.StopMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterStopCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcStop != nil && mm_atomic.LoadUint64(&m.afterStopCounter) < 1 {
return false
}
return true
}
// MinimockStopInspect logs each unmet expectation
func (m *CleanerMock) MinimockStopInspect() {
for _, e := range m.StopMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Error("Expected call to CleanerMock.Stop")
}
}
// if default expectation was set then invocations count should be greater than zero
if m.StopMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterStopCounter) < 1 {
m.t.Error("Expected call to CleanerMock.Stop")
}
// if func was set then invocations count should be greater than zero
if m.funcStop != nil && mm_atomic.LoadUint64(&m.afterStopCounter) < 1 {
m.t.Error("Expected call to CleanerMock.Stop")
}
}
// MinimockFinish checks that all mocked methods have been called the expected number of times
func (m *CleanerMock) MinimockFinish() {
if !m.minimockDone() {
m.MinimockNotifyAboutPulseInspect()
m.MinimockStopInspect()
m.t.FailNow()
}
}
// MinimockWait waits for all mocked methods to be called the expected number of times
func (m *CleanerMock) 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 *CleanerMock) minimockDone() bool {
done := true
return done &&
m.MinimockNotifyAboutPulseDone() &&
m.MinimockStopDone()
}