mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
multi: introduce migration stream for unit tests
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.
This commit is contained in:
parent
a5f727279f
commit
f77ae5dcf2
5 changed files with 49 additions and 7 deletions
|
|
@ -18,7 +18,8 @@ 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.LitdMigrationStreams).BaseDB,
|
||||
t,
|
||||
sqldb.NewTestSqliteDB(t, db.MakeTestMigrationStreams()).BaseDB,
|
||||
clock,
|
||||
)
|
||||
}
|
||||
|
|
@ -28,7 +29,9 @@ func NewTestDB(t *testing.T, clock clock.Clock) Store {
|
|||
func NewTestDBFromPath(t *testing.T, dbPath string,
|
||||
clock clock.Clock) Store {
|
||||
|
||||
tDb := sqldb.NewTestSqliteDBFromPath(t, dbPath, db.LitdMigrationStreams)
|
||||
tDb := sqldb.NewTestSqliteDBFromPath(
|
||||
t, dbPath, db.MakeTestMigrationStreams(),
|
||||
)
|
||||
|
||||
return createStore(t, tDb.BaseDB, clock)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
"github.com/golang-migrate/migrate/v4/database/pgx/v5"
|
||||
"github.com/lightningnetwork/lnd/sqldb/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
// LatestMigrationVersion is the latest migration version of the
|
||||
// database. This is used to implement downgrade protection for the
|
||||
|
|
@ -8,3 +14,28 @@ const (
|
|||
// NOTE: This MUST be updated when a new migration is added.
|
||||
LatestMigrationVersion = 5
|
||||
)
|
||||
|
||||
// MakeTestMigrationStreams creates the migration streams for the unit test
|
||||
// environment.
|
||||
func MakeTestMigrationStreams() []sqldb.MigrationStream {
|
||||
migStream := sqldb.MigrationStream{
|
||||
TrackingTableName: pgx.DefaultMigrationsTable,
|
||||
SQLFileDirectory: "sqlc/migrations",
|
||||
SQLFiles: SqlSchemas,
|
||||
|
||||
// LatestMigrationVersion is the latest migration version of the
|
||||
// database. This is used to implement downgrade protection for
|
||||
// the daemon.
|
||||
//
|
||||
// NOTE: This MUST be updated when a new migration is added.
|
||||
LatestMigrationVersion: LatestMigrationVersion,
|
||||
|
||||
MakeProgrammaticMigrations: func(db *sqldb.BaseDB) (
|
||||
map[uint]migrate.ProgrammaticMigrEntry, error) {
|
||||
|
||||
return make(map[uint]migrate.ProgrammaticMigrEntry), nil
|
||||
},
|
||||
}
|
||||
|
||||
return []sqldb.MigrationStream{migStream}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,5 +68,7 @@ func NewTestPostgresDB(t *testing.T) *sqldb.PostgresStore {
|
|||
sqlFixture.TearDown(t)
|
||||
})
|
||||
|
||||
return sqldb.NewTestPostgresDB(t, sqlFixture, LitdMigrationStreams)
|
||||
return sqldb.NewTestPostgresDB(
|
||||
t, sqlFixture, MakeTestMigrationStreams(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ 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.LitdMigrationStreams).BaseDB,
|
||||
t,
|
||||
sqldb.NewTestSqliteDB(t, db.MakeTestMigrationStreams()).BaseDB,
|
||||
clock,
|
||||
)
|
||||
}
|
||||
|
|
@ -26,7 +27,9 @@ func NewTestDB(t *testing.T, clock clock.Clock) FirewallDBs {
|
|||
func NewTestDBFromPath(t *testing.T, dbPath string,
|
||||
clock clock.Clock) FirewallDBs {
|
||||
|
||||
tDb := sqldb.NewTestSqliteDBFromPath(t, dbPath, db.LitdMigrationStreams)
|
||||
tDb := sqldb.NewTestSqliteDBFromPath(
|
||||
t, dbPath, db.MakeTestMigrationStreams(),
|
||||
)
|
||||
|
||||
return createStore(t, tDb.BaseDB, clock)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ 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.LitdMigrationStreams).BaseDB,
|
||||
t,
|
||||
sqldb.NewTestSqliteDB(t, db.MakeTestMigrationStreams()).BaseDB,
|
||||
clock,
|
||||
)
|
||||
}
|
||||
|
|
@ -28,7 +29,9 @@ func NewTestDB(t *testing.T, clock clock.Clock) Store {
|
|||
func NewTestDBFromPath(t *testing.T, dbPath string,
|
||||
clock clock.Clock) Store {
|
||||
|
||||
tDb := sqldb.NewTestSqliteDBFromPath(t, dbPath, db.LitdMigrationStreams)
|
||||
tDb := sqldb.NewTestSqliteDBFromPath(
|
||||
t, dbPath, db.MakeTestMigrationStreams(),
|
||||
)
|
||||
|
||||
return createStore(t, tDb.BaseDB, clock)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue