Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

testutil: fix block generator #135

Merged
merged 1 commit into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var prioritySeq int
// GenerateBlocksOfSize generates a series of blocks of the given byte size
func GenerateBlocksOfSize(n int, size int64) []blocks.Block {
generatedBlocks := make([]blocks.Block, 0, n)
buf := make([]byte, size)
for i := 0; i < n; i++ {
// rand.Read never errors
buf := make([]byte, size)
rand.Read(buf)
b := blocks.NewBlock(buf)
generatedBlocks = append(generatedBlocks, b)
Expand Down
16 changes: 16 additions & 0 deletions testutil/testutil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package testutil

import (
"testing"

blocks "github.com/ipfs/go-block-format"
)

func TestGenerateBlocksOfSize(t *testing.T) {
for _, b1 := range GenerateBlocksOfSize(10, 100) {
b2 := blocks.NewBlock(b1.RawData())
if b2.Cid() != b1.Cid() {
t.Fatal("block CIDs mismatch")
}
}
}