mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
In preparation for upcoming migration tests from a kvdb to an SQL store, this commit updates the NewTestDB function to return the Store interface rather than a concrete store implementation. This change ensures that migration tests can call NewTestDB under any build tag while receiving a consistent return type.
35 lines
903 B
Go
35 lines
903 B
Go
//go:build !test_db_sqlite && !test_db_postgres
|
|
|
|
package accounts
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/lightningnetwork/lnd/clock"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// ErrDBClosed is an error that is returned when a database operation is
|
|
// performed on a closed database.
|
|
var ErrDBClosed = errors.New("database not open")
|
|
|
|
// NewTestDB is a helper function that creates an BBolt database for testing.
|
|
func NewTestDB(t *testing.T, clock clock.Clock) Store {
|
|
return NewTestDBFromPath(t, t.TempDir(), clock)
|
|
}
|
|
|
|
// NewTestDBFromPath is a helper function that creates a new BoltStore with a
|
|
// connection to an existing BBolt database for testing.
|
|
func NewTestDBFromPath(t *testing.T, dbPath string,
|
|
clock clock.Clock) Store {
|
|
|
|
store, err := NewBoltStore(dbPath, DBFilename, clock)
|
|
require.NoError(t, err)
|
|
|
|
t.Cleanup(func() {
|
|
require.NoError(t, store.db.Close())
|
|
})
|
|
|
|
return store
|
|
}
|