test: fixup style and add more checks to blockstore tests
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
Jakub Sztandera committed
Aug 16, 2016 at 18:59 UTC
7febd606d47530001c00940b27addcc6d85067ca
2 files changed
+20
-14
blocks/blockstore/blockstore_test.go
+16
-10
@@ -8,23 +8,23 @@ import (
8
ds "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore"
9
dsq "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore/query"
10
ds_sync "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore/sync"
11
+ u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
12
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
13
14
blocks "github.com/ipfs/go-ipfs/blocks"
15
key "github.com/ipfs/go-ipfs/blocks/key"
16
)
17
17
-// TODO(brian): TestGetReturnsNil
18
-
18
func TestGetWhenKeyNotPresent(t *testing.T) {
19
bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
21
- _, err := bs.Get(key.Key("not present"))
20
+ bl, err := bs.Get(key.Key("not present"))
21
23
- if err != nil {
24
- t.Log("As expected, block is not present")
25
- return
22
+ if bl != nil {
23
+ t.Error("nil block expected")
24
+ }
25
+ if err == nil {
26
+ t.Error("error expected, got nil")
27
}
27
- t.Fail()
28
}
29
30
func TestGetWhenKeyIsEmptyString(t *testing.T) {
@@ -54,19 +54,25 @@ func TestPutThenGetBlock(t *testing.T) {
54
}
55
56
func TestRuntimeHashing(t *testing.T) {
57
+ orginalDebug := u.Debug
58
+ defer (func() {
59
+ u.Debug = orginalDebug
60
+ })()
61
+ u.Debug = false
62
+
63
bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
64
bl := blocks.NewBlock([]byte("some data"))
65
blBad, err := blocks.NewBlockWithHash([]byte("some other data"), bl.Key().ToMultihash())
60
- bl2 := blocks.NewBlock([]byte("some other data"))
66
if err != nil {
62
- t.Fatal("Debug is enabled")
67
+ t.Fatal("debug is off, still got an error")
68
}
69
+ bl2 := blocks.NewBlock([]byte("some other data"))
70
bs.Put(blBad)
71
bs.Put(bl2)
72
bs.RuntimeHashing(true)
73
74
if _, err := bs.Get(bl.Key()); err != ErrHashMismatch {
69
- t.Fatalf("Expected '%v' got '%v'\n", ErrHashMismatch, err)
75
+ t.Fatalf("expected '%v' got '%v'\n", ErrHashMismatch, err)
76
}
77
78
if b, err := bs.Get(bl2.Key()); err != nil || b.String() != bl2.String() {
blocks/blockstore/caching_test.go
+4
-4
@@ -7,21 +7,21 @@ func TestCachingOptsLessThanZero(t *testing.T) {
7
opts.HasARCCacheSize = -1
8
9
if _, err := CachedBlockstore(nil, nil, opts); err == nil {
10
- t.Fatal()
10
+ t.Error("wrong ARC setting was not detected")
11
}
12
13
opts = DefaultCacheOpts()
14
opts.HasBloomFilterSize = -1
15
16
if _, err := CachedBlockstore(nil, nil, opts); err == nil {
17
- t.Fatal()
17
+ t.Error("negative bloom size was not detected")
18
}
19
20
opts = DefaultCacheOpts()
21
opts.HasBloomFilterHashes = -1
22
23
if _, err := CachedBlockstore(nil, nil, opts); err == nil {
24
- t.Fatal()
24
+ t.Error("negative hashes setting was not detected")
25
}
26
}
27
@@ -30,6 +30,6 @@ func TestBloomHashesAtZero(t *testing.T) {
30
opts.HasBloomFilterHashes = 0
31
32
if _, err := CachedBlockstore(nil, nil, opts); err == nil {
33
- t.Fatal()
33
+ t.Error("zero hashes setting with positive size was not detected")
34
}
35
}