Skip to content

Commit 4ff5923

Browse files
committedJul 29, 2015
Merge pull request #1524 from ipfs/fix/coremock
set identity on core mock to fix ipns tests
2 parents 9e4d6e1 + 5513aab commit 4ff5923

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed
 

‎core/core.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ func NewIPFSNode(ctx context.Context, option ConfigOption) (*IpfsNode, error) {
130130
return nil, err
131131
}
132132

133-
node.proc = goprocessctx.WithContextAndTeardown(ctx, node.teardown)
134-
node.ctx = ctx
133+
if node.ctx == nil {
134+
node.ctx = ctx
135+
}
136+
if node.proc == nil {
137+
node.proc = goprocessctx.WithContextAndTeardown(node.ctx, node.teardown)
138+
}
135139

136140
success := false // flip to true after all sub-system inits succeed
137141
defer func() {
@@ -217,6 +221,9 @@ func standardWithRouting(r repo.Repo, online bool, routingOption RoutingOption,
217221
Repo: r,
218222
}
219223

224+
n.ctx = ctx
225+
n.proc = goprocessctx.WithContextAndTeardown(ctx, n.teardown)
226+
220227
// setup Peerstore
221228
n.Peerstore = peer.NewPeerstore()
222229

‎core/mock/mock.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
55
syncds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
66
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
7+
78
"github.com/ipfs/go-ipfs/blocks/blockstore"
89
blockservice "github.com/ipfs/go-ipfs/blockservice"
910
commands "github.com/ipfs/go-ipfs/commands"
@@ -24,7 +25,7 @@ import (
2425

2526
// TODO this is super sketch. Deprecate and initialize one that shares code
2627
// with the actual core constructor. Lots of fields aren't initialized.
27-
// Additionally, the context group isn't wired up. This is as good as broken.
28+
// "This is as good as broken." --- is it?
2829

2930
// NewMockNode constructs an IpfsNode for use in tests.
3031
func NewMockNode() (*core.IpfsNode, error) {
@@ -55,8 +56,9 @@ func NewMockNode() (*core.IpfsNode, error) {
5556
nd.Peerstore = peer.NewPeerstore()
5657
nd.Peerstore.AddPrivKey(p, ident.PrivateKey())
5758
nd.Peerstore.AddPubKey(p, ident.PublicKey())
59+
nd.Identity = p
5860

59-
nd.PeerHost, err = mocknet.New(ctx).AddPeer(ident.PrivateKey(), ident.Address()) // effectively offline
61+
nd.PeerHost, err = mocknet.New(nd.Context()).AddPeer(ident.PrivateKey(), ident.Address()) // effectively offline
6062
if err != nil {
6163
return nil, err
6264
}

0 commit comments

Comments
 (0)
Please sign in to comment.