lightning-terminal/accounts/test_sqlite.go
Viktor Tigerström 92689c546c
accounts: update NewTestDB func to return Store
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.
2025-05-02 15:44:50 +07:00

30 lines
848 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"
)
// 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 NewSQLStore(db.NewTestSqliteDB(t).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 {
return NewSQLStore(
db.NewTestSqliteDbHandleFromPath(t, dbPath).BaseDB, clock,
)
}