Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
85401d53
Commit
85401d53
authored
Jan 10, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: use the Core in the integration test
parent
2c3fb433
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
40 deletions
+35
-40
test/epictest/addcat_test.go
test/epictest/addcat_test.go
+2
-2
test/epictest/core.go
test/epictest/core.go
+30
-35
test/epictest/three_legged_cat_test.go
test/epictest/three_legged_cat_test.go
+3
-3
No files found.
test/epictest/addcat_test.go
View file @
85401d53
...
...
@@ -109,8 +109,8 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
return
err
}
adder
.
Bootstrap
(
ctx
,
catter
.
ID
())
catter
.
Bootstrap
(
ctx
,
adder
.
ID
())
adder
.
Bootstrap
(
ctx
,
catter
.
Peerstore
.
PeerInfo
(
catter
.
PeerHost
.
ID
())
)
catter
.
Bootstrap
(
ctx
,
adder
.
Peerstore
.
PeerInfo
(
adder
.
PeerHost
.
ID
())
)
keyAdded
,
err
:=
adder
.
Add
(
bytes
.
NewReader
(
data
))
if
err
!=
nil
{
...
...
test/epictest/core.go
View file @
85401d53
...
...
@@ -9,7 +9,7 @@ import (
blockstore
"github.com/jbenet/go-ipfs/blocks/blockstore"
blockservice
"github.com/jbenet/go-ipfs/blockservice"
testutil
"github.com/jbenet/go-ipfs/
util/testutil
"
core
"github.com/jbenet/go-ipfs/
core
"
exchange
"github.com/jbenet/go-ipfs/exchange"
bitswap
"github.com/jbenet/go-ipfs/exchange/bitswap"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
...
...
@@ -25,30 +25,26 @@ import (
"github.com/jbenet/go-ipfs/util/datastore2"
delay
"github.com/jbenet/go-ipfs/util/delay"
eventlog
"github.com/jbenet/go-ipfs/util/eventlog"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
var
log
=
eventlog
.
Logger
(
"epictest"
)
// TODO merge with core.IpfsNode
type
core
struct
{
repo
Repo
blockService
*
blockservice
.
BlockService
blockstore
blockstore
.
Blockstore
dag
merkledag
.
DAGService
id
peer
.
ID
type
Core
struct
{
*
core
.
IpfsNode
}
func
(
c
*
c
ore
)
ID
()
peer
.
ID
{
return
c
.
repo
.
ID
()
func
(
c
*
C
ore
)
ID
()
peer
.
ID
{
return
c
.
IpfsNode
.
Identity
}
func
(
c
*
c
ore
)
Bootstrap
(
ctx
context
.
Context
,
p
peer
.
ID
)
error
{
return
c
.
repo
.
Bootstrap
(
ctx
,
p
)
func
(
c
*
C
ore
)
Bootstrap
(
ctx
context
.
Context
,
p
peer
.
PeerInfo
)
error
{
return
c
.
IpfsNode
.
Bootstrap
(
ctx
,
[]
peer
.
PeerInfo
{
p
}
)
}
func
(
c
*
c
ore
)
Cat
(
k
util
.
Key
)
(
io
.
Reader
,
error
)
{
catterdag
:=
c
.
dag
func
(
c
*
C
ore
)
Cat
(
k
util
.
Key
)
(
io
.
Reader
,
error
)
{
catterdag
:=
c
.
IpfsNode
.
DAG
nodeCatted
,
err
:=
(
&
path
.
Resolver
{
catterdag
})
.
ResolvePath
(
k
.
String
())
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -56,10 +52,10 @@ func (c *core) Cat(k util.Key) (io.Reader, error) {
return
uio
.
NewDagReader
(
nodeCatted
,
catterdag
)
}
func
(
c
*
c
ore
)
Add
(
r
io
.
Reader
)
(
util
.
Key
,
error
)
{
func
(
c
*
C
ore
)
Add
(
r
io
.
Reader
)
(
util
.
Key
,
error
)
{
nodeAdded
,
err
:=
importer
.
BuildDagFromReader
(
r
,
c
.
dag
,
c
.
IpfsNode
.
DAG
,
nil
,
chunk
.
DefaultSplitter
,
)
...
...
@@ -69,28 +65,26 @@ func (c *core) Add(r io.Reader) (util.Key, error) {
return
nodeAdded
.
Key
()
}
func
makeCore
(
ctx
context
.
Context
,
rf
RepoFactory
)
(
*
c
ore
,
error
)
{
repo
,
err
:=
rf
(
ctx
)
func
makeCore
(
ctx
context
.
Context
,
rf
RepoFactory
)
(
*
C
ore
,
error
)
{
node
,
err
:=
rf
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
bs
s
,
err
:
=
blockservice
.
New
(
repo
.
Blockstore
(),
repo
.
Exchange
()
)
node
.
Block
s
,
err
=
blockservice
.
New
(
node
.
Blockstore
,
node
.
Exchange
)
if
err
!=
nil
{
return
nil
,
err
}
dag
:
=
merkledag
.
NewDAGService
(
bs
s
)
node
.
DAG
=
merkledag
.
NewDAGService
(
node
.
Block
s
)
// to make sure nothing is omitted, init each individual field and assign
// all at once at the bottom.
return
&
core
{
repo
:
repo
,
blockService
:
bss
,
dag
:
dag
,
return
&
Core
{
IpfsNode
:
node
,
},
nil
}
type
RepoFactory
func
(
ctx
context
.
Context
)
(
Repo
,
error
)
type
RepoFactory
func
(
ctx
context
.
Context
)
(
*
core
.
IpfsNode
,
error
)
type
Repo
interface
{
ID
()
peer
.
ID
...
...
@@ -132,11 +126,11 @@ func (r *repo) Exchange() exchange.Interface {
}
func
MocknetTestRepo
(
p
peer
.
ID
,
h
host
.
Host
,
conf
testutil
.
LatencyConfig
)
RepoFactory
{
return
func
(
ctx
context
.
Context
)
(
Repo
,
error
)
{
return
func
(
ctx
context
.
Context
)
(
*
core
.
IpfsNode
,
error
)
{
const
kWriteCacheElems
=
100
const
alwaysSendToPeer
=
true
dsDelay
:=
delay
.
Fixed
(
conf
.
BlockstoreLatency
)
ds
:=
sync
.
MutexWrap
(
datastore2
.
WithDelay
(
datastore
.
NewMapDatastore
(),
dsDelay
))
ds
:=
datastore2
.
CloserWrap
(
sync
.
MutexWrap
(
datastore2
.
WithDelay
(
datastore
.
NewMapDatastore
(),
dsDelay
))
)
log
.
Debugf
(
"MocknetTestRepo: %s %s %s"
,
p
,
h
.
ID
(),
h
)
dhtt
:=
dht
.
NewDHT
(
ctx
,
h
,
ds
)
...
...
@@ -146,14 +140,15 @@ func MocknetTestRepo(p peer.ID, h host.Host, conf testutil.LatencyConfig) RepoFa
return
nil
,
err
}
exch
:=
bitswap
.
New
(
ctx
,
p
,
bsn
,
bstore
,
alwaysSendToPeer
)
return
&
repo
{
bitSwapNetwork
:
bsn
,
blockstore
:
bstore
,
exchange
:
exch
,
datastore
:
ds
,
host
:
h
,
dht
:
dhtt
,
id
:
p
,
return
&
core
.
IpfsNode
{
Peerstore
:
h
.
Peerstore
(),
Blockstore
:
bstore
,
Exchange
:
exch
,
Datastore
:
ds
,
PeerHost
:
h
,
Routing
:
dhtt
,
Identity
:
p
,
DHT
:
dhtt
,
},
nil
}
}
test/epictest/three_legged_cat_test.go
View file @
85401d53
...
...
@@ -55,9 +55,9 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
if
err
!=
nil
{
return
err
}
adder
.
Bootstrap
(
ctx
,
boo
t
strap
.
ID
()
)
catter
.
Bootstrap
(
ctx
,
boo
t
strap
.
ID
()
)
boostrapInfo
:=
bootstrap
.
Peerstore
.
PeerInfo
(
bootstrap
.
PeerHost
.
ID
())
adder
.
Bootstrap
(
ctx
,
boostrap
Info
)
catter
.
Bootstrap
(
ctx
,
boostrap
Info
)
keyAdded
,
err
:=
adder
.
Add
(
bytes
.
NewReader
(
data
))
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment