paymentsdb: add harness to run payment db agnostic tests
In commit adds the harness which will be used to run db agnostic tests against the kv and sql backend. We have adopted all the unit tests so far so that with this commit all the payment tests not specifically put into the kv_store_test.go should all pass for all backends.
This commit is contained in:
3 files changed
+135
No files matched your search
@@ -0,0 +1,56 @@
|
||||
//go:build !test_db_postgres && test_db_sqlite
|
||||
|
||||
package paymentsdb
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
|
||||
"github.com/lightningnetwork/lnd/sqldb"
|
||||
"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, opts ...OptionModifier) DB {
|
||||
return NewTestDBWithFixture(t, nil, opts...)
|
||||
}
|
||||
|
||||
// NewTestDBFixture is a no-op for the sqlite build.
|
||||
func NewTestDBFixture(_ *testing.T) *sqldb.TestPgFixture {
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewTestDBWithFixture is a helper function that creates a SQLStore backed by a
|
||||
// SQL database for testing.
|
||||
func NewTestDBWithFixture(t testing.TB, _ *sqldb.TestPgFixture,
|
||||
opts ...OptionModifier) DB {
|
||||
|
||||
store, err := NewSQLStore(
|
||||
&SQLStoreConfig{
|
||||
QueryCfg: sqldb.DefaultSQLiteConfig(),
|
||||
}, newBatchQuerier(t), opts...,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
return store
|
||||
}
|
||||
|
||||
// newBatchQuerier creates a new BatchedSQLQueries instance for testing
|
||||
// using a SQLite database.
|
||||
func newBatchQuerier(t testing.TB) BatchedSQLQueries {
|
||||
return newBatchQuerierWithFixture(t, nil)
|
||||
}
|
||||
|
||||
// newBatchQuerierWithFixture creates a new BatchedSQLQueries instance for
|
||||
// testing using a SQLite database.
|
||||
func newBatchQuerierWithFixture(t testing.TB,
|
||||
_ *sqldb.TestPgFixture) BatchedSQLQueries {
|
||||
|
||||
db := sqldb.NewTestSqliteDB(t).BaseDB
|
||||
|
||||
return sqldb.NewTransactionExecutor(
|
||||
db, func(tx *sql.Tx) SQLQueries {
|
||||
return db.WithTx(tx)
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user