Skip to content

Commit ae8370a

Browse files
db: add sqldb/v2 PostgresStore creation helper
As we will change the `accounts`, `session` & `firewalldb` packages to use the `sqldb/v2` package, we need to make those packages use the `sqldb/v2` `PostgresStore` when setting up their test postgres databases, instead of `litd`'s own `PostgresStore` version. In order to enable that functionality, we add a new helper function that creates a `PostgresStore` using the `sqldb/v2` package, in addition to helper function that creates a `PostgresStore` using the `litd` version. Once we have shifted all of `litd`'s code to use the `sqldb/v2` definition, we will remove the `litd` version.
1 parent 4012073 commit ae8370a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

db/postgres.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
postgres_migrate "github.com/golang-migrate/migrate/v4/database/postgres"
1010
_ "github.com/golang-migrate/migrate/v4/source/file"
1111
"github.com/lightninglabs/lightning-terminal/db/sqlc"
12+
"github.com/lightningnetwork/lnd/sqldb/v2"
1213
"github.com/stretchr/testify/require"
1314
)
1415

@@ -164,8 +165,26 @@ func (s *PostgresStore) ExecuteMigrations(target MigrationTarget,
164165
)
165166
}
166167

168+
// NewTestPostgresV2DB is a helper function that creates a Postgres database for
169+
// testing, using the sqldb v2 package's definition of the PostgresStore.
170+
func NewTestPostgresV2DB(t *testing.T) *sqldb.PostgresStore {
171+
t.Helper()
172+
173+
t.Logf("Creating new Postgres DB for testing")
174+
175+
sqlFixture := sqldb.NewTestPgFixture(t, DefaultPostgresFixtureLifetime)
176+
t.Cleanup(func() {
177+
sqlFixture.TearDown(t)
178+
})
179+
180+
return sqldb.NewTestPostgresDB(t, sqlFixture, LitdMigrationStreams)
181+
}
182+
167183
// NewTestPostgresDB is a helper function that creates a Postgres database for
168-
// testing.
184+
// testing, using the litd db package's definition of the PostgresStore.
185+
//
186+
// TODO(viktor): remove this once the sqldb v2 package is implemented in
187+
// all of litd's packages.
169188
func NewTestPostgresDB(t *testing.T) *PostgresStore {
170189
t.Helper()
171190

0 commit comments

Comments
 (0)