/
meter_mock.go
377 lines (353 loc) · 12.8 KB
/
meter_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
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package fake
import (
"go.opentelemetry.io/otel/metric"
"sync"
)
// IMeterMock is a mock implementation of interfaces.IMeter.
//
// func TestSomethingThatUsesIMeter(t *testing.T) {
//
// // make and configure a mocked interfaces.IMeter
// mockedIMeter := &IMeterMock{
// Float64CounterFunc: func(name string, options ...metric.Float64CounterOption) (metric.Float64Counter, error) {
// panic("mock out the Float64Counter method")
// },
// Float64HistogramFunc: func(name string, options ...metric.Float64HistogramOption) (metric.Float64Histogram, error) {
// panic("mock out the Float64Histogram method")
// },
// Float64ObservableGaugeFunc: func(name string, options ...metric.Float64ObservableGaugeOption) (metric.Float64ObservableGauge, error) {
// panic("mock out the Float64ObservableGauge method")
// },
// Int64CounterFunc: func(name string, options ...metric.Int64CounterOption) (metric.Int64Counter, error) {
// panic("mock out the Int64Counter method")
// },
// Int64HistogramFunc: func(name string, options ...metric.Int64HistogramOption) (metric.Int64Histogram, error) {
// panic("mock out the Int64Histogram method")
// },
// Int64ObservableGaugeFunc: func(name string, options ...metric.Int64ObservableGaugeOption) (metric.Int64ObservableGauge, error) {
// panic("mock out the Int64ObservableGauge method")
// },
// RegisterCallbackFunc: func(f metric.Callback, instruments ...metric.Observable) (metric.Registration, error) {
// panic("mock out the RegisterCallback method")
// },
// }
//
// // use mockedIMeter in code that requires interfaces.IMeter
// // and then make assertions.
//
// }
type IMeterMock struct {
// Float64CounterFunc mocks the Float64Counter method.
Float64CounterFunc func(name string, options ...metric.Float64CounterOption) (metric.Float64Counter, error)
// Float64HistogramFunc mocks the Float64Histogram method.
Float64HistogramFunc func(name string, options ...metric.Float64HistogramOption) (metric.Float64Histogram, error)
// Float64ObservableGaugeFunc mocks the Float64ObservableGauge method.
Float64ObservableGaugeFunc func(name string, options ...metric.Float64ObservableGaugeOption) (metric.Float64ObservableGauge, error)
// Int64CounterFunc mocks the Int64Counter method.
Int64CounterFunc func(name string, options ...metric.Int64CounterOption) (metric.Int64Counter, error)
// Int64HistogramFunc mocks the Int64Histogram method.
Int64HistogramFunc func(name string, options ...metric.Int64HistogramOption) (metric.Int64Histogram, error)
// Int64ObservableGaugeFunc mocks the Int64ObservableGauge method.
Int64ObservableGaugeFunc func(name string, options ...metric.Int64ObservableGaugeOption) (metric.Int64ObservableGauge, error)
// RegisterCallbackFunc mocks the RegisterCallback method.
RegisterCallbackFunc func(f metric.Callback, instruments ...metric.Observable) (metric.Registration, error)
// calls tracks calls to the methods.
calls struct {
// Float64Counter holds details about calls to the Float64Counter method.
Float64Counter []struct {
// Name is the name argument value.
Name string
// Options is the options argument value.
Options []metric.Float64CounterOption
}
// Float64Histogram holds details about calls to the Float64Histogram method.
Float64Histogram []struct {
// Name is the name argument value.
Name string
// Options is the options argument value.
Options []metric.Float64HistogramOption
}
// Float64ObservableGauge holds details about calls to the Float64ObservableGauge method.
Float64ObservableGauge []struct {
// Name is the name argument value.
Name string
// Options is the options argument value.
Options []metric.Float64ObservableGaugeOption
}
// Int64Counter holds details about calls to the Int64Counter method.
Int64Counter []struct {
// Name is the name argument value.
Name string
// Options is the options argument value.
Options []metric.Int64CounterOption
}
// Int64Histogram holds details about calls to the Int64Histogram method.
Int64Histogram []struct {
// Name is the name argument value.
Name string
// Options is the options argument value.
Options []metric.Int64HistogramOption
}
// Int64ObservableGauge holds details about calls to the Int64ObservableGauge method.
Int64ObservableGauge []struct {
// Name is the name argument value.
Name string
// Options is the options argument value.
Options []metric.Int64ObservableGaugeOption
}
// RegisterCallback holds details about calls to the RegisterCallback method.
RegisterCallback []struct {
// F is the f argument value.
F metric.Callback
// Instruments is the instruments argument value.
Instruments []metric.Observable
}
}
lockFloat64Counter sync.RWMutex
lockFloat64Histogram sync.RWMutex
lockFloat64ObservableGauge sync.RWMutex
lockInt64Counter sync.RWMutex
lockInt64Histogram sync.RWMutex
lockInt64ObservableGauge sync.RWMutex
lockRegisterCallback sync.RWMutex
}
// Float64Counter calls Float64CounterFunc.
func (mock *IMeterMock) Float64Counter(name string, options ...metric.Float64CounterOption) (metric.Float64Counter, error) {
if mock.Float64CounterFunc == nil {
panic("IMeterMock.Float64CounterFunc: method is nil but IMeter.Float64Counter was just called")
}
callInfo := struct {
Name string
Options []metric.Float64CounterOption
}{
Name: name,
Options: options,
}
mock.lockFloat64Counter.Lock()
mock.calls.Float64Counter = append(mock.calls.Float64Counter, callInfo)
mock.lockFloat64Counter.Unlock()
return mock.Float64CounterFunc(name, options...)
}
// Float64CounterCalls gets all the calls that were made to Float64Counter.
// Check the length with:
//
// len(mockedIMeter.Float64CounterCalls())
func (mock *IMeterMock) Float64CounterCalls() []struct {
Name string
Options []metric.Float64CounterOption
} {
var calls []struct {
Name string
Options []metric.Float64CounterOption
}
mock.lockFloat64Counter.RLock()
calls = mock.calls.Float64Counter
mock.lockFloat64Counter.RUnlock()
return calls
}
// Float64Histogram calls Float64HistogramFunc.
func (mock *IMeterMock) Float64Histogram(name string, options ...metric.Float64HistogramOption) (metric.Float64Histogram, error) {
if mock.Float64HistogramFunc == nil {
panic("IMeterMock.Float64HistogramFunc: method is nil but IMeter.Float64Histogram was just called")
}
callInfo := struct {
Name string
Options []metric.Float64HistogramOption
}{
Name: name,
Options: options,
}
mock.lockFloat64Histogram.Lock()
mock.calls.Float64Histogram = append(mock.calls.Float64Histogram, callInfo)
mock.lockFloat64Histogram.Unlock()
return mock.Float64HistogramFunc(name, options...)
}
// Float64HistogramCalls gets all the calls that were made to Float64Histogram.
// Check the length with:
//
// len(mockedIMeter.Float64HistogramCalls())
func (mock *IMeterMock) Float64HistogramCalls() []struct {
Name string
Options []metric.Float64HistogramOption
} {
var calls []struct {
Name string
Options []metric.Float64HistogramOption
}
mock.lockFloat64Histogram.RLock()
calls = mock.calls.Float64Histogram
mock.lockFloat64Histogram.RUnlock()
return calls
}
// Float64ObservableGauge calls Float64ObservableGaugeFunc.
func (mock *IMeterMock) Float64ObservableGauge(name string, options ...metric.Float64ObservableGaugeOption) (metric.Float64ObservableGauge, error) {
if mock.Float64ObservableGaugeFunc == nil {
panic("IMeterMock.Float64ObservableGaugeFunc: method is nil but IMeter.Float64ObservableGauge was just called")
}
callInfo := struct {
Name string
Options []metric.Float64ObservableGaugeOption
}{
Name: name,
Options: options,
}
mock.lockFloat64ObservableGauge.Lock()
mock.calls.Float64ObservableGauge = append(mock.calls.Float64ObservableGauge, callInfo)
mock.lockFloat64ObservableGauge.Unlock()
return mock.Float64ObservableGaugeFunc(name, options...)
}
// Float64ObservableGaugeCalls gets all the calls that were made to Float64ObservableGauge.
// Check the length with:
//
// len(mockedIMeter.Float64ObservableGaugeCalls())
func (mock *IMeterMock) Float64ObservableGaugeCalls() []struct {
Name string
Options []metric.Float64ObservableGaugeOption
} {
var calls []struct {
Name string
Options []metric.Float64ObservableGaugeOption
}
mock.lockFloat64ObservableGauge.RLock()
calls = mock.calls.Float64ObservableGauge
mock.lockFloat64ObservableGauge.RUnlock()
return calls
}
// Int64Counter calls Int64CounterFunc.
func (mock *IMeterMock) Int64Counter(name string, options ...metric.Int64CounterOption) (metric.Int64Counter, error) {
if mock.Int64CounterFunc == nil {
panic("IMeterMock.Int64CounterFunc: method is nil but IMeter.Int64Counter was just called")
}
callInfo := struct {
Name string
Options []metric.Int64CounterOption
}{
Name: name,
Options: options,
}
mock.lockInt64Counter.Lock()
mock.calls.Int64Counter = append(mock.calls.Int64Counter, callInfo)
mock.lockInt64Counter.Unlock()
return mock.Int64CounterFunc(name, options...)
}
// Int64CounterCalls gets all the calls that were made to Int64Counter.
// Check the length with:
//
// len(mockedIMeter.Int64CounterCalls())
func (mock *IMeterMock) Int64CounterCalls() []struct {
Name string
Options []metric.Int64CounterOption
} {
var calls []struct {
Name string
Options []metric.Int64CounterOption
}
mock.lockInt64Counter.RLock()
calls = mock.calls.Int64Counter
mock.lockInt64Counter.RUnlock()
return calls
}
// Int64Histogram calls Int64HistogramFunc.
func (mock *IMeterMock) Int64Histogram(name string, options ...metric.Int64HistogramOption) (metric.Int64Histogram, error) {
if mock.Int64HistogramFunc == nil {
panic("IMeterMock.Int64HistogramFunc: method is nil but IMeter.Int64Histogram was just called")
}
callInfo := struct {
Name string
Options []metric.Int64HistogramOption
}{
Name: name,
Options: options,
}
mock.lockInt64Histogram.Lock()
mock.calls.Int64Histogram = append(mock.calls.Int64Histogram, callInfo)
mock.lockInt64Histogram.Unlock()
return mock.Int64HistogramFunc(name, options...)
}
// Int64HistogramCalls gets all the calls that were made to Int64Histogram.
// Check the length with:
//
// len(mockedIMeter.Int64HistogramCalls())
func (mock *IMeterMock) Int64HistogramCalls() []struct {
Name string
Options []metric.Int64HistogramOption
} {
var calls []struct {
Name string
Options []metric.Int64HistogramOption
}
mock.lockInt64Histogram.RLock()
calls = mock.calls.Int64Histogram
mock.lockInt64Histogram.RUnlock()
return calls
}
// Int64ObservableGauge calls Int64ObservableGaugeFunc.
func (mock *IMeterMock) Int64ObservableGauge(name string, options ...metric.Int64ObservableGaugeOption) (metric.Int64ObservableGauge, error) {
if mock.Int64ObservableGaugeFunc == nil {
panic("IMeterMock.Int64ObservableGaugeFunc: method is nil but IMeter.Int64ObservableGauge was just called")
}
callInfo := struct {
Name string
Options []metric.Int64ObservableGaugeOption
}{
Name: name,
Options: options,
}
mock.lockInt64ObservableGauge.Lock()
mock.calls.Int64ObservableGauge = append(mock.calls.Int64ObservableGauge, callInfo)
mock.lockInt64ObservableGauge.Unlock()
return mock.Int64ObservableGaugeFunc(name, options...)
}
// Int64ObservableGaugeCalls gets all the calls that were made to Int64ObservableGauge.
// Check the length with:
//
// len(mockedIMeter.Int64ObservableGaugeCalls())
func (mock *IMeterMock) Int64ObservableGaugeCalls() []struct {
Name string
Options []metric.Int64ObservableGaugeOption
} {
var calls []struct {
Name string
Options []metric.Int64ObservableGaugeOption
}
mock.lockInt64ObservableGauge.RLock()
calls = mock.calls.Int64ObservableGauge
mock.lockInt64ObservableGauge.RUnlock()
return calls
}
// RegisterCallback calls RegisterCallbackFunc.
func (mock *IMeterMock) RegisterCallback(f metric.Callback, instruments ...metric.Observable) (metric.Registration, error) {
if mock.RegisterCallbackFunc == nil {
panic("IMeterMock.RegisterCallbackFunc: method is nil but IMeter.RegisterCallback was just called")
}
callInfo := struct {
F metric.Callback
Instruments []metric.Observable
}{
F: f,
Instruments: instruments,
}
mock.lockRegisterCallback.Lock()
mock.calls.RegisterCallback = append(mock.calls.RegisterCallback, callInfo)
mock.lockRegisterCallback.Unlock()
return mock.RegisterCallbackFunc(f, instruments...)
}
// RegisterCallbackCalls gets all the calls that were made to RegisterCallback.
// Check the length with:
//
// len(mockedIMeter.RegisterCallbackCalls())
func (mock *IMeterMock) RegisterCallbackCalls() []struct {
F metric.Callback
Instruments []metric.Observable
} {
var calls []struct {
F metric.Callback
Instruments []metric.Observable
}
mock.lockRegisterCallback.RLock()
calls = mock.calls.RegisterCallback
mock.lockRegisterCallback.RUnlock()
return calls
}