mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 17:36:38 +08:00
hotfix(core/mock) set Network field
This commit is contained in:
16
core/mock.go
16
core/mock.go
@ -10,12 +10,18 @@ import (
|
||||
"github.com/jbenet/go-ipfs/exchange/offline"
|
||||
mdag "github.com/jbenet/go-ipfs/merkledag"
|
||||
nsys "github.com/jbenet/go-ipfs/namesys"
|
||||
"github.com/jbenet/go-ipfs/net/mock"
|
||||
path "github.com/jbenet/go-ipfs/path"
|
||||
peer "github.com/jbenet/go-ipfs/peer"
|
||||
dht "github.com/jbenet/go-ipfs/routing/dht"
|
||||
ds2 "github.com/jbenet/go-ipfs/util/datastore2"
|
||||
"github.com/jbenet/go-ipfs/util/testutil"
|
||||
)
|
||||
|
||||
// TODO this is super sketch. Deprecate and initialize one that shares code
|
||||
// with the actual core constructor. Lots of fields aren't initialized.
|
||||
// Additionally, the context group isn't wired up. This is as good as broken.
|
||||
|
||||
// NewMockNode constructs an IpfsNode for use in tests.
|
||||
func NewMockNode() (*IpfsNode, error) {
|
||||
ctx := context.TODO()
|
||||
@ -37,13 +43,17 @@ func NewMockNode() (*IpfsNode, error) {
|
||||
nd.Peerstore = peer.NewPeerstore()
|
||||
nd.Peerstore.AddPrivKey(p, sk)
|
||||
nd.Peerstore.AddPubKey(p, pk)
|
||||
|
||||
nd.Network, err = mocknet.New(ctx).AddPeer(sk, testutil.RandLocalTCPAddress()) // effectively offline
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Temp Datastore
|
||||
dstore := ds.NewMapDatastore()
|
||||
nd.Datastore = ds2.CloserWrap(syncds.MutexWrap(dstore))
|
||||
|
||||
// Routing
|
||||
nd.Routing = dht.NewDHT(ctx, nd.Identity, nd.Network, nd.Datastore)
|
||||
dht := dht.NewDHT(ctx, nd.Identity, nd.Network, nd.Datastore)
|
||||
nd.Routing = dht
|
||||
|
||||
// Bitswap
|
||||
bstore := blockstore.NewBlockstore(nd.Datastore)
|
||||
@ -55,7 +65,7 @@ func NewMockNode() (*IpfsNode, error) {
|
||||
nd.DAG = mdag.NewDAGService(bserv)
|
||||
|
||||
// Namespace resolver
|
||||
nd.Namesys = nsys.NewNameSystem(nd.Routing)
|
||||
nd.Namesys = nsys.NewNameSystem(dht)
|
||||
|
||||
// Path resolver
|
||||
nd.Resolver = &path.Resolver{DAG: nd.DAG}
|
||||
|
Reference in New Issue
Block a user