2025-01-05 08:57:19 +02:00
|
|
|
//go:build test_db_sqlite && !test_db_postgres
|
|
|
|
|
|
|
|
|
|
package accounts
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/lightninglabs/lightning-terminal/db"
|
|
|
|
|
"github.com/lightningnetwork/lnd/clock"
|
2025-07-22 12:20:04 +02:00
|
|
|
"github.com/lightningnetwork/lnd/sqldb/v2"
|
2025-01-05 08:57:19 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 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.
|
2025-04-24 15:48:10 +07:00
|
|
|
func NewTestDB(t *testing.T, clock clock.Clock) Store {
|
2025-07-22 12:20:04 +02:00
|
|
|
return createStore(
|
2025-07-24 02:39:36 +02:00
|
|
|
t,
|
2026-03-26 11:57:14 +01:00
|
|
|
sqldb.NewTestSqliteDB(t, db.MakeTestMigrationSets()).BaseDB,
|
2025-07-22 12:20:04 +02:00
|
|
|
clock,
|
|
|
|
|
)
|
2025-01-05 08:57:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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,
|
2025-04-24 15:48:10 +07:00
|
|
|
clock clock.Clock) Store {
|
2025-01-05 08:57:19 +02:00
|
|
|
|
2025-07-24 02:39:36 +02:00
|
|
|
tDb := sqldb.NewTestSqliteDBFromPath(
|
2026-03-26 11:57:14 +01:00
|
|
|
t, dbPath, db.MakeTestMigrationSets(),
|
2025-07-24 02:39:36 +02:00
|
|
|
)
|
2025-07-22 12:20:04 +02:00
|
|
|
|
|
|
|
|
return createStore(t, tDb.BaseDB, clock)
|
2025-01-05 08:57:19 +02:00
|
|
|
}
|