-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock.go
31 lines (26 loc) · 769 Bytes
/
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
package bstest
import (
. "github.com/ipfs/go-ipfs/blockservice"
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
)
type fataler interface {
Fatal(args ...interface{})
}
// Mocks returns |n| connected mock Blockservices
func Mocks(t fataler, n int) []*BlockService {
net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
sg := bitswap.NewTestSessionGenerator(net)
instances := sg.Instances(n)
var servs []*BlockService
for _, i := range instances {
bserv, err := New(i.Blockstore(), i.Exchange)
if err != nil {
t.Fatal(err)
}
servs = append(servs, bserv)
}
return servs
}