faraday/chanevents/test_postgres.go
bitromortac 85f0a261a4 chanevents+db: widen test fixtures to testing.TB
Promote the existing test-store and test-DB constructors from
*testing.T to testing.TB so the upcoming EffectiveUptime benchmark can
share the same fixture path as the existing tests. testing.TB is the
shared interface of *testing.T and *testing.B, so every current caller
keeps type-checking unchanged.
2026-06-03 17:55:30 +02:00

29 lines
799 B
Go

//go:build test_db_postgres
package chanevents
import (
"testing"
"github.com/lightninglabs/faraday/db"
"github.com/lightningnetwork/lnd/clock"
"github.com/stretchr/testify/require"
)
// NewTestDB creates a new test chanevents.Store backed by a postgres DB.
func NewTestDB(t testing.TB, clock clock.Clock) *Store {
// We'll create a new test database. The call to NewTestPostgresDB will
// automatically create the DB and apply the migrations.
testDB := db.NewTestPostgresDB(t)
// Now, we'll create the FaradayDB instance from the test database. The
// FaradayDB is the main database object that holds the connection and
// the generated querier.
faradayDB := createStore(t, testDB.BaseDB, clock)
t.Cleanup(func() {
require.NoError(t, faradayDB.Close())
})
return faradayDB
}