2025-03-02 08:37:19 +02:00
|
|
|
//go:build test_db_postgres || test_db_sqlite
|
|
|
|
|
|
|
|
|
|
package session
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/lightninglabs/lightning-terminal/accounts"
|
2025-07-22 12:21:06 +02:00
|
|
|
"github.com/lightninglabs/lightning-terminal/db/sqlc"
|
2025-03-02 08:37:19 +02:00
|
|
|
"github.com/lightningnetwork/lnd/clock"
|
2025-07-22 12:21:06 +02:00
|
|
|
"github.com/lightningnetwork/lnd/sqldb/v2"
|
2025-03-02 08:37:19 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func NewTestDBWithAccounts(t *testing.T, clock clock.Clock,
|
2025-04-30 00:12:39 +07:00
|
|
|
acctStore accounts.Store) Store {
|
2025-03-02 08:37:19 +02:00
|
|
|
|
|
|
|
|
accounts, ok := acctStore.(*accounts.SQLStore)
|
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
2025-06-08 13:31:03 +02:00
|
|
|
return createStore(t, accounts.BaseDB, clock)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// createStore is a helper function that creates a new SQLStore and ensure that
|
|
|
|
|
// it is closed when during the test cleanup.
|
2025-07-22 12:21:06 +02:00
|
|
|
func createStore(t *testing.T, sqlDB *sqldb.BaseDB,
|
|
|
|
|
clock clock.Clock) *SQLStore {
|
|
|
|
|
|
|
|
|
|
queries := sqlc.NewForType(sqlDB, sqlDB.BackendType)
|
|
|
|
|
|
|
|
|
|
store := NewSQLStore(sqlDB, queries, clock)
|
2025-06-08 13:31:03 +02:00
|
|
|
t.Cleanup(func() {
|
|
|
|
|
require.NoError(t, store.Close())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return store
|
2025-03-02 08:37:19 +02:00
|
|
|
}
|