-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Table.go
591 lines (483 loc) · 16.7 KB
/
Table.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
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
// Code generated by mockery v2.40.1. DO NOT EDIT.
package ktable_mocks
import (
ktable "github.com/bitmagnet-io/bitmagnet/internal/protocol/dht/ktable"
btree "github.com/bitmagnet-io/bitmagnet/internal/protocol/dht/ktable/btree"
mock "github.com/stretchr/testify/mock"
netip "net/netip"
protocol "github.com/bitmagnet-io/bitmagnet/internal/protocol"
time "time"
)
// Table is an autogenerated mock type for the Table type
type Table struct {
mock.Mock
}
type Table_Expecter struct {
mock *mock.Mock
}
func (_m *Table) EXPECT() *Table_Expecter {
return &Table_Expecter{mock: &_m.Mock}
}
// BatchCommand provides a mock function with given fields: commands
func (_m *Table) BatchCommand(commands ...ktable.Command) {
_va := make([]interface{}, len(commands))
for _i := range commands {
_va[_i] = commands[_i]
}
var _ca []interface{}
_ca = append(_ca, _va...)
_m.Called(_ca...)
}
// Table_BatchCommand_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchCommand'
type Table_BatchCommand_Call struct {
*mock.Call
}
// BatchCommand is a helper method to define mock.On call
// - commands ...ktable.Command
func (_e *Table_Expecter) BatchCommand(commands ...interface{}) *Table_BatchCommand_Call {
return &Table_BatchCommand_Call{Call: _e.mock.On("BatchCommand",
append([]interface{}{}, commands...)...)}
}
func (_c *Table_BatchCommand_Call) Run(run func(commands ...ktable.Command)) *Table_BatchCommand_Call {
_c.Call.Run(func(args mock.Arguments) {
variadicArgs := make([]ktable.Command, len(args)-0)
for i, a := range args[0:] {
if a != nil {
variadicArgs[i] = a.(ktable.Command)
}
}
run(variadicArgs...)
})
return _c
}
func (_c *Table_BatchCommand_Call) Return() *Table_BatchCommand_Call {
_c.Call.Return()
return _c
}
func (_c *Table_BatchCommand_Call) RunAndReturn(run func(...ktable.Command)) *Table_BatchCommand_Call {
_c.Call.Return(run)
return _c
}
// DropNode provides a mock function with given fields: id, reason
func (_m *Table) DropNode(id protocol.ID, reason error) bool {
ret := _m.Called(id, reason)
if len(ret) == 0 {
panic("no return value specified for DropNode")
}
var r0 bool
if rf, ok := ret.Get(0).(func(protocol.ID, error) bool); ok {
r0 = rf(id, reason)
} else {
r0 = ret.Get(0).(bool)
}
return r0
}
// Table_DropNode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DropNode'
type Table_DropNode_Call struct {
*mock.Call
}
// DropNode is a helper method to define mock.On call
// - id protocol.ID
// - reason error
func (_e *Table_Expecter) DropNode(id interface{}, reason interface{}) *Table_DropNode_Call {
return &Table_DropNode_Call{Call: _e.mock.On("DropNode", id, reason)}
}
func (_c *Table_DropNode_Call) Run(run func(id protocol.ID, reason error)) *Table_DropNode_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(protocol.ID), args[1].(error))
})
return _c
}
func (_c *Table_DropNode_Call) Return(_a0 bool) *Table_DropNode_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_DropNode_Call) RunAndReturn(run func(protocol.ID, error) bool) *Table_DropNode_Call {
_c.Call.Return(run)
return _c
}
// FilterKnownAddrs provides a mock function with given fields: addrs
func (_m *Table) FilterKnownAddrs(addrs []netip.Addr) []netip.Addr {
ret := _m.Called(addrs)
if len(ret) == 0 {
panic("no return value specified for FilterKnownAddrs")
}
var r0 []netip.Addr
if rf, ok := ret.Get(0).(func([]netip.Addr) []netip.Addr); ok {
r0 = rf(addrs)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]netip.Addr)
}
}
return r0
}
// Table_FilterKnownAddrs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FilterKnownAddrs'
type Table_FilterKnownAddrs_Call struct {
*mock.Call
}
// FilterKnownAddrs is a helper method to define mock.On call
// - addrs []netip.Addr
func (_e *Table_Expecter) FilterKnownAddrs(addrs interface{}) *Table_FilterKnownAddrs_Call {
return &Table_FilterKnownAddrs_Call{Call: _e.mock.On("FilterKnownAddrs", addrs)}
}
func (_c *Table_FilterKnownAddrs_Call) Run(run func(addrs []netip.Addr)) *Table_FilterKnownAddrs_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].([]netip.Addr))
})
return _c
}
func (_c *Table_FilterKnownAddrs_Call) Return(_a0 []netip.Addr) *Table_FilterKnownAddrs_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_FilterKnownAddrs_Call) RunAndReturn(run func([]netip.Addr) []netip.Addr) *Table_FilterKnownAddrs_Call {
_c.Call.Return(run)
return _c
}
// GetClosestNodes provides a mock function with given fields: id
func (_m *Table) GetClosestNodes(id protocol.ID) []ktable.Node {
ret := _m.Called(id)
if len(ret) == 0 {
panic("no return value specified for GetClosestNodes")
}
var r0 []ktable.Node
if rf, ok := ret.Get(0).(func(protocol.ID) []ktable.Node); ok {
r0 = rf(id)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]ktable.Node)
}
}
return r0
}
// Table_GetClosestNodes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetClosestNodes'
type Table_GetClosestNodes_Call struct {
*mock.Call
}
// GetClosestNodes is a helper method to define mock.On call
// - id protocol.ID
func (_e *Table_Expecter) GetClosestNodes(id interface{}) *Table_GetClosestNodes_Call {
return &Table_GetClosestNodes_Call{Call: _e.mock.On("GetClosestNodes", id)}
}
func (_c *Table_GetClosestNodes_Call) Run(run func(id protocol.ID)) *Table_GetClosestNodes_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(protocol.ID))
})
return _c
}
func (_c *Table_GetClosestNodes_Call) Return(_a0 []ktable.Node) *Table_GetClosestNodes_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_GetClosestNodes_Call) RunAndReturn(run func(protocol.ID) []ktable.Node) *Table_GetClosestNodes_Call {
_c.Call.Return(run)
return _c
}
// GetHashOrClosestNodes provides a mock function with given fields: id
func (_m *Table) GetHashOrClosestNodes(id protocol.ID) ktable.GetHashOrClosestNodesResult {
ret := _m.Called(id)
if len(ret) == 0 {
panic("no return value specified for GetHashOrClosestNodes")
}
var r0 ktable.GetHashOrClosestNodesResult
if rf, ok := ret.Get(0).(func(protocol.ID) ktable.GetHashOrClosestNodesResult); ok {
r0 = rf(id)
} else {
r0 = ret.Get(0).(ktable.GetHashOrClosestNodesResult)
}
return r0
}
// Table_GetHashOrClosestNodes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetHashOrClosestNodes'
type Table_GetHashOrClosestNodes_Call struct {
*mock.Call
}
// GetHashOrClosestNodes is a helper method to define mock.On call
// - id protocol.ID
func (_e *Table_Expecter) GetHashOrClosestNodes(id interface{}) *Table_GetHashOrClosestNodes_Call {
return &Table_GetHashOrClosestNodes_Call{Call: _e.mock.On("GetHashOrClosestNodes", id)}
}
func (_c *Table_GetHashOrClosestNodes_Call) Run(run func(id protocol.ID)) *Table_GetHashOrClosestNodes_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(protocol.ID))
})
return _c
}
func (_c *Table_GetHashOrClosestNodes_Call) Return(_a0 ktable.GetHashOrClosestNodesResult) *Table_GetHashOrClosestNodes_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_GetHashOrClosestNodes_Call) RunAndReturn(run func(protocol.ID) ktable.GetHashOrClosestNodesResult) *Table_GetHashOrClosestNodes_Call {
_c.Call.Return(run)
return _c
}
// GetNodesForSampleInfoHashes provides a mock function with given fields: n
func (_m *Table) GetNodesForSampleInfoHashes(n int) []ktable.Node {
ret := _m.Called(n)
if len(ret) == 0 {
panic("no return value specified for GetNodesForSampleInfoHashes")
}
var r0 []ktable.Node
if rf, ok := ret.Get(0).(func(int) []ktable.Node); ok {
r0 = rf(n)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]ktable.Node)
}
}
return r0
}
// Table_GetNodesForSampleInfoHashes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetNodesForSampleInfoHashes'
type Table_GetNodesForSampleInfoHashes_Call struct {
*mock.Call
}
// GetNodesForSampleInfoHashes is a helper method to define mock.On call
// - n int
func (_e *Table_Expecter) GetNodesForSampleInfoHashes(n interface{}) *Table_GetNodesForSampleInfoHashes_Call {
return &Table_GetNodesForSampleInfoHashes_Call{Call: _e.mock.On("GetNodesForSampleInfoHashes", n)}
}
func (_c *Table_GetNodesForSampleInfoHashes_Call) Run(run func(n int)) *Table_GetNodesForSampleInfoHashes_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(int))
})
return _c
}
func (_c *Table_GetNodesForSampleInfoHashes_Call) Return(_a0 []ktable.Node) *Table_GetNodesForSampleInfoHashes_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_GetNodesForSampleInfoHashes_Call) RunAndReturn(run func(int) []ktable.Node) *Table_GetNodesForSampleInfoHashes_Call {
_c.Call.Return(run)
return _c
}
// GetOldestNodes provides a mock function with given fields: cutoff, n
func (_m *Table) GetOldestNodes(cutoff time.Time, n int) []ktable.Node {
ret := _m.Called(cutoff, n)
if len(ret) == 0 {
panic("no return value specified for GetOldestNodes")
}
var r0 []ktable.Node
if rf, ok := ret.Get(0).(func(time.Time, int) []ktable.Node); ok {
r0 = rf(cutoff, n)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]ktable.Node)
}
}
return r0
}
// Table_GetOldestNodes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetOldestNodes'
type Table_GetOldestNodes_Call struct {
*mock.Call
}
// GetOldestNodes is a helper method to define mock.On call
// - cutoff time.Time
// - n int
func (_e *Table_Expecter) GetOldestNodes(cutoff interface{}, n interface{}) *Table_GetOldestNodes_Call {
return &Table_GetOldestNodes_Call{Call: _e.mock.On("GetOldestNodes", cutoff, n)}
}
func (_c *Table_GetOldestNodes_Call) Run(run func(cutoff time.Time, n int)) *Table_GetOldestNodes_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(time.Time), args[1].(int))
})
return _c
}
func (_c *Table_GetOldestNodes_Call) Return(_a0 []ktable.Node) *Table_GetOldestNodes_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_GetOldestNodes_Call) RunAndReturn(run func(time.Time, int) []ktable.Node) *Table_GetOldestNodes_Call {
_c.Call.Return(run)
return _c
}
// Origin provides a mock function with given fields:
func (_m *Table) Origin() protocol.ID {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Origin")
}
var r0 protocol.ID
if rf, ok := ret.Get(0).(func() protocol.ID); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(protocol.ID)
}
}
return r0
}
// Table_Origin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Origin'
type Table_Origin_Call struct {
*mock.Call
}
// Origin is a helper method to define mock.On call
func (_e *Table_Expecter) Origin() *Table_Origin_Call {
return &Table_Origin_Call{Call: _e.mock.On("Origin")}
}
func (_c *Table_Origin_Call) Run(run func()) *Table_Origin_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *Table_Origin_Call) Return(_a0 protocol.ID) *Table_Origin_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_Origin_Call) RunAndReturn(run func() protocol.ID) *Table_Origin_Call {
_c.Call.Return(run)
return _c
}
// PutHash provides a mock function with given fields: id, peers, options
func (_m *Table) PutHash(id protocol.ID, peers []ktable.HashPeer, options ...ktable.HashOption) btree.PutResult {
_va := make([]interface{}, len(options))
for _i := range options {
_va[_i] = options[_i]
}
var _ca []interface{}
_ca = append(_ca, id, peers)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
if len(ret) == 0 {
panic("no return value specified for PutHash")
}
var r0 btree.PutResult
if rf, ok := ret.Get(0).(func(protocol.ID, []ktable.HashPeer, ...ktable.HashOption) btree.PutResult); ok {
r0 = rf(id, peers, options...)
} else {
r0 = ret.Get(0).(btree.PutResult)
}
return r0
}
// Table_PutHash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PutHash'
type Table_PutHash_Call struct {
*mock.Call
}
// PutHash is a helper method to define mock.On call
// - id protocol.ID
// - peers []ktable.HashPeer
// - options ...ktable.HashOption
func (_e *Table_Expecter) PutHash(id interface{}, peers interface{}, options ...interface{}) *Table_PutHash_Call {
return &Table_PutHash_Call{Call: _e.mock.On("PutHash",
append([]interface{}{id, peers}, options...)...)}
}
func (_c *Table_PutHash_Call) Run(run func(id protocol.ID, peers []ktable.HashPeer, options ...ktable.HashOption)) *Table_PutHash_Call {
_c.Call.Run(func(args mock.Arguments) {
variadicArgs := make([]ktable.HashOption, len(args)-2)
for i, a := range args[2:] {
if a != nil {
variadicArgs[i] = a.(ktable.HashOption)
}
}
run(args[0].(protocol.ID), args[1].([]ktable.HashPeer), variadicArgs...)
})
return _c
}
func (_c *Table_PutHash_Call) Return(_a0 btree.PutResult) *Table_PutHash_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_PutHash_Call) RunAndReturn(run func(protocol.ID, []ktable.HashPeer, ...ktable.HashOption) btree.PutResult) *Table_PutHash_Call {
_c.Call.Return(run)
return _c
}
// PutNode provides a mock function with given fields: id, addr, options
func (_m *Table) PutNode(id protocol.ID, addr netip.AddrPort, options ...ktable.NodeOption) btree.PutResult {
_va := make([]interface{}, len(options))
for _i := range options {
_va[_i] = options[_i]
}
var _ca []interface{}
_ca = append(_ca, id, addr)
_ca = append(_ca, _va...)
ret := _m.Called(_ca...)
if len(ret) == 0 {
panic("no return value specified for PutNode")
}
var r0 btree.PutResult
if rf, ok := ret.Get(0).(func(protocol.ID, netip.AddrPort, ...ktable.NodeOption) btree.PutResult); ok {
r0 = rf(id, addr, options...)
} else {
r0 = ret.Get(0).(btree.PutResult)
}
return r0
}
// Table_PutNode_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PutNode'
type Table_PutNode_Call struct {
*mock.Call
}
// PutNode is a helper method to define mock.On call
// - id protocol.ID
// - addr netip.AddrPort
// - options ...ktable.NodeOption
func (_e *Table_Expecter) PutNode(id interface{}, addr interface{}, options ...interface{}) *Table_PutNode_Call {
return &Table_PutNode_Call{Call: _e.mock.On("PutNode",
append([]interface{}{id, addr}, options...)...)}
}
func (_c *Table_PutNode_Call) Run(run func(id protocol.ID, addr netip.AddrPort, options ...ktable.NodeOption)) *Table_PutNode_Call {
_c.Call.Run(func(args mock.Arguments) {
variadicArgs := make([]ktable.NodeOption, len(args)-2)
for i, a := range args[2:] {
if a != nil {
variadicArgs[i] = a.(ktable.NodeOption)
}
}
run(args[0].(protocol.ID), args[1].(netip.AddrPort), variadicArgs...)
})
return _c
}
func (_c *Table_PutNode_Call) Return(_a0 btree.PutResult) *Table_PutNode_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_PutNode_Call) RunAndReturn(run func(protocol.ID, netip.AddrPort, ...ktable.NodeOption) btree.PutResult) *Table_PutNode_Call {
_c.Call.Return(run)
return _c
}
// SampleHashesAndNodes provides a mock function with given fields:
func (_m *Table) SampleHashesAndNodes() ktable.SampleHashesAndNodesResult {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for SampleHashesAndNodes")
}
var r0 ktable.SampleHashesAndNodesResult
if rf, ok := ret.Get(0).(func() ktable.SampleHashesAndNodesResult); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(ktable.SampleHashesAndNodesResult)
}
return r0
}
// Table_SampleHashesAndNodes_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SampleHashesAndNodes'
type Table_SampleHashesAndNodes_Call struct {
*mock.Call
}
// SampleHashesAndNodes is a helper method to define mock.On call
func (_e *Table_Expecter) SampleHashesAndNodes() *Table_SampleHashesAndNodes_Call {
return &Table_SampleHashesAndNodes_Call{Call: _e.mock.On("SampleHashesAndNodes")}
}
func (_c *Table_SampleHashesAndNodes_Call) Run(run func()) *Table_SampleHashesAndNodes_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *Table_SampleHashesAndNodes_Call) Return(_a0 ktable.SampleHashesAndNodesResult) *Table_SampleHashesAndNodes_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *Table_SampleHashesAndNodes_Call) RunAndReturn(run func() ktable.SampleHashesAndNodesResult) *Table_SampleHashesAndNodes_Call {
_c.Call.Return(run)
return _c
}
// NewTable creates a new instance of Table. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewTable(t interface {
mock.TestingT
Cleanup(func())
}) *Table {
mock := &Table{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}