mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
accounts: ensure that test SQL store is closed
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.
This commit is contained in:
parent
8986d41616
commit
12343cf4ba
4 changed files with 27 additions and 8 deletions
|
|
@ -39,9 +39,6 @@ func TestAccountStoreMigration(t *testing.T) {
|
|||
*db.TransactionExecutor[SQLQueries]) {
|
||||
|
||||
testDBStore := NewTestDB(t, clock)
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, testDBStore.Close())
|
||||
})
|
||||
|
||||
store, ok := testDBStore.(*SQLStore)
|
||||
require.True(t, ok)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ var ErrDBClosed = errors.New("database is closed")
|
|||
|
||||
// NewTestDB is a helper function that creates an SQLStore database for testing.
|
||||
func NewTestDB(t *testing.T, clock clock.Clock) Store {
|
||||
return NewSQLStore(db.NewTestPostgresDB(t).BaseDB, clock)
|
||||
return createStore(t, db.NewTestPostgresDB(t).BaseDB, clock)
|
||||
}
|
||||
|
||||
// NewTestDBFromPath is a helper function that creates a new SQLStore with a
|
||||
|
|
@ -24,5 +24,5 @@ func NewTestDB(t *testing.T, clock clock.Clock) Store {
|
|||
func NewTestDBFromPath(t *testing.T, dbPath string,
|
||||
clock clock.Clock) Store {
|
||||
|
||||
return NewSQLStore(db.NewTestPostgresDB(t).BaseDB, clock)
|
||||
return createStore(t, db.NewTestPostgresDB(t).BaseDB, clock)
|
||||
}
|
||||
|
|
|
|||
22
accounts/test_sql.go
Normal file
22
accounts/test_sql.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
//go:build test_db_postgres || test_db_sqlite
|
||||
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lightninglabs/lightning-terminal/db"
|
||||
"github.com/lightningnetwork/lnd/clock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ var ErrDBClosed = errors.New("database is closed")
|
|||
|
||||
// NewTestDB is a helper function that creates an SQLStore database for testing.
|
||||
func NewTestDB(t *testing.T, clock clock.Clock) Store {
|
||||
return NewSQLStore(db.NewTestSqliteDB(t).BaseDB, clock)
|
||||
return createStore(t, db.NewTestSqliteDB(t).BaseDB, clock)
|
||||
}
|
||||
|
||||
// NewTestDBFromPath is a helper function that creates a new SQLStore with a
|
||||
|
|
@ -24,7 +24,7 @@ func NewTestDB(t *testing.T, clock clock.Clock) Store {
|
|||
func NewTestDBFromPath(t *testing.T, dbPath string,
|
||||
clock clock.Clock) Store {
|
||||
|
||||
return NewSQLStore(
|
||||
db.NewTestSqliteDbHandleFromPath(t, dbPath).BaseDB, clock,
|
||||
return createStore(
|
||||
t, db.NewTestSqliteDbHandleFromPath(t, dbPath).BaseDB, clock,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue