lightning-terminal/session/test_kvdb.go
Viktor Tigerström b48e40f000
session: update NewTestDB funcs to return Store
In preparation for upcoming migration tests from a kvdb to an SQL store,
this commit updates the NewTestDB function to return the Store interface
rather than a concrete store implementation.

This change ensures that migration tests can call NewTestDB under any
build tag while receiving a consistent return type.
2025-06-12 11:52:38 +02:00

47 lines
1.3 KiB
Go

//go:build !test_db_postgres && !test_db_sqlite
package session
import (
"testing"
"github.com/lightninglabs/lightning-terminal/accounts"
"github.com/lightningnetwork/lnd/clock"
"github.com/stretchr/testify/require"
)
// NewTestDB is a helper function that creates an BBolt database for testing.
func NewTestDB(t *testing.T, clock clock.Clock) Store {
return NewTestDBFromPath(t, t.TempDir(), clock)
}
// NewTestDBFromPath is a helper function that creates a new BoltStore with a
// connection to an existing BBolt database for testing.
func NewTestDBFromPath(t *testing.T, dbPath string,
clock clock.Clock) Store {
acctStore := accounts.NewTestDB(t, clock)
return newDBFromPathWithAccounts(t, clock, dbPath, acctStore)
}
// NewTestDBWithAccounts creates a new test session Store with access to an
// existing accounts DB.
func NewTestDBWithAccounts(t *testing.T, clock clock.Clock,
acctStore accounts.Store) Store {
return newDBFromPathWithAccounts(t, clock, t.TempDir(), acctStore)
}
func newDBFromPathWithAccounts(t *testing.T, clock clock.Clock, dbPath string,
acctStore accounts.Store) Store {
store, err := NewDB(dbPath, DBFilename, clock, acctStore)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, store.DB.Close())
})
return store
}