kubo/util/testutil/blocks.go
2014-09-16 04:03:30 -07:00

23 lines
664 B
Go

package testutil
import (
"testing"
blocks "github.com/jbenet/go-ipfs/blocks"
)
// NewBlockOrFail returns a block created from msgData. Signals test failure if
// creation fails.
//
// NB: NewBlockOrFail accepts a msgData parameter to avoid non-determinism in
// tests. Generating random block data could potentially result in unexpected
// behavior in tests. Thus, it is left up to the caller to select the msgData
// that will determine the blocks key.
func NewBlockOrFail(t *testing.T, msgData string) blocks.Block {
block, blockCreationErr := blocks.NewBlock([]byte(msgData))
if blockCreationErr != nil {
t.Fatal(blockCreationErr)
}
return *block
}