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