Commit edf6fdfe authored by Jakub Sztandera's avatar Jakub Sztandera

test: fixup style and add more checks to blockstore tests

License: MIT
Signed-off-by: default avatarJakub Sztandera <kubuxu@protonmail.ch>
parent 71c18780
......@@ -8,23 +8,23 @@ import (
ds "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore"
dsq "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore/query"
ds_sync "gx/ipfs/QmTxLSvdhwg68WJimdS6icLPhZi28aTp6b7uihC2Yb47Xk/go-datastore/sync"
u "gx/ipfs/QmZNVWh8LLjAavuQ2JXuFmuYH3C11xo988vSgp7UQrTRj1/go-ipfs-util"
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
blocks "github.com/ipfs/go-ipfs/blocks"
key "github.com/ipfs/go-ipfs/blocks/key"
)
// TODO(brian): TestGetReturnsNil
func TestGetWhenKeyNotPresent(t *testing.T) {
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 {
t.Log("As expected, block is not present")
return
if bl != nil {
t.Error("nil block expected")
}
if err == nil {
t.Error("error expected, got nil")
}
t.Fail()
}
func TestGetWhenKeyIsEmptyString(t *testing.T) {
......@@ -54,19 +54,25 @@ func TestPutThenGetBlock(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()))
bl := blocks.NewBlock([]byte("some data"))
blBad, err := blocks.NewBlockWithHash([]byte("some other data"), bl.Key().ToMultihash())
bl2 := blocks.NewBlock([]byte("some other data"))
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(bl2)
bs.RuntimeHashing(true)
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() {
......
......@@ -7,21 +7,21 @@ func TestCachingOptsLessThanZero(t *testing.T) {
opts.HasARCCacheSize = -1
if _, err := CachedBlockstore(nil, nil, opts); err == nil {
t.Fatal()
t.Error("wrong ARC setting was not detected")
}
opts = DefaultCacheOpts()
opts.HasBloomFilterSize = -1
if _, err := CachedBlockstore(nil, nil, opts); err == nil {
t.Fatal()
t.Error("negative bloom size was not detected")
}
opts = DefaultCacheOpts()
opts.HasBloomFilterHashes = -1
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) {
opts.HasBloomFilterHashes = 0
if _, err := CachedBlockstore(nil, nil, opts); err == nil {
t.Fatal()
t.Error("zero hashes setting with positive size was not detected")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment