-
Notifications
You must be signed in to change notification settings - Fork 38
/
generic_out.go
235 lines (190 loc) · 6.75 KB
/
generic_out.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
// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT.
package tests
//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericOut -o generic_out.go -n GenericOutMock -p tests
import (
"sync"
mm_atomic "sync/atomic"
mm_time "time"
"github.com/gojuno/minimock/v3"
)
// GenericOutMock implements genericOut
type GenericOutMock[T any] struct {
t minimock.Tester
finishOnce sync.Once
funcName func() (t1 T)
inspectFuncName func()
afterNameCounter uint64
beforeNameCounter uint64
NameMock mGenericOutMockName[T]
}
// NewGenericOutMock returns a mock for genericOut
func NewGenericOutMock[T any](t minimock.Tester) *GenericOutMock[T] {
m := &GenericOutMock[T]{t: t}
if controller, ok := t.(minimock.MockController); ok {
controller.RegisterMocker(m)
}
m.NameMock = mGenericOutMockName[T]{mock: m}
t.Cleanup(m.MinimockFinish)
return m
}
type mGenericOutMockName[T any] struct {
mock *GenericOutMock[T]
defaultExpectation *GenericOutMockNameExpectation[T]
expectations []*GenericOutMockNameExpectation[T]
expectedInvocations uint64
}
// GenericOutMockNameExpectation specifies expectation struct of the genericOut.Name
type GenericOutMockNameExpectation[T any] struct {
mock *GenericOutMock[T]
results *GenericOutMockNameResults[T]
Counter uint64
}
// GenericOutMockNameResults contains results of the genericOut.Name
type GenericOutMockNameResults[T any] struct {
t1 T
}
// Expect sets up expected params for genericOut.Name
func (mmName *mGenericOutMockName[T]) Expect() *mGenericOutMockName[T] {
if mmName.mock.funcName != nil {
mmName.mock.t.Fatalf("GenericOutMock.Name mock is already set by Set")
}
if mmName.defaultExpectation == nil {
mmName.defaultExpectation = &GenericOutMockNameExpectation[T]{}
}
return mmName
}
// Inspect accepts an inspector function that has same arguments as the genericOut.Name
func (mmName *mGenericOutMockName[T]) Inspect(f func()) *mGenericOutMockName[T] {
if mmName.mock.inspectFuncName != nil {
mmName.mock.t.Fatalf("Inspect function is already set for GenericOutMock.Name")
}
mmName.mock.inspectFuncName = f
return mmName
}
// Return sets up results that will be returned by genericOut.Name
func (mmName *mGenericOutMockName[T]) Return(t1 T) *GenericOutMock[T] {
if mmName.mock.funcName != nil {
mmName.mock.t.Fatalf("GenericOutMock.Name mock is already set by Set")
}
if mmName.defaultExpectation == nil {
mmName.defaultExpectation = &GenericOutMockNameExpectation[T]{mock: mmName.mock}
}
mmName.defaultExpectation.results = &GenericOutMockNameResults[T]{t1}
return mmName.mock
}
// Set uses given function f to mock the genericOut.Name method
func (mmName *mGenericOutMockName[T]) Set(f func() (t1 T)) *GenericOutMock[T] {
if mmName.defaultExpectation != nil {
mmName.mock.t.Fatalf("Default expectation is already set for the genericOut.Name method")
}
if len(mmName.expectations) > 0 {
mmName.mock.t.Fatalf("Some expectations are already set for the genericOut.Name method")
}
mmName.mock.funcName = f
return mmName.mock
}
// Times sets number of times genericOut.Name should be invoked
func (mmName *mGenericOutMockName[T]) Times(n uint64) *mGenericOutMockName[T] {
if n == 0 {
mmName.mock.t.Fatalf("Times of GenericOutMock.Name mock can not be zero")
}
mm_atomic.StoreUint64(&mmName.expectedInvocations, n)
return mmName
}
func (mmName *mGenericOutMockName[T]) invocationsDone() bool {
if len(mmName.expectations) == 0 && mmName.defaultExpectation == nil && mmName.mock.funcName == nil {
return true
}
totalInvocations := mm_atomic.LoadUint64(&mmName.mock.afterNameCounter)
expectedInvocations := mm_atomic.LoadUint64(&mmName.expectedInvocations)
return totalInvocations > 0 && (expectedInvocations == 0 || expectedInvocations == totalInvocations)
}
// Name implements genericOut
func (mmName *GenericOutMock[T]) Name() (t1 T) {
mm_atomic.AddUint64(&mmName.beforeNameCounter, 1)
defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1)
if mmName.inspectFuncName != nil {
mmName.inspectFuncName()
}
if mmName.NameMock.defaultExpectation != nil {
mm_atomic.AddUint64(&mmName.NameMock.defaultExpectation.Counter, 1)
mm_results := mmName.NameMock.defaultExpectation.results
if mm_results == nil {
mmName.t.Fatal("No results are set for the GenericOutMock.Name")
}
return (*mm_results).t1
}
if mmName.funcName != nil {
return mmName.funcName()
}
mmName.t.Fatalf("Unexpected call to GenericOutMock.Name.")
return
}
// NameAfterCounter returns a count of finished GenericOutMock.Name invocations
func (mmName *GenericOutMock[T]) NameAfterCounter() uint64 {
return mm_atomic.LoadUint64(&mmName.afterNameCounter)
}
// NameBeforeCounter returns a count of GenericOutMock.Name invocations
func (mmName *GenericOutMock[T]) NameBeforeCounter() uint64 {
return mm_atomic.LoadUint64(&mmName.beforeNameCounter)
}
// MinimockNameDone returns true if the count of the Name invocations corresponds
// the number of defined expectations
func (m *GenericOutMock[T]) MinimockNameDone() bool {
for _, e := range m.NameMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
return false
}
}
return m.NameMock.invocationsDone()
}
// MinimockNameInspect logs each unmet expectation
func (m *GenericOutMock[T]) MinimockNameInspect() {
for _, e := range m.NameMock.expectations {
if mm_atomic.LoadUint64(&e.Counter) < 1 {
m.t.Error("Expected call to GenericOutMock.Name")
}
}
afterNameCounter := mm_atomic.LoadUint64(&m.afterNameCounter)
// if default expectation was set then invocations count should be greater than zero
if m.NameMock.defaultExpectation != nil && afterNameCounter < 1 {
m.t.Error("Expected call to GenericOutMock.Name")
}
// if func was set then invocations count should be greater than zero
if m.funcName != nil && afterNameCounter < 1 {
m.t.Error("Expected call to GenericOutMock.Name")
}
if !m.NameMock.invocationsDone() && afterNameCounter > 0 {
m.t.Errorf("Expected %d calls to GenericOutMock.Name but found %d calls",
mm_atomic.LoadUint64(&m.NameMock.expectedInvocations), afterNameCounter)
}
}
// MinimockFinish checks that all mocked methods have been called the expected number of times
func (m *GenericOutMock[T]) MinimockFinish() {
m.finishOnce.Do(func() {
if !m.minimockDone() {
m.MinimockNameInspect()
m.t.FailNow()
}
})
}
// MinimockWait waits for all mocked methods to be called the expected number of times
func (m *GenericOutMock[T]) 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 *GenericOutMock[T]) minimockDone() bool {
done := true
return done &&
m.MinimockNameDone()
}