mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
In this commit, we add the SQLStore type which implements the accounts.Store interface. To demonstrate that it works as expected, we also plug this implementation into all the account unit tests to show that they pass against the sqlite and postgres backends. One can use `make unit pkg=accounts tags=test_db_postgres` or `make unit pkg=accounts tags=test_db_sqlite` to test locally. Note that 2 small timestamp related changes are made to the unit tests. This is to compensate for timestamp precision in postgres.
28 lines
837 B
Go
28 lines
837 B
Go
//go:build test_db_postgres && !test_db_sqlite
|
|
|
|
package accounts
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/lightninglabs/lightning-terminal/db"
|
|
"github.com/lightningnetwork/lnd/clock"
|
|
)
|
|
|
|
// ErrDBClosed is an error that is returned when a database operation is
|
|
// performed on a closed database.
|
|
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) *SQLStore {
|
|
return NewSQLStore(db.NewTestPostgresDB(t).BaseDB, clock)
|
|
}
|
|
|
|
// NewTestDBFromPath is a helper function that creates a new SQLStore with a
|
|
// connection to an existing postgres database for testing.
|
|
func NewTestDBFromPath(t *testing.T, dbPath string,
|
|
clock clock.Clock) *SQLStore {
|
|
|
|
return NewSQLStore(db.NewTestPostgresDB(t).BaseDB, clock)
|
|
}
|