@cryptotaxi247 / kubo / commits / 68d519726

test: do explicit error check

License: MIT Signed-off-by: Jakub Sztandera <kubuxu@ipfs.io>

Jakub Sztandera committed Aug 15, 2016 at 17:23 UTC 68d5197265ad6587b0a512e06d955fe8f170c8d7
2 files changed +4 -2
blocks/blocks.go
+3 -1
@@ -11,6 +11,8 @@ import (
11 u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
12 )
13
14 +var errWrongHash = errors.New("Data did not match given hash!")
15 +
16 type Block interface {
17 Multihash() mh.Multihash
18 Data() []byte
@@ -37,7 +39,7 @@ func NewBlockWithHash(data []byte, h mh.Multihash) (*BasicBlock, error) {
39 if u.Debug {
40 chk := u.Hash(data)
41 if string(chk) != string(h) {
40 - return nil, errors.New("Data did not match given hash!")
42 + return nil, errWrongHash
43 }
44 }
45 return &BasicBlock{data: data, multihash: h}, nil
blocks/blocks_test.go
+1 -1
@@ -89,7 +89,7 @@ func TestManualHash(t *testing.T) {
89 u.Debug = true
90
91 block, err = NewBlockWithHash(data, hash)
92 - if err == nil {
92 + if err != errWrongHash {
93 t.Fatal(err)
94 }
95