Skip to content

Commit 97ad86d

Browse files
firewalldb: update NewTestDB funcs to return FirewallDBs
In the upcoming migration of the firewall database to SQL, the helper functions that creates the test databases of different types, need to return a unified interface in order to not have to control the migration tests file by build tags. Therefore, we update the `NewTestDB` functions to return the `FirewallDBs` interface instead of the specific store implementation type.
1 parent 27cfc39 commit 97ad86d

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

firewalldb/test_kvdb.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,46 @@ import (
66
"testing"
77

88
"github.com/lightninglabs/lightning-terminal/accounts"
9+
"github.com/lightninglabs/lightning-terminal/session"
910
"github.com/lightningnetwork/lnd/clock"
1011
"github.com/lightningnetwork/lnd/fn"
1112
"github.com/stretchr/testify/require"
1213
)
1314

1415
// NewTestDB is a helper function that creates an BBolt database for testing.
15-
func NewTestDB(t *testing.T, clock clock.Clock) *BoltDB {
16+
func NewTestDB(t *testing.T, clock clock.Clock) FirewallDBs {
1617
return NewTestDBFromPath(t, t.TempDir(), clock)
1718
}
1819

1920
// NewTestDBFromPath is a helper function that creates a new BoltStore with a
2021
// connection to an existing BBolt database for testing.
21-
func NewTestDBFromPath(t *testing.T, dbPath string, clock clock.Clock) *BoltDB {
22+
func NewTestDBFromPath(t *testing.T, dbPath string,
23+
clock clock.Clock) FirewallDBs {
24+
2225
return newDBFromPathWithSessions(t, dbPath, nil, nil, clock)
2326
}
2427

2528
// NewTestDBWithSessions creates a new test BoltDB Store with access to an
2629
// existing sessions DB.
27-
func NewTestDBWithSessions(t *testing.T, sessStore SessionDB,
28-
clock clock.Clock) *BoltDB {
30+
func NewTestDBWithSessions(t *testing.T, sessStore session.Store,
31+
clock clock.Clock) FirewallDBs {
2932

3033
return newDBFromPathWithSessions(t, t.TempDir(), sessStore, nil, clock)
3134
}
3235

3336
// NewTestDBWithSessionsAndAccounts creates a new test BoltDB Store with access
3437
// to an existing sessions DB and accounts DB.
35-
func NewTestDBWithSessionsAndAccounts(t *testing.T, sessStore SessionDB,
36-
acctStore AccountsDB, clock clock.Clock) *BoltDB {
38+
func NewTestDBWithSessionsAndAccounts(t *testing.T, sessStore session.Store,
39+
acctStore AccountsDB, clock clock.Clock) FirewallDBs {
3740

3841
return newDBFromPathWithSessions(
3942
t, t.TempDir(), sessStore, acctStore, clock,
4043
)
4144
}
4245

4346
func newDBFromPathWithSessions(t *testing.T, dbPath string,
44-
sessStore SessionDB, acctStore AccountsDB, clock clock.Clock) *BoltDB {
47+
sessStore session.Store, acctStore AccountsDB,
48+
clock clock.Clock) FirewallDBs {
4549

4650
store, err := NewBoltDB(dbPath, DBFilename, sessStore, acctStore, clock)
4751
require.NoError(t, err)

firewalldb/test_postgres.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
)
1111

1212
// NewTestDB is a helper function that creates an BBolt database for testing.
13-
func NewTestDB(t *testing.T, clock clock.Clock) *SQLDB {
13+
func NewTestDB(t *testing.T, clock clock.Clock) FirewallDBs {
1414
return createStore(t, db.NewTestPostgresDB(t).BaseDB, clock)
1515
}
1616

1717
// NewTestDBFromPath is a helper function that creates a new BoltStore with a
1818
// connection to an existing BBolt database for testing.
19-
func NewTestDBFromPath(t *testing.T, _ string, clock clock.Clock) *SQLDB {
19+
func NewTestDBFromPath(t *testing.T, _ string, clock clock.Clock) FirewallDBs {
2020
return createStore(t, db.NewTestPostgresDB(t).BaseDB, clock)
2121
}

firewalldb/test_sql.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import (
1616
// NewTestDBWithSessions creates a new test SQLDB Store with access to an
1717
// existing sessions DB.
1818
func NewTestDBWithSessions(t *testing.T, sessionStore session.Store,
19-
clock clock.Clock) *SQLDB {
20-
19+
clock clock.Clock) FirewallDBs {
2120
sessions, ok := sessionStore.(*session.SQLStore)
2221
require.True(t, ok)
2322

@@ -27,7 +26,7 @@ func NewTestDBWithSessions(t *testing.T, sessionStore session.Store,
2726
// NewTestDBWithSessionsAndAccounts creates a new test SQLDB Store with access
2827
// to an existing sessions DB and accounts DB.
2928
func NewTestDBWithSessionsAndAccounts(t *testing.T, sessionStore SessionDB,
30-
acctStore AccountsDB, clock clock.Clock) *SQLDB {
29+
acctStore AccountsDB, clock clock.Clock) FirewallDBs {
3130

3231
sessions, ok := sessionStore.(*session.SQLStore)
3332
require.True(t, ok)

firewalldb/test_sqlite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
)
1111

1212
// NewTestDB is a helper function that creates an BBolt database for testing.
13-
func NewTestDB(t *testing.T, clock clock.Clock) *SQLDB {
13+
func NewTestDB(t *testing.T, clock clock.Clock) FirewallDBs {
1414
return createStore(t, db.NewTestSqliteDB(t).BaseDB, clock)
1515
}
1616

1717
// NewTestDBFromPath is a helper function that creates a new BoltStore with a
1818
// connection to an existing BBolt database for testing.
19-
func NewTestDBFromPath(t *testing.T, dbPath string, clock clock.Clock) *SQLDB {
19+
func NewTestDBFromPath(t *testing.T, dbPath string, clock clock.Clock) FirewallDBs {
2020
return createStore(
2121
t, db.NewTestSqliteDbHandleFromPath(t, dbPath).BaseDB, clock,
2222
)

0 commit comments

Comments
 (0)