mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
In upcoming commits, we will introduce a new migration stream package that will need to reference the db package, as well as the accounts, session and firewalldb package in future commits. To avoid circular dependencies, we therefore introduce a new migration stream that unit tests can use, in order to avoid having to import the new migration stream package.
37 lines
985 B
Go
37 lines
985 B
Go
//go:build test_db_sqlite && !test_db_postgres
|
|
|
|
package session
|
|
|
|
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.MakeTestMigrationStreams()).BaseDB,
|
|
clock,
|
|
)
|
|
}
|
|
|
|
// NewTestDBFromPath is a helper function that creates a new SQLStore with a
|
|
// connection to an existing sqlite database for testing.
|
|
func NewTestDBFromPath(t *testing.T, dbPath string,
|
|
clock clock.Clock) Store {
|
|
|
|
tDb := sqldb.NewTestSqliteDBFromPath(
|
|
t, dbPath, db.MakeTestMigrationStreams(),
|
|
)
|
|
|
|
return createStore(t, tDb.BaseDB, clock)
|
|
}
|