lightning-terminal/accounts/test_sqlite.go
2026-05-14 11:39:09 +02:00

37 lines
977 B
Go

//go:build test_db_sqlite && !test_db_postgres
package accounts
import (
"errors"
"testing"
"github.com/lightninglabs/lightning-terminal/db"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/sqldb/v2"
)
// ErrDBClosed is an error that is returned when a database operation is
// performed on a closed database.
var ErrDBClosed = errors.New("database is closed")
// NewTestDB is a helper function that creates an SQLStore database for testing.
func NewTestDB(t *testing.T, clock clock.Clock) Store {
return createStore(
t,
sqldb.NewTestSqliteDB(t, db.MakeTestMigrationSets()).BaseDB,
clock,
)
}
// NewTestDBFromPath is a helper function that creates a new SQLStore with a
// connection to an existing SQL database for testing.
func NewTestDBFromPath(t *testing.T, dbPath string,
clock clock.Clock) Store {
tDb := sqldb.NewTestSqliteDBFromPath(
t, dbPath, db.MakeTestMigrationSets(),
)
return createStore(t, tDb.BaseDB, clock)
}