Files
lnd/graph/db/test_postgres.go
Elle Mouton 5d7abcdf03 graph/db: refactor SQL DB creation files
Factor out the transaction executor construction so that we can have
access to the raw BatchedSQLQueries type from within tests.
2025-07-07 08:36:12 +02:00

30 lines
607 B
Go

//go:build test_db_postgres && !test_db_sqlite
package graphdb
import (
"database/sql"
"testing"
"github.com/lightningnetwork/lnd/sqldb"
)
// newBatchQuerier creates a new BatchedSQLQueries instance for testing
// using a PostgreSQL database fixture.
func newBatchQuerier(t testing.TB) BatchedSQLQueries {
pgFixture := sqldb.NewTestPgFixture(
t, sqldb.DefaultPostgresFixtureLifetime,
)
t.Cleanup(func() {
pgFixture.TearDown(t)
})
db := sqldb.NewTestPostgresDB(t, pgFixture).BaseDB
return sqldb.NewTransactionExecutor(
db, func(tx *sql.Tx) SQLQueries {
return db.WithTx(tx)
},
)
}