@cryptotaxi247 / kubo / commits / 697625a9e

feat(util:testutil) add NewBlockOrFail(t, data) factory method

for use in tests

Brian Tiger Chow committed Sep 16, 2014 at 04:03 UTC 697625a9e5f405bcc5cb106a05b66c74698d1054
1 file changed +22
util/testutil/blocks.go new
+22
@@ -0,0 +1,22 @@
1 +package testutil
2 +
3 +import (
4 + "testing"
5 +
6 + blocks "github.com/jbenet/go-ipfs/blocks"
7 +)
8 +
9 +// NewBlockOrFail returns a block created from msgData. Signals test failure if
10 +// creation fails.
11 +//
12 +// NB: NewBlockOrFail accepts a msgData parameter to avoid non-determinism in
13 +// tests. Generating random block data could potentially result in unexpected
14 +// behavior in tests. Thus, it is left up to the caller to select the msgData
15 +// that will determine the blocks key.
16 +func NewBlockOrFail(t *testing.T, msgData string) blocks.Block {
17 + block, blockCreationErr := blocks.NewBlock([]byte(msgData))
18 + if blockCreationErr != nil {
19 + t.Fatal(blockCreationErr)
20 + }
21 + return *block
22 +}