mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
We add a helper function to the functions that creates the test SQL stores, in order to ensure that the store is properly closed when the test is cleaned up.
32 lines
809 B
Go
32 lines
809 B
Go
//go:build test_db_postgres || test_db_sqlite
|
|
|
|
package session
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/lightninglabs/lightning-terminal/accounts"
|
|
"github.com/lightninglabs/lightning-terminal/db"
|
|
"github.com/lightningnetwork/lnd/clock"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func NewTestDBWithAccounts(t *testing.T, clock clock.Clock,
|
|
acctStore accounts.Store) Store {
|
|
|
|
accounts, ok := acctStore.(*accounts.SQLStore)
|
|
require.True(t, ok)
|
|
|
|
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.
|
|
func createStore(t *testing.T, sqlDB *db.BaseDB, clock clock.Clock) *SQLStore {
|
|
store := NewSQLStore(sqlDB, clock)
|
|
t.Cleanup(func() {
|
|
require.NoError(t, store.Close())
|
|
})
|
|
|
|
return store
|
|
}
|