mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-16 13:01:14 +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.
35 lines
909 B
Go
35 lines
909 B
Go
//go:build test_db_sqlite && !test_db_postgres
|
|
|
|
package firewalldb
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/lightninglabs/lightning-terminal/db"
|
|
"github.com/lightningnetwork/lnd/clock"
|
|
"github.com/lightningnetwork/lnd/sqldb/v2"
|
|
)
|
|
|
|
// isSqlite is true if the test_db_sqlite build flag is set.
|
|
var isSqlite = true
|
|
|
|
// NewTestDB is a helper function that creates an BBolt database for testing.
|
|
func NewTestDB(t *testing.T, clock clock.Clock) FirewallDBs {
|
|
return createStore(
|
|
t,
|
|
sqldb.NewTestSqliteDB(t, db.MakeTestMigrationStreams()).BaseDB,
|
|
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) FirewallDBs {
|
|
|
|
tDb := sqldb.NewTestSqliteDBFromPath(
|
|
t, dbPath, db.MakeTestMigrationStreams(),
|
|
)
|
|
|
|
return createStore(t, tDb.BaseDB, clock)
|
|
}
|