mock.go 694 Bytes
Newer Older
1 2 3 4 5 6 7
package blockservice

import (
	"testing"

	bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
	tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
Brian Tiger Chow's avatar
Brian Tiger Chow committed
8
	mockrouting "github.com/jbenet/go-ipfs/routing/mock"
9
	delay "github.com/jbenet/go-ipfs/util/delay"
10 11 12 13
)

// Mocks returns |n| connected mock Blockservices
func Mocks(t *testing.T, n int) []*BlockService {
14
	net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
15
	sg := bitswap.NewTestSessionGenerator(net)
16 17 18 19 20 21 22 23 24 25 26 27 28

	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
}