test for bolt backed tracking store

This commit is contained in:
vyzo 2021-02-27 13:40:26 +02:00
parent f1c61c4753
commit 2e4d45ef07

View File

@ -1,19 +1,18 @@
package splitstore
import (
"os"
"testing"
"golang.org/x/xerrors"
"github.com/ledgerwatch/lmdb-go/lmdb"
cid "github.com/ipfs/go-cid"
"github.com/multiformats/go-multihash"
"github.com/filecoin-project/go-state-types/abi"
)
func TestTrackingStore(t *testing.T) {
func testTrackingStore(t *testing.T, useLMDB bool) {
t.Helper()
makeCid := func(key string) cid.Cid {
h, err := multihash.Sum([]byte(key), multihash.SHA2_256, -1)
if err != nil {
@ -36,16 +35,19 @@ func TestTrackingStore(t *testing.T) {
mustNotHave := func(s TrackingStore, cid cid.Cid) {
_, err := s.Get(cid)
xerr := xerrors.Unwrap(err)
if xerr == nil {
xerr = err
}
if !lmdb.IsNotFound(xerr) {
t.Fatal("expected key not found")
if err == nil {
t.Fatal("expected error")
}
}
s, err := NewLMDBTrackingStore("/tmp/snoop-test")
path := "/tmp/liveset-test"
err := os.MkdirAll(path, 0777)
if err != nil {
t.Fatal(err)
}
s, err := NewTrackingStore(path, useLMDB)
if err != nil {
t.Fatal(err)
}
@ -112,7 +114,7 @@ func TestTrackingStore(t *testing.T) {
t.Fatal(err)
}
s, err = NewLMDBTrackingStore("/tmp/snoop-test")
s, err = NewTrackingStore(path, useLMDB)
if err != nil {
t.Fatal(err)
}
@ -124,3 +126,11 @@ func TestTrackingStore(t *testing.T) {
s.Close() //nolint:errcheck
}
func TestLMDBTrackingStore(t *testing.T) {
testTrackingStore(t, true)
}
func TestBoltTrackingStore(t *testing.T) {
testTrackingStore(t, false)
}