From 07fa9eecbde9c30cf1d5a62f561ef35ccfb57b3f Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Thu, 25 Dec 2014 15:19:54 -0500 Subject: [PATCH] hotfix(core/mock) set Network field --- core/mock.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/mock.go b/core/mock.go index cd47875c9..a0ce6a460 100644 --- a/core/mock.go +++ b/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}