-
Notifications
You must be signed in to change notification settings - Fork 46
/
availability_checker_mock.go
281 lines (233 loc) · 10.5 KB
/
availability_checker_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
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/v3"
)
// AvailabilityCheckerMock implements insolar.AvailabilityChecker
type AvailabilityCheckerMock struct {
t minimock.Tester
funcIsAvailable func(ctx context.Context) (b1 bool)
inspectFuncIsAvailable func(ctx context.Context)
afterIsAvailableCounter uint64
beforeIsAvailableCounter uint64
IsAvailableMock mAvailabilityCheckerMockIsAvailable
}
// NewAvailabilityCheckerMock returns a mock for insolar.AvailabilityChecker
func NewAvailabilityCheckerMock(t minimock.Tester) *AvailabilityCheckerMock {
m := &AvailabilityCheckerMock{t: t}
if controller, ok := t.(minimock.MockController); ok {
controller.RegisterMocker(m)
}
m.IsAvailableMock = mAvailabilityCheckerMockIsAvailable{mock: m}
m.IsAvailableMock.callArgs = []*AvailabilityCheckerMockIsAvailableParams{}
return m
}
type mAvailabilityCheckerMockIsAvailable struct {
mock *AvailabilityCheckerMock
defaultExpectation *AvailabilityCheckerMockIsAvailableExpectation
expectations []*AvailabilityCheckerMockIsAvailableExpectation
callArgs []*AvailabilityCheckerMockIsAvailableParams
mutex sync.RWMutex
}
// AvailabilityCheckerMockIsAvailableExpectation specifies expectation struct of the AvailabilityChecker.IsAvailable
type AvailabilityCheckerMockIsAvailableExpectation struct {
mock *AvailabilityCheckerMock
params *AvailabilityCheckerMockIsAvailableParams
results *AvailabilityCheckerMockIsAvailableResults
Counter uint64
}
// AvailabilityCheckerMockIsAvailableParams contains parameters of the AvailabilityChecker.IsAvailable
type AvailabilityCheckerMockIsAvailableParams struct {
ctx context.Context
}
// AvailabilityCheckerMockIsAvailableResults contains results of the AvailabilityChecker.IsAvailable
type AvailabilityCheckerMockIsAvailableResults struct {
b1 bool
}
// Expect sets up expected params for AvailabilityChecker.IsAvailable
func (mmIsAvailable *mAvailabilityCheckerMockIsAvailable) Expect(ctx context.Context) *mAvailabilityCheckerMockIsAvailable {
if mmIsAvailable.mock.funcIsAvailable != nil {
mmIsAvailable.mock.t.Fatalf("AvailabilityCheckerMock.IsAvailable mock is already set by Set")
}
if mmIsAvailable.defaultExpectation == nil {
mmIsAvailable.defaultExpectation = &AvailabilityCheckerMockIsAvailableExpectation{}
}
mmIsAvailable.defaultExpectation.params = &AvailabilityCheckerMockIsAvailableParams{ctx}
for _, e := range mmIsAvailable.expectations {
if minimock.Equal(e.params, mmIsAvailable.defaultExpectation.params) {
mmIsAvailable.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmIsAvailable.defaultExpectation.params)
}
}
return mmIsAvailable
}
// Inspect accepts an inspector function that has same arguments as the AvailabilityChecker.IsAvailable
func (mmIsAvailable *mAvailabilityCheckerMockIsAvailable) Inspect(f func(ctx context.Context)) *mAvailabilityCheckerMockIsAvailable {
if mmIsAvailable.mock.inspectFuncIsAvailable != nil {
mmIsAvailable.mock.t.Fatalf("Inspect function is already set for AvailabilityCheckerMock.IsAvailable")
}
mmIsAvailable.mock.inspectFuncIsAvailable = f
return mmIsAvailable
}
// Return sets up results that will be returned by AvailabilityChecker.IsAvailable
func (mmIsAvailable *mAvailabilityCheckerMockIsAvailable) Return(b1 bool) *AvailabilityCheckerMock {
if mmIsAvailable.mock.funcIsAvailable != nil {
mmIsAvailable.mock.t.Fatalf("AvailabilityCheckerMock.IsAvailable mock is already set by Set")
}
if mmIsAvailable.defaultExpectation == nil {
mmIsAvailable.defaultExpectation = &AvailabilityCheckerMockIsAvailableExpectation{mock: mmIsAvailable.mock}
}
mmIsAvailable.defaultExpectation.results = &AvailabilityCheckerMockIsAvailableResults{b1}
return mmIsAvailable.mock
}
//Set uses given function f to mock the AvailabilityChecker.IsAvailable method
func (mmIsAvailable *mAvailabilityCheckerMockIsAvailable) Set(f func(ctx context.Context) (b1 bool)) *AvailabilityCheckerMock {
if mmIsAvailable.defaultExpectation != nil {
mmIsAvailable.mock.t.Fatalf("Default expectation is already set for the AvailabilityChecker.IsAvailable method")
}
if len(mmIsAvailable.expectations) > 0 {
mmIsAvailable.mock.t.Fatalf("Some expectations are already set for the AvailabilityChecker.IsAvailable method")
}
mmIsAvailable.mock.funcIsAvailable = f
return mmIsAvailable.mock
}
// When sets expectation for the AvailabilityChecker.IsAvailable which will trigger the result defined by the following
// Then helper
func (mmIsAvailable *mAvailabilityCheckerMockIsAvailable) When(ctx context.Context) *AvailabilityCheckerMockIsAvailableExpectation {
if mmIsAvailable.mock.funcIsAvailable != nil {
mmIsAvailable.mock.t.Fatalf("AvailabilityCheckerMock.IsAvailable mock is already set by Set")
}
expectation := &AvailabilityCheckerMockIsAvailableExpectation{
mock: mmIsAvailable.mock,
params: &AvailabilityCheckerMockIsAvailableParams{ctx},
}
mmIsAvailable.expectations = append(mmIsAvailable.expectations, expectation)
return expectation
}
// Then sets up AvailabilityChecker.IsAvailable return parameters for the expectation previously defined by the When method
func (e *AvailabilityCheckerMockIsAvailableExpectation) Then(b1 bool) *AvailabilityCheckerMock {
e.results = &AvailabilityCheckerMockIsAvailableResults{b1}
return e.mock
}
// IsAvailable implements insolar.AvailabilityChecker
func (mmIsAvailable *AvailabilityCheckerMock) IsAvailable(ctx context.Context) (b1 bool) {
mm_atomic.AddUint64(&mmIsAvailable.beforeIsAvailableCounter, 1)
defer mm_atomic.AddUint64(&mmIsAvailable.afterIsAvailableCounter, 1)
if mmIsAvailable.inspectFuncIsAvailable != nil {
mmIsAvailable.inspectFuncIsAvailable(ctx)
}
mm_params := &AvailabilityCheckerMockIsAvailableParams{ctx}
// Record call args
mmIsAvailable.IsAvailableMock.mutex.Lock()
mmIsAvailable.IsAvailableMock.callArgs = append(mmIsAvailable.IsAvailableMock.callArgs, mm_params)
mmIsAvailable.IsAvailableMock.mutex.Unlock()
for _, e := range mmIsAvailable.IsAvailableMock.expectations {
if minimock.Equal(e.params, mm_params) {
mm_atomic.AddUint64(&e.Counter, 1)
return e.results.b1
}
}
if mmIsAvailable.IsAvailableMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmIsAvailable.IsAvailableMock.defaultExpectation.Counter, 1)
mm_want := mmIsAvailable.IsAvailableMock.defaultExpectation.params
mm_got := AvailabilityCheckerMockIsAvailableParams{ctx}
if mm_want != nil && !minimock.Equal(*mm_want, mm_got) {
mmIsAvailable.t.Errorf("AvailabilityCheckerMock.IsAvailable got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got))
}
mm_results := mmIsAvailable.IsAvailableMock.defaultExpectation.results
if mm_results == nil {
mmIsAvailable.t.Fatal("No results are set for the AvailabilityCheckerMock.IsAvailable")
}
return (*mm_results).b1
}
if mmIsAvailable.funcIsAvailable != nil {
return mmIsAvailable.funcIsAvailable(ctx)
}
mmIsAvailable.t.Fatalf("Unexpected call to AvailabilityCheckerMock.IsAvailable. %v", ctx)
return
}
// IsAvailableAfterCounter returns a count of finished AvailabilityCheckerMock.IsAvailable invocations
func (mmIsAvailable *AvailabilityCheckerMock) IsAvailableAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmIsAvailable.afterIsAvailableCounter)
}
// IsAvailableBeforeCounter returns a count of AvailabilityCheckerMock.IsAvailable invocations
func (mmIsAvailable *AvailabilityCheckerMock) IsAvailableBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmIsAvailable.beforeIsAvailableCounter)
}
// Calls returns a list of arguments used in each call to AvailabilityCheckerMock.IsAvailable.
// The list is in the same order as the calls were made (i.e. recent calls have a higher index)
func (mmIsAvailable *mAvailabilityCheckerMockIsAvailable) Calls() []*AvailabilityCheckerMockIsAvailableParams {
mmIsAvailable.mutex.RLock()
argCopy := make([]*AvailabilityCheckerMockIsAvailableParams, len(mmIsAvailable.callArgs))
copy(argCopy, mmIsAvailable.callArgs)
mmIsAvailable.mutex.RUnlock()
return argCopy
}
// MinimockIsAvailableDone returns true if the count of the IsAvailable invocations corresponds
// the number of defined expectations
func (m *AvailabilityCheckerMock) MinimockIsAvailableDone() bool {
for _, e := range m.IsAvailableMock.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.IsAvailableMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterIsAvailableCounter) < 1 {
return false
}
// if func was set then invocations count should be greater than zero
if m.funcIsAvailable != nil && mm_atomic.LoadUint64(&m.afterIsAvailableCounter) < 1 {
return false
}
return true
}
// MinimockIsAvailableInspect logs each unmet expectation
func (m *AvailabilityCheckerMock) MinimockIsAvailableInspect() {
for _, e := range m.IsAvailableMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Errorf("Expected call to AvailabilityCheckerMock.IsAvailable with params: %#v", *e.params)
}
}
// if default expectation was set then invocations count should be greater than zero
if m.IsAvailableMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterIsAvailableCounter) < 1 {
if m.IsAvailableMock.defaultExpectation.params == nil {
m.t.Error("Expected call to AvailabilityCheckerMock.IsAvailable")
} else {
m.t.Errorf("Expected call to AvailabilityCheckerMock.IsAvailable with params: %#v", *m.IsAvailableMock.defaultExpectation.params)
}
}
// if func was set then invocations count should be greater than zero
if m.funcIsAvailable != nil && mm_atomic.LoadUint64(&m.afterIsAvailableCounter) < 1 {
m.t.Error("Expected call to AvailabilityCheckerMock.IsAvailable")
}
}
// MinimockFinish checks that all mocked methods have been called the expected number of times
func (m *AvailabilityCheckerMock) MinimockFinish() {
if !m.minimockDone() {
m.MinimockIsAvailableInspect()
m.t.FailNow()
}
}
// MinimockWait waits for all mocked methods to be called the expected number of times
func (m *AvailabilityCheckerMock) 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 *AvailabilityCheckerMock) minimockDone() bool {
done := true
return done &&
m.MinimockIsAvailableDone()
}