refactor: use the Core in the integration test
Brian Tiger Chow committed
Jan 10, 2015 at 19:48 UTC
85401d53fd832e644de93dccf625e98f9be1a1c4
3 files changed
+35
-40
test/epictest/addcat_test.go
+2
-2
@@ -109,8 +109,8 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
109
return err
110
}
111
112
- adder.Bootstrap(ctx, catter.ID())
113
- catter.Bootstrap(ctx, adder.ID())
112
+ adder.Bootstrap(ctx, catter.Peerstore.PeerInfo(catter.PeerHost.ID()))
113
+ catter.Bootstrap(ctx, adder.Peerstore.PeerInfo(adder.PeerHost.ID()))
114
115
keyAdded, err := adder.Add(bytes.NewReader(data))
116
if err != nil {
test/epictest/core.go
+30
-35
@@ -9,7 +9,7 @@ import (
9
10
blockstore "github.com/jbenet/go-ipfs/blocks/blockstore"
11
blockservice "github.com/jbenet/go-ipfs/blockservice"
12
- testutil "github.com/jbenet/go-ipfs/util/testutil"
12
+ core "github.com/jbenet/go-ipfs/core"
13
exchange "github.com/jbenet/go-ipfs/exchange"
14
bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
15
bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
@@ -25,30 +25,26 @@ import (
25
"github.com/jbenet/go-ipfs/util/datastore2"
26
delay "github.com/jbenet/go-ipfs/util/delay"
27
eventlog "github.com/jbenet/go-ipfs/util/eventlog"
28
+ testutil "github.com/jbenet/go-ipfs/util/testutil"
29
)
30
31
var log = eventlog.Logger("epictest")
32
33
// TODO merge with core.IpfsNode
33
-type core struct {
34
- repo Repo
35
-
36
- blockService *blockservice.BlockService
37
- blockstore blockstore.Blockstore
38
- dag merkledag.DAGService
39
- id peer.ID
34
+type Core struct {
35
+ *core.IpfsNode
36
}
37
42
-func (c *core) ID() peer.ID {
43
- return c.repo.ID()
38
+func (c *Core) ID() peer.ID {
39
+ return c.IpfsNode.Identity
40
}
41
46
-func (c *core) Bootstrap(ctx context.Context, p peer.ID) error {
47
- return c.repo.Bootstrap(ctx, p)
42
+func (c *Core) Bootstrap(ctx context.Context, p peer.PeerInfo) error {
43
+ return c.IpfsNode.Bootstrap(ctx, []peer.PeerInfo{p})
44
}
45
50
-func (c *core) Cat(k util.Key) (io.Reader, error) {
51
- catterdag := c.dag
46
+func (c *Core) Cat(k util.Key) (io.Reader, error) {
47
+ catterdag := c.IpfsNode.DAG
48
nodeCatted, err := (&path.Resolver{catterdag}).ResolvePath(k.String())
49
if err != nil {
50
return nil, err
@@ -56,10 +52,10 @@ func (c *core) Cat(k util.Key) (io.Reader, error) {
52
return uio.NewDagReader(nodeCatted, catterdag)
53
}
54
59
-func (c *core) Add(r io.Reader) (util.Key, error) {
55
+func (c *Core) Add(r io.Reader) (util.Key, error) {
56
nodeAdded, err := importer.BuildDagFromReader(
57
r,
62
- c.dag,
58
+ c.IpfsNode.DAG,
59
nil,
60
chunk.DefaultSplitter,
61
)
@@ -69,28 +65,26 @@ func (c *core) Add(r io.Reader) (util.Key, error) {
65
return nodeAdded.Key()
66
}
67
72
-func makeCore(ctx context.Context, rf RepoFactory) (*core, error) {
73
- repo, err := rf(ctx)
68
+func makeCore(ctx context.Context, rf RepoFactory) (*Core, error) {
69
+ node, err := rf(ctx)
70
if err != nil {
71
return nil, err
72
}
73
78
- bss, err := blockservice.New(repo.Blockstore(), repo.Exchange())
74
+ node.Blocks, err = blockservice.New(node.Blockstore, node.Exchange)
75
if err != nil {
76
return nil, err
77
}
78
83
- dag := merkledag.NewDAGService(bss)
79
+ node.DAG = merkledag.NewDAGService(node.Blocks)
80
// to make sure nothing is omitted, init each individual field and assign
81
// all at once at the bottom.
86
- return &core{
87
- repo: repo,
88
- blockService: bss,
89
- dag: dag,
82
+ return &Core{
83
+ IpfsNode: node,
84
}, nil
85
}
86
93
-type RepoFactory func(ctx context.Context) (Repo, error)
87
+type RepoFactory func(ctx context.Context) (*core.IpfsNode, error)
88
89
type Repo interface {
90
ID() peer.ID
@@ -132,11 +126,11 @@ func (r *repo) Exchange() exchange.Interface {
126
}
127
128
func MocknetTestRepo(p peer.ID, h host.Host, conf testutil.LatencyConfig) RepoFactory {
135
- return func(ctx context.Context) (Repo, error) {
129
+ return func(ctx context.Context) (*core.IpfsNode, error) {
130
const kWriteCacheElems = 100
131
const alwaysSendToPeer = true
132
dsDelay := delay.Fixed(conf.BlockstoreLatency)
139
- ds := sync.MutexWrap(datastore2.WithDelay(datastore.NewMapDatastore(), dsDelay))
133
+ ds := datastore2.CloserWrap(sync.MutexWrap(datastore2.WithDelay(datastore.NewMapDatastore(), dsDelay)))
134
135
log.Debugf("MocknetTestRepo: %s %s %s", p, h.ID(), h)
136
dhtt := dht.NewDHT(ctx, h, ds)
@@ -146,14 +140,15 @@ func MocknetTestRepo(p peer.ID, h host.Host, conf testutil.LatencyConfig) RepoFa
140
return nil, err
141
}
142
exch := bitswap.New(ctx, p, bsn, bstore, alwaysSendToPeer)
149
- return &repo{
150
- bitSwapNetwork: bsn,
151
- blockstore: bstore,
152
- exchange: exch,
153
- datastore: ds,
154
- host: h,
155
- dht: dhtt,
156
- id: p,
143
+ return &core.IpfsNode{
144
+ Peerstore: h.Peerstore(),
145
+ Blockstore: bstore,
146
+ Exchange: exch,
147
+ Datastore: ds,
148
+ PeerHost: h,
149
+ Routing: dhtt,
150
+ Identity: p,
151
+ DHT: dhtt,
152
}, nil
153
}
154
}
test/epictest/three_legged_cat_test.go
+3
-3
@@ -55,9 +55,9 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
55
if err != nil {
56
return err
57
}
58
-
59
- adder.Bootstrap(ctx, bootstrap.ID())
60
- catter.Bootstrap(ctx, bootstrap.ID())
58
+ boostrapInfo := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID())
59
+ adder.Bootstrap(ctx, boostrapInfo)
60
+ catter.Bootstrap(ctx, boostrapInfo)
61
62
keyAdded, err := adder.Add(bytes.NewReader(data))
63
if err != nil {