paymentsdb: introduce a harness interface

The design of the sql and kv db are a bit different. A harness
interface is introduced which allows us to unit most of the test
and keep the backend specific tests at a minimum.
This commit is contained in:
ziggie committed 2026-02-25 08:02:17 +01:00
1 parent 570863ca26
commit 080fd78fb4
6 files changed
+162 -101

No files matched your search

+20 -2
View File
@@ -6,14 +6,16 @@ import (
"database/sql"
"testing"
"github.com/lightningnetwork/lnd/lntypes"
"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...)
func NewTestDB(t testing.TB, opts ...OptionModifier) (DB, TestHarness) {
db := NewTestDBWithFixture(t, nil, opts...)
return db, &noopTestHarness{}
}
// NewTestDBFixture is a no-op for the sqlite build.
@@ -54,3 +56,19 @@ func newBatchQuerierWithFixture(t testing.TB,
},
)
}
// noopTestHarness is the SQL test harness implementation. Since SQL doesn't
// use a separate payment index bucket like KV, these assertions are no-ops.
type noopTestHarness struct{}
// AssertPaymentIndex is a no-op for SQL implementations.
func (h *noopTestHarness) AssertPaymentIndex(t *testing.T,
expectedHash lntypes.Hash) {
// No-op: SQL doesn't use a separate index bucket.
}
// AssertNoIndex is a no-op for SQL implementations.
func (h *noopTestHarness) AssertNoIndex(t *testing.T, seqNr uint64) {
// No-op: SQL doesn't use a separate index bucket.
}