Skip to content

Commit

Permalink
test: do explicit error check
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Jakub Sztandera committed Aug 15, 2016
1 parent e6e5593 commit 7614cda
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
)

var errWrongHash = errors.New("Data did not match given hash!")

type Block interface {
Multihash() mh.Multihash
Data() []byte
Expand All @@ -37,7 +39,7 @@ func NewBlockWithHash(data []byte, h mh.Multihash) (*BasicBlock, error) {
if u.Debug {
chk := u.Hash(data)
if string(chk) != string(h) {
return nil, errors.New("Data did not match given hash!")
return nil, errWrongHash
}
}
return &BasicBlock{data: data, multihash: h}, nil
Expand Down
2 changes: 1 addition & 1 deletion blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestManualHash(t *testing.T) {
u.Debug = true

block, err = NewBlockWithHash(data, hash)
if err == nil {
if err != errWrongHash {
t.Fatal(err)
}

Expand Down

0 comments on commit 7614cda

Please sign in to comment.