Commit 1e4a4eaa authored by Hector Sanjuan's avatar Hector Sanjuan

Use ReadFull. Remove duplicated code

License: MIT
Signed-off-by: default avatarHector Sanjuan <hector@protocol.ai>
parent 90a5c15f
...@@ -133,19 +133,23 @@ func TestBatchFetchDupBlock(t *testing.T) { ...@@ -133,19 +133,23 @@ func TestBatchFetchDupBlock(t *testing.T) {
func makeTestDAG(t *testing.T, read io.Reader, ds ipld.DAGService) ipld.Node { func makeTestDAG(t *testing.T, read io.Reader, ds ipld.DAGService) ipld.Node {
p := make([]byte, 512) p := make([]byte, 512)
nodes := []*ProtoNode{} nodes := []*ProtoNode{}
var err error
n, err = io.ReadFull(read, p) for {
if n != len(p) { n, err := io.ReadFull(read, p)
t.Fatal("should have read 512 bytes from the reader") if err == io.EOF {
} break
for err == nil { }
if err != nil {
t.Fatal(err)
}
if n != len(p) {
t.Fatal("should have read 512 bytes from the reader")
}
protoNode := NodeWithData(p) protoNode := NodeWithData(p)
nodes = append(nodes, protoNode) nodes = append(nodes, protoNode)
_, err = read.Read(p)
}
if err != io.EOF {
t.Fatal(err)
} }
ctx := context.Background() ctx := context.Background()
...@@ -158,7 +162,7 @@ func makeTestDAG(t *testing.T, read io.Reader, ds ipld.DAGService) ipld.Node { ...@@ -158,7 +162,7 @@ func makeTestDAG(t *testing.T, read io.Reader, ds ipld.DAGService) ipld.Node {
t.Fatal(err) t.Fatal(err)
} }
} }
err = ds.Add(ctx, root) err := ds.Add(ctx, root)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment