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-merkledag
Commits
b6ffb6a3
Commit
b6ffb6a3
authored
Nov 25, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a test in merkledag to exercise GetBlocks
parent
eba3c6bd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
1 deletion
+93
-1
merkledag_test.go
merkledag_test.go
+93
-1
No files found.
merkledag_test.go
View file @
b6ffb6a3
package
merkledag
package
merkledag
_test
import
(
"bytes"
"fmt"
"io"
"io/ioutil"
"testing"
bserv
"github.com/jbenet/go-ipfs/blockservice"
bs
"github.com/jbenet/go-ipfs/exchange/bitswap"
tn
"github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
imp
"github.com/jbenet/go-ipfs/importer"
chunk
"github.com/jbenet/go-ipfs/importer/chunk"
.
"github.com/jbenet/go-ipfs/merkledag"
"github.com/jbenet/go-ipfs/routing/mock"
uio
"github.com/jbenet/go-ipfs/unixfs/io"
u
"github.com/jbenet/go-ipfs/util"
)
...
...
@@ -56,3 +67,84 @@ func TestNode(t *testing.T) {
printn
(
"boop"
,
n2
)
printn
(
"beep boop"
,
n3
)
}
func
makeTestDag
(
t
*
testing
.
T
)
*
Node
{
read
:=
io
.
LimitReader
(
u
.
NewTimeSeededRand
(),
1024
*
32
)
spl
:=
&
chunk
.
SizeSplitter
{
512
}
root
,
err
:=
imp
.
NewDagFromReaderWithSplitter
(
read
,
spl
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
root
}
func
TestBatchFetch
(
t
*
testing
.
T
)
{
net
:=
tn
.
VirtualNetwork
()
rs
:=
mock
.
VirtualRoutingServer
()
sg
:=
bs
.
NewSessionGenerator
(
net
,
rs
)
instances
:=
sg
.
Instances
(
5
)
var
servs
[]
*
bserv
.
BlockService
var
dagservs
[]
DAGService
for
_
,
i
:=
range
instances
{
bsi
,
err
:=
bserv
.
New
(
i
.
Blockstore
,
i
.
Exchange
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
servs
=
append
(
servs
,
bsi
)
dagservs
=
append
(
dagservs
,
NewDAGService
(
bsi
))
}
t
.
Log
(
"finished setup."
)
root
:=
makeTestDag
(
t
)
read
,
err
:=
uio
.
NewDagReader
(
root
,
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
expected
,
err
:=
ioutil
.
ReadAll
(
read
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
dagservs
[
0
]
.
AddRecursive
(
root
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
t
.
Log
(
"Added file to first node."
)
k
,
err
:=
root
.
Key
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
done
:=
make
(
chan
struct
{})
for
i
:=
1
;
i
<
len
(
dagservs
);
i
++
{
go
func
(
i
int
)
{
first
,
err
:=
dagservs
[
i
]
.
Get
(
k
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
fmt
.
Println
(
"Got first node back."
)
read
,
err
:=
uio
.
NewDagReader
(
first
,
dagservs
[
i
])
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
datagot
,
err
:=
ioutil
.
ReadAll
(
read
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
datagot
,
expected
)
{
t
.
Fatal
(
"Got bad data back!"
)
}
done
<-
struct
{}{}
}(
i
)
}
for
i
:=
1
;
i
<
len
(
dagservs
);
i
++
{
<-
done
}
}
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