test: fixup style and add more checks to blockstore tests

License: MIT
Signed-off-by: 's avatarJakub Sztandera <kubuxu@protonmail.ch>
上级 233a622e
...@@ -8,23 +8,23 @@ import ( ...@@ -8,23 +8,23 @@ import (
ds "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore" ds "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore"
dsq "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore/query" dsq "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore/query"
ds_sync "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore/sync" ds_sync "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore/sync"
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
blocks "github.com/ipfs/go-ipfs/blocks" blocks "github.com/ipfs/go-ipfs/blocks"
key "github.com/ipfs/go-ipfs/blocks/key" key "github.com/ipfs/go-ipfs/blocks/key"
) )
// TODO(brian): TestGetReturnsNil
func TestGetWhenKeyNotPresent(t *testing.T) { func TestGetWhenKeyNotPresent(t *testing.T) {
bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore())) bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
_, err := bs.Get(key.Key("not present")) bl, err := bs.Get(key.Key("not present"))
if err != nil { if bl != nil {
t.Log("As expected, block is not present") t.Error("nil block expected")
return }
if err == nil {
t.Error("error expected, got nil")
} }
t.Fail()
} }
func TestGetWhenKeyIsEmptyString(t *testing.T) { func TestGetWhenKeyIsEmptyString(t *testing.T) {
...@@ -54,19 +54,25 @@ func TestPutThenGetBlock(t *testing.T) { ...@@ -54,19 +54,25 @@ func TestPutThenGetBlock(t *testing.T) {
} }
func TestRuntimeHashing(t *testing.T) { func TestRuntimeHashing(t *testing.T) {
orginalDebug := u.Debug
defer (func() {
u.Debug = orginalDebug
})()
u.Debug = false
bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore())) bs := NewBlockstore(ds_sync.MutexWrap(ds.NewMapDatastore()))
bl := blocks.NewBlock([]byte("some data")) bl := blocks.NewBlock([]byte("some data"))
blBad, err := blocks.NewBlockWithHash([]byte("some other data"), bl.Key().ToMultihash()) blBad, err := blocks.NewBlockWithHash([]byte("some other data"), bl.Key().ToMultihash())
bl2 := blocks.NewBlock([]byte("some other data"))
if err != nil { if err != nil {
t.Fatal("Debug is enabled") t.Fatal("debug is off, still got an error")
} }
bl2 := blocks.NewBlock([]byte("some other data"))
bs.Put(blBad) bs.Put(blBad)
bs.Put(bl2) bs.Put(bl2)
bs.RuntimeHashing(true) bs.RuntimeHashing(true)
if _, err := bs.Get(bl.Key()); err != ErrHashMismatch { if _, err := bs.Get(bl.Key()); err != ErrHashMismatch {
t.Fatalf("Expected '%v' got '%v'\n", ErrHashMismatch, err) t.Fatalf("expected '%v' got '%v'\n", ErrHashMismatch, err)
} }
if b, err := bs.Get(bl2.Key()); err != nil || b.String() != bl2.String() { if b, err := bs.Get(bl2.Key()); err != nil || b.String() != bl2.String() {
......
...@@ -7,21 +7,21 @@ func TestCachingOptsLessThanZero(t *testing.T) { ...@@ -7,21 +7,21 @@ func TestCachingOptsLessThanZero(t *testing.T) {
opts.HasARCCacheSize = -1 opts.HasARCCacheSize = -1
if _, err := CachedBlockstore(nil, nil, opts); err == nil { if _, err := CachedBlockstore(nil, nil, opts); err == nil {
t.Fatal() t.Error("wrong ARC setting was not detected")
} }
opts = DefaultCacheOpts() opts = DefaultCacheOpts()
opts.HasBloomFilterSize = -1 opts.HasBloomFilterSize = -1
if _, err := CachedBlockstore(nil, nil, opts); err == nil { if _, err := CachedBlockstore(nil, nil, opts); err == nil {
t.Fatal() t.Error("negative bloom size was not detected")
} }
opts = DefaultCacheOpts() opts = DefaultCacheOpts()
opts.HasBloomFilterHashes = -1 opts.HasBloomFilterHashes = -1
if _, err := CachedBlockstore(nil, nil, opts); err == nil { if _, err := CachedBlockstore(nil, nil, opts); err == nil {
t.Fatal() t.Error("negative hashes setting was not detected")
} }
} }
...@@ -30,6 +30,6 @@ func TestBloomHashesAtZero(t *testing.T) { ...@@ -30,6 +30,6 @@ func TestBloomHashesAtZero(t *testing.T) {
opts.HasBloomFilterHashes = 0 opts.HasBloomFilterHashes = 0
if _, err := CachedBlockstore(nil, nil, opts); err == nil { if _, err := CachedBlockstore(nil, nil, opts); err == nil {
t.Fatal() t.Error("zero hashes setting with positive size was not detected")
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论