-
Notifications
You must be signed in to change notification settings - Fork 2
/
raiju_mock_test.go
521 lines (491 loc) · 15.3 KB
/
raiju_mock_test.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
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package raiju
import (
"context"
"github.com/nyonson/raiju/lightning"
"sync"
"time"
)
// lightningerMock is a mock implementation of lightninger.
//
// func TestSomethingThatUseslightninger(t *testing.T) {
//
// // make and configure a mocked lightninger
// mockedlightninger := &lightningerMock{
// AddInvoiceFunc: func(ctx context.Context, amount lightning.Satoshi) (lightning.Invoice, error) {
// panic("mock out the AddInvoice method")
// },
// DescribeGraphFunc: func(ctx context.Context) (*lightning.Graph, error) {
// panic("mock out the DescribeGraph method")
// },
// ForwardingHistoryFunc: func(ctx context.Context, since time.Time) ([]lightning.Forward, error) {
// panic("mock out the ForwardingHistory method")
// },
// GetChannelFunc: func(ctx context.Context, channelID lightning.ChannelID) (lightning.Channel, error) {
// panic("mock out the GetChannel method")
// },
// GetInfoFunc: func(ctx context.Context) (*lightning.Info, error) {
// panic("mock out the GetInfo method")
// },
// ListChannelsFunc: func(ctx context.Context) (lightning.Channels, error) {
// panic("mock out the ListChannels method")
// },
// SendPaymentFunc: func(ctx context.Context, invoice lightning.Invoice, outChannelID lightning.ChannelID, lastHopPubKey lightning.PubKey, maxFee lightning.FeePPM) (lightning.Satoshi, error) {
// panic("mock out the SendPayment method")
// },
// SetFeesFunc: func(ctx context.Context, channelID lightning.ChannelID, fee lightning.FeePPM, maxHTLC lightning.MilliSatoshi) error {
// panic("mock out the SetFees method")
// },
// SubscribeChannelUpdatesFunc: func(ctx context.Context) (<-chan lightning.Channels, <-chan error, error) {
// panic("mock out the SubscribeChannelUpdates method")
// },
// }
//
// // use mockedlightninger in code that requires lightninger
// // and then make assertions.
//
// }
type lightningerMock struct {
// AddInvoiceFunc mocks the AddInvoice method.
AddInvoiceFunc func(ctx context.Context, amount lightning.Satoshi) (lightning.Invoice, error)
// DescribeGraphFunc mocks the DescribeGraph method.
DescribeGraphFunc func(ctx context.Context) (*lightning.Graph, error)
// ForwardingHistoryFunc mocks the ForwardingHistory method.
ForwardingHistoryFunc func(ctx context.Context, since time.Time) ([]lightning.Forward, error)
// GetChannelFunc mocks the GetChannel method.
GetChannelFunc func(ctx context.Context, channelID lightning.ChannelID) (lightning.Channel, error)
// GetInfoFunc mocks the GetInfo method.
GetInfoFunc func(ctx context.Context) (*lightning.Info, error)
// ListChannelsFunc mocks the ListChannels method.
ListChannelsFunc func(ctx context.Context) (lightning.Channels, error)
// SendPaymentFunc mocks the SendPayment method.
SendPaymentFunc func(ctx context.Context, invoice lightning.Invoice, outChannelID lightning.ChannelID, lastHopPubKey lightning.PubKey, maxFee lightning.FeePPM) (lightning.Satoshi, error)
// SetFeesFunc mocks the SetFees method.
SetFeesFunc func(ctx context.Context, channelID lightning.ChannelID, fee lightning.FeePPM, maxHTLC lightning.MilliSatoshi) error
// SubscribeChannelUpdatesFunc mocks the SubscribeChannelUpdates method.
SubscribeChannelUpdatesFunc func(ctx context.Context) (<-chan lightning.Channels, <-chan error, error)
// calls tracks calls to the methods.
calls struct {
// AddInvoice holds details about calls to the AddInvoice method.
AddInvoice []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Amount is the amount argument value.
Amount lightning.Satoshi
}
// DescribeGraph holds details about calls to the DescribeGraph method.
DescribeGraph []struct {
// Ctx is the ctx argument value.
Ctx context.Context
}
// ForwardingHistory holds details about calls to the ForwardingHistory method.
ForwardingHistory []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Since is the since argument value.
Since time.Time
}
// GetChannel holds details about calls to the GetChannel method.
GetChannel []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// ChannelID is the channelID argument value.
ChannelID lightning.ChannelID
}
// GetInfo holds details about calls to the GetInfo method.
GetInfo []struct {
// Ctx is the ctx argument value.
Ctx context.Context
}
// ListChannels holds details about calls to the ListChannels method.
ListChannels []struct {
// Ctx is the ctx argument value.
Ctx context.Context
}
// SendPayment holds details about calls to the SendPayment method.
SendPayment []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Invoice is the invoice argument value.
Invoice lightning.Invoice
// OutChannelID is the outChannelID argument value.
OutChannelID lightning.ChannelID
// LastHopPubKey is the lastHopPubKey argument value.
LastHopPubKey lightning.PubKey
// MaxFee is the maxFee argument value.
MaxFee lightning.FeePPM
}
// SetFees holds details about calls to the SetFees method.
SetFees []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// ChannelID is the channelID argument value.
ChannelID lightning.ChannelID
// Fee is the fee argument value.
Fee lightning.FeePPM
// MaxHTLC is the maxHTLC argument value.
MaxHTLC lightning.MilliSatoshi
}
// SubscribeChannelUpdates holds details about calls to the SubscribeChannelUpdates method.
SubscribeChannelUpdates []struct {
// Ctx is the ctx argument value.
Ctx context.Context
}
}
lockAddInvoice sync.RWMutex
lockDescribeGraph sync.RWMutex
lockForwardingHistory sync.RWMutex
lockGetChannel sync.RWMutex
lockGetInfo sync.RWMutex
lockListChannels sync.RWMutex
lockSendPayment sync.RWMutex
lockSetFees sync.RWMutex
lockSubscribeChannelUpdates sync.RWMutex
}
// AddInvoice calls AddInvoiceFunc.
func (mock *lightningerMock) AddInvoice(ctx context.Context, amount lightning.Satoshi) (lightning.Invoice, error) {
callInfo := struct {
Ctx context.Context
Amount lightning.Satoshi
}{
Ctx: ctx,
Amount: amount,
}
mock.lockAddInvoice.Lock()
mock.calls.AddInvoice = append(mock.calls.AddInvoice, callInfo)
mock.lockAddInvoice.Unlock()
if mock.AddInvoiceFunc == nil {
var (
invoiceOut lightning.Invoice
errOut error
)
return invoiceOut, errOut
}
return mock.AddInvoiceFunc(ctx, amount)
}
// AddInvoiceCalls gets all the calls that were made to AddInvoice.
// Check the length with:
//
// len(mockedlightninger.AddInvoiceCalls())
func (mock *lightningerMock) AddInvoiceCalls() []struct {
Ctx context.Context
Amount lightning.Satoshi
} {
var calls []struct {
Ctx context.Context
Amount lightning.Satoshi
}
mock.lockAddInvoice.RLock()
calls = mock.calls.AddInvoice
mock.lockAddInvoice.RUnlock()
return calls
}
// DescribeGraph calls DescribeGraphFunc.
func (mock *lightningerMock) DescribeGraph(ctx context.Context) (*lightning.Graph, error) {
callInfo := struct {
Ctx context.Context
}{
Ctx: ctx,
}
mock.lockDescribeGraph.Lock()
mock.calls.DescribeGraph = append(mock.calls.DescribeGraph, callInfo)
mock.lockDescribeGraph.Unlock()
if mock.DescribeGraphFunc == nil {
var (
graphOut *lightning.Graph
errOut error
)
return graphOut, errOut
}
return mock.DescribeGraphFunc(ctx)
}
// DescribeGraphCalls gets all the calls that were made to DescribeGraph.
// Check the length with:
//
// len(mockedlightninger.DescribeGraphCalls())
func (mock *lightningerMock) DescribeGraphCalls() []struct {
Ctx context.Context
} {
var calls []struct {
Ctx context.Context
}
mock.lockDescribeGraph.RLock()
calls = mock.calls.DescribeGraph
mock.lockDescribeGraph.RUnlock()
return calls
}
// ForwardingHistory calls ForwardingHistoryFunc.
func (mock *lightningerMock) ForwardingHistory(ctx context.Context, since time.Time) ([]lightning.Forward, error) {
callInfo := struct {
Ctx context.Context
Since time.Time
}{
Ctx: ctx,
Since: since,
}
mock.lockForwardingHistory.Lock()
mock.calls.ForwardingHistory = append(mock.calls.ForwardingHistory, callInfo)
mock.lockForwardingHistory.Unlock()
if mock.ForwardingHistoryFunc == nil {
var (
forwardsOut []lightning.Forward
errOut error
)
return forwardsOut, errOut
}
return mock.ForwardingHistoryFunc(ctx, since)
}
// ForwardingHistoryCalls gets all the calls that were made to ForwardingHistory.
// Check the length with:
//
// len(mockedlightninger.ForwardingHistoryCalls())
func (mock *lightningerMock) ForwardingHistoryCalls() []struct {
Ctx context.Context
Since time.Time
} {
var calls []struct {
Ctx context.Context
Since time.Time
}
mock.lockForwardingHistory.RLock()
calls = mock.calls.ForwardingHistory
mock.lockForwardingHistory.RUnlock()
return calls
}
// GetChannel calls GetChannelFunc.
func (mock *lightningerMock) GetChannel(ctx context.Context, channelID lightning.ChannelID) (lightning.Channel, error) {
callInfo := struct {
Ctx context.Context
ChannelID lightning.ChannelID
}{
Ctx: ctx,
ChannelID: channelID,
}
mock.lockGetChannel.Lock()
mock.calls.GetChannel = append(mock.calls.GetChannel, callInfo)
mock.lockGetChannel.Unlock()
if mock.GetChannelFunc == nil {
var (
channelOut lightning.Channel
errOut error
)
return channelOut, errOut
}
return mock.GetChannelFunc(ctx, channelID)
}
// GetChannelCalls gets all the calls that were made to GetChannel.
// Check the length with:
//
// len(mockedlightninger.GetChannelCalls())
func (mock *lightningerMock) GetChannelCalls() []struct {
Ctx context.Context
ChannelID lightning.ChannelID
} {
var calls []struct {
Ctx context.Context
ChannelID lightning.ChannelID
}
mock.lockGetChannel.RLock()
calls = mock.calls.GetChannel
mock.lockGetChannel.RUnlock()
return calls
}
// GetInfo calls GetInfoFunc.
func (mock *lightningerMock) GetInfo(ctx context.Context) (*lightning.Info, error) {
callInfo := struct {
Ctx context.Context
}{
Ctx: ctx,
}
mock.lockGetInfo.Lock()
mock.calls.GetInfo = append(mock.calls.GetInfo, callInfo)
mock.lockGetInfo.Unlock()
if mock.GetInfoFunc == nil {
var (
infoOut *lightning.Info
errOut error
)
return infoOut, errOut
}
return mock.GetInfoFunc(ctx)
}
// GetInfoCalls gets all the calls that were made to GetInfo.
// Check the length with:
//
// len(mockedlightninger.GetInfoCalls())
func (mock *lightningerMock) GetInfoCalls() []struct {
Ctx context.Context
} {
var calls []struct {
Ctx context.Context
}
mock.lockGetInfo.RLock()
calls = mock.calls.GetInfo
mock.lockGetInfo.RUnlock()
return calls
}
// ListChannels calls ListChannelsFunc.
func (mock *lightningerMock) ListChannels(ctx context.Context) (lightning.Channels, error) {
callInfo := struct {
Ctx context.Context
}{
Ctx: ctx,
}
mock.lockListChannels.Lock()
mock.calls.ListChannels = append(mock.calls.ListChannels, callInfo)
mock.lockListChannels.Unlock()
if mock.ListChannelsFunc == nil {
var (
channelsOut lightning.Channels
errOut error
)
return channelsOut, errOut
}
return mock.ListChannelsFunc(ctx)
}
// ListChannelsCalls gets all the calls that were made to ListChannels.
// Check the length with:
//
// len(mockedlightninger.ListChannelsCalls())
func (mock *lightningerMock) ListChannelsCalls() []struct {
Ctx context.Context
} {
var calls []struct {
Ctx context.Context
}
mock.lockListChannels.RLock()
calls = mock.calls.ListChannels
mock.lockListChannels.RUnlock()
return calls
}
// SendPayment calls SendPaymentFunc.
func (mock *lightningerMock) SendPayment(ctx context.Context, invoice lightning.Invoice, outChannelID lightning.ChannelID, lastHopPubKey lightning.PubKey, maxFee lightning.FeePPM) (lightning.Satoshi, error) {
callInfo := struct {
Ctx context.Context
Invoice lightning.Invoice
OutChannelID lightning.ChannelID
LastHopPubKey lightning.PubKey
MaxFee lightning.FeePPM
}{
Ctx: ctx,
Invoice: invoice,
OutChannelID: outChannelID,
LastHopPubKey: lastHopPubKey,
MaxFee: maxFee,
}
mock.lockSendPayment.Lock()
mock.calls.SendPayment = append(mock.calls.SendPayment, callInfo)
mock.lockSendPayment.Unlock()
if mock.SendPaymentFunc == nil {
var (
satoshiOut lightning.Satoshi
errOut error
)
return satoshiOut, errOut
}
return mock.SendPaymentFunc(ctx, invoice, outChannelID, lastHopPubKey, maxFee)
}
// SendPaymentCalls gets all the calls that were made to SendPayment.
// Check the length with:
//
// len(mockedlightninger.SendPaymentCalls())
func (mock *lightningerMock) SendPaymentCalls() []struct {
Ctx context.Context
Invoice lightning.Invoice
OutChannelID lightning.ChannelID
LastHopPubKey lightning.PubKey
MaxFee lightning.FeePPM
} {
var calls []struct {
Ctx context.Context
Invoice lightning.Invoice
OutChannelID lightning.ChannelID
LastHopPubKey lightning.PubKey
MaxFee lightning.FeePPM
}
mock.lockSendPayment.RLock()
calls = mock.calls.SendPayment
mock.lockSendPayment.RUnlock()
return calls
}
// SetFees calls SetFeesFunc.
func (mock *lightningerMock) SetFees(ctx context.Context, channelID lightning.ChannelID, fee lightning.FeePPM, maxHTLC lightning.MilliSatoshi) error {
callInfo := struct {
Ctx context.Context
ChannelID lightning.ChannelID
Fee lightning.FeePPM
MaxHTLC lightning.MilliSatoshi
}{
Ctx: ctx,
ChannelID: channelID,
Fee: fee,
MaxHTLC: maxHTLC,
}
mock.lockSetFees.Lock()
mock.calls.SetFees = append(mock.calls.SetFees, callInfo)
mock.lockSetFees.Unlock()
if mock.SetFeesFunc == nil {
var (
errOut error
)
return errOut
}
return mock.SetFeesFunc(ctx, channelID, fee, maxHTLC)
}
// SetFeesCalls gets all the calls that were made to SetFees.
// Check the length with:
//
// len(mockedlightninger.SetFeesCalls())
func (mock *lightningerMock) SetFeesCalls() []struct {
Ctx context.Context
ChannelID lightning.ChannelID
Fee lightning.FeePPM
MaxHTLC lightning.MilliSatoshi
} {
var calls []struct {
Ctx context.Context
ChannelID lightning.ChannelID
Fee lightning.FeePPM
MaxHTLC lightning.MilliSatoshi
}
mock.lockSetFees.RLock()
calls = mock.calls.SetFees
mock.lockSetFees.RUnlock()
return calls
}
// SubscribeChannelUpdates calls SubscribeChannelUpdatesFunc.
func (mock *lightningerMock) SubscribeChannelUpdates(ctx context.Context) (<-chan lightning.Channels, <-chan error, error) {
callInfo := struct {
Ctx context.Context
}{
Ctx: ctx,
}
mock.lockSubscribeChannelUpdates.Lock()
mock.calls.SubscribeChannelUpdates = append(mock.calls.SubscribeChannelUpdates, callInfo)
mock.lockSubscribeChannelUpdates.Unlock()
if mock.SubscribeChannelUpdatesFunc == nil {
var (
channelsChOut <-chan lightning.Channels
errChOut <-chan error
errOut error
)
return channelsChOut, errChOut, errOut
}
return mock.SubscribeChannelUpdatesFunc(ctx)
}
// SubscribeChannelUpdatesCalls gets all the calls that were made to SubscribeChannelUpdates.
// Check the length with:
//
// len(mockedlightninger.SubscribeChannelUpdatesCalls())
func (mock *lightningerMock) SubscribeChannelUpdatesCalls() []struct {
Ctx context.Context
} {
var calls []struct {
Ctx context.Context
}
mock.lockSubscribeChannelUpdates.RLock()
calls = mock.calls.SubscribeChannelUpdates
mock.lockSubscribeChannelUpdates.RUnlock()
return calls
}