diff --git a/graph/db/test_postgres.go b/graph/db/test_postgres.go index 8067756e2..7af420d19 100644 --- a/graph/db/test_postgres.go +++ b/graph/db/test_postgres.go @@ -6,14 +6,12 @@ import ( "database/sql" "testing" - "github.com/btcsuite/btcd/chaincfg" "github.com/lightningnetwork/lnd/sqldb" - "github.com/stretchr/testify/require" ) -// NewTestDB is a helper function that creates a SQLStore backed by a postgres -// database for testing. -func NewTestDB(t testing.TB) V1Store { +// 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, ) @@ -23,18 +21,9 @@ func NewTestDB(t testing.TB) V1Store { db := sqldb.NewTestPostgresDB(t, pgFixture).BaseDB - executor := sqldb.NewTransactionExecutor( + return sqldb.NewTransactionExecutor( db, func(tx *sql.Tx) SQLQueries { return db.WithTx(tx) }, ) - - store, err := NewSQLStore( - &SQLStoreConfig{ - ChainHash: *chaincfg.MainNetParams.GenesisHash, - }, executor, - ) - require.NoError(t, err) - - return store } diff --git a/graph/db/test_sql.go b/graph/db/test_sql.go new file mode 100644 index 000000000..9d4d507b3 --- /dev/null +++ b/graph/db/test_sql.go @@ -0,0 +1,23 @@ +//go:build test_db_postgres || test_db_sqlite + +package graphdb + +import ( + "testing" + + "github.com/btcsuite/btcd/chaincfg" + "github.com/stretchr/testify/require" +) + +// NewTestDB is a helper function that creates a SQLStore backed by a SQL +// database for testing. +func NewTestDB(t testing.TB) V1Store { + store, err := NewSQLStore( + &SQLStoreConfig{ + ChainHash: *chaincfg.MainNetParams.GenesisHash, + }, newBatchQuerier(t), + ) + require.NoError(t, err) + + return store +} diff --git a/graph/db/test_sqlite.go b/graph/db/test_sqlite.go index 2af105259..35f7cb5d8 100644 --- a/graph/db/test_sqlite.go +++ b/graph/db/test_sqlite.go @@ -6,28 +6,17 @@ import ( "database/sql" "testing" - "github.com/btcsuite/btcd/chaincfg" "github.com/lightningnetwork/lnd/sqldb" - "github.com/stretchr/testify/require" ) -// NewTestDB is a helper function that creates a SQLStore backed by a sqlite -// database for testing. -func NewTestDB(t testing.TB) V1Store { +// newBatchQuerier creates a new BatchedSQLQueries instance for testing +// using a SQLite database. +func newBatchQuerier(t testing.TB) BatchedSQLQueries { db := sqldb.NewTestSqliteDB(t).BaseDB - executor := sqldb.NewTransactionExecutor( + return sqldb.NewTransactionExecutor( db, func(tx *sql.Tx) SQLQueries { return db.WithTx(tx) }, ) - - store, err := NewSQLStore( - &SQLStoreConfig{ - ChainHash: *chaincfg.MainNetParams.GenesisHash, - }, executor, - ) - require.NoError(t, err) - - return store }