From 383453635b2f83d8f5b94aff786b52900adbb5ad Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Sat, 5 Apr 2025 19:11:24 +0200 Subject: [PATCH] sqldb+go.mod: update sqldb test methods Update the test methods to take a `testing.TB` param instead of a `*testing.T` so that the test functions can be used for all the graph's tests including benchmark tests. We also add a temporary replace so that we can make use of these changes and also since we will soon be adding graph related schemas and queries in this submodule that we'll want to have access to. --- go.mod | 4 ++++ go.sum | 2 -- sqldb/postgres_fixture.go | 8 ++++---- sqldb/sqlite.go | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 1dd775257..8cdddddb5 100644 --- a/go.mod +++ b/go.mod @@ -199,6 +199,10 @@ require ( sigs.k8s.io/yaml v1.2.0 // indirect ) +// TODO(elle): remove once all the schemas and queries for the graph +// store have been included in a tagged sqldb version. +replace github.com/lightningnetwork/lnd/sqldb => ./sqldb + // This replace is for https://github.com/advisories/GHSA-25xm-hr59-7c27 replace github.com/ulikunitz/xz => github.com/ulikunitz/xz v0.5.11 diff --git a/go.sum b/go.sum index cc17829d6..1593ff474 100644 --- a/go.sum +++ b/go.sum @@ -375,8 +375,6 @@ github.com/lightningnetwork/lnd/kvdb v1.4.16 h1:9BZgWdDfjmHRHLS97cz39bVuBAqMc4/p github.com/lightningnetwork/lnd/kvdb v1.4.16/go.mod h1:HW+bvwkxNaopkz3oIgBV6NEnV4jCEZCACFUcNg4xSjM= github.com/lightningnetwork/lnd/queue v1.1.1 h1:99ovBlpM9B0FRCGYJo6RSFDlt8/vOkQQZznVb18iNMI= github.com/lightningnetwork/lnd/queue v1.1.1/go.mod h1:7A6nC1Qrm32FHuhx/mi1cieAiBZo5O6l8IBIoQxvkz4= -github.com/lightningnetwork/lnd/sqldb v1.0.9 h1:7OHi+Hui823mB/U9NzCdlZTAGSVdDCbjp33+6d/Q+G0= -github.com/lightningnetwork/lnd/sqldb v1.0.9/go.mod h1:OG09zL/PHPaBJefp4HsPz2YLUJ+zIQHbpgCtLnOx8I4= github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6ijJlbdiZFbSM= github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA= github.com/lightningnetwork/lnd/tlv v1.3.1 h1:o7CZg06y+rJZfUMAo0WzBLr0pgBWCzrt0f9gpujYUzk= diff --git a/sqldb/postgres_fixture.go b/sqldb/postgres_fixture.go index d7814df78..91b95d66e 100644 --- a/sqldb/postgres_fixture.go +++ b/sqldb/postgres_fixture.go @@ -39,7 +39,7 @@ type TestPgFixture struct { // NewTestPgFixture constructs a new TestPgFixture starting up a docker // container running Postgres 11. The started container will expire in after // the passed duration. -func NewTestPgFixture(t *testing.T, expiry time.Duration) *TestPgFixture { +func NewTestPgFixture(t testing.TB, expiry time.Duration) *TestPgFixture { // Use a sensible default on Windows (tcp/http) and linux/osx (socket) // by specifying an empty endpoint. pool, err := dockertest.NewPool("") @@ -119,13 +119,13 @@ func (f *TestPgFixture) GetConfig(dbName string) *PostgresConfig { } // TearDown stops the underlying docker container. -func (f *TestPgFixture) TearDown(t *testing.T) { +func (f *TestPgFixture) TearDown(t testing.TB) { err := f.pool.Purge(f.resource) require.NoError(t, err, "Could not purge resource") } // randomDBName generates a random database name. -func randomDBName(t *testing.T) string { +func randomDBName(t testing.TB) string { randBytes := make([]byte, 8) _, err := rand.Read(randBytes) require.NoError(t, err) @@ -135,7 +135,7 @@ func randomDBName(t *testing.T) string { // NewTestPostgresDB is a helper function that creates a Postgres database for // testing using the given fixture. -func NewTestPostgresDB(t *testing.T, fixture *TestPgFixture) *PostgresStore { +func NewTestPostgresDB(t testing.TB, fixture *TestPgFixture) *PostgresStore { t.Helper() dbName := randomDBName(t) diff --git a/sqldb/sqlite.go b/sqldb/sqlite.go index a542a9b63..2b2f7be13 100644 --- a/sqldb/sqlite.go +++ b/sqldb/sqlite.go @@ -220,7 +220,7 @@ func (s *SqliteStore) SetSchemaVersion(version int, dirty bool) error { // NewTestSqliteDB is a helper function that creates an SQLite database for // testing. -func NewTestSqliteDB(t *testing.T) *SqliteStore { +func NewTestSqliteDB(t testing.TB) *SqliteStore { t.Helper() t.Logf("Creating new SQLite DB for testing")