hotfix(core/mock) set Network field
Brian Tiger Chow committed
Dec 25, 2014 at 15:19 UTC
07fa9eecbde9c30cf1d5a62f561ef35ccfb57b3f
1 file changed
+13
-3
core/mock.go
+13
-3
@@ -10,12 +10,18 @@ import (
10
"github.com/jbenet/go-ipfs/exchange/offline"
11
mdag "github.com/jbenet/go-ipfs/merkledag"
12
nsys "github.com/jbenet/go-ipfs/namesys"
13
+ "github.com/jbenet/go-ipfs/net/mock"
14
path "github.com/jbenet/go-ipfs/path"
15
peer "github.com/jbenet/go-ipfs/peer"
16
dht "github.com/jbenet/go-ipfs/routing/dht"
17
ds2 "github.com/jbenet/go-ipfs/util/datastore2"
18
+ "github.com/jbenet/go-ipfs/util/testutil"
19
)
20
21
+// TODO this is super sketch. Deprecate and initialize one that shares code
22
+// with the actual core constructor. Lots of fields aren't initialized.
23
+// Additionally, the context group isn't wired up. This is as good as broken.
24
+
25
// NewMockNode constructs an IpfsNode for use in tests.
26
func NewMockNode() (*IpfsNode, error) {
27
ctx := context.TODO()
@@ -37,13 +43,17 @@ func NewMockNode() (*IpfsNode, error) {
43
nd.Peerstore = peer.NewPeerstore()
44
nd.Peerstore.AddPrivKey(p, sk)
45
nd.Peerstore.AddPubKey(p, pk)
40
-
46
+ nd.Network, err = mocknet.New(ctx).AddPeer(sk, testutil.RandLocalTCPAddress()) // effectively offline
47
+ if err != nil {
48
+ return nil, err
49
+ }
50
// Temp Datastore
51
dstore := ds.NewMapDatastore()
52
nd.Datastore = ds2.CloserWrap(syncds.MutexWrap(dstore))
53
54
// Routing
46
- nd.Routing = dht.NewDHT(ctx, nd.Identity, nd.Network, nd.Datastore)
55
+ dht := dht.NewDHT(ctx, nd.Identity, nd.Network, nd.Datastore)
56
+ nd.Routing = dht
57
58
// Bitswap
59
bstore := blockstore.NewBlockstore(nd.Datastore)
@@ -55,7 +65,7 @@ func NewMockNode() (*IpfsNode, error) {
65
nd.DAG = mdag.NewDAGService(bserv)
66
67
// Namespace resolver
58
- nd.Namesys = nsys.NewNameSystem(nd.Routing)
68
+ nd.Namesys = nsys.NewNameSystem(dht)
69
70
// Path resolver
71
nd.Resolver = &path.Resolver{DAG: nd.DAG}