kvdb/test: add bolt test

This commit is contained in:
Joost Jager
2021-07-07 09:27:43 +02:00
parent f592375d1b
commit e9cba1a526
3 changed files with 130 additions and 6 deletions

44
kvdb/bolt_fixture.go Normal file
View File

@@ -0,0 +1,44 @@
package kvdb
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/btcsuite/btcwallet/walletdb"
"github.com/stretchr/testify/require"
)
type boltFixture struct {
t *testing.T
tempDir string
}
func NewBoltFixture(t *testing.T) *boltFixture {
tempDir, err := ioutil.TempDir("", "test")
require.NoError(t, err)
return &boltFixture{
t: t,
tempDir: tempDir,
}
}
func (b *boltFixture) Cleanup() {
os.RemoveAll(b.tempDir)
}
func (b *boltFixture) NewBackend() walletdb.DB {
dbPath := filepath.Join(b.tempDir)
db, err := GetBoltBackend(&BoltBackendConfig{
DBPath: dbPath,
DBFileName: "test.db",
NoFreelistSync: true,
DBTimeout: DefaultDBTimeout,
})
require.NoError(b.t, err)
return db
}