Skip to content

Commit efe82a6

Browse files
firewalldb: use sqldb/v2 in the firewalldb mig test
1 parent b8c772b commit efe82a6

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

firewalldb/sql_migration_test.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import (
99
"time"
1010

1111
"github.com/lightninglabs/lightning-terminal/accounts"
12-
"github.com/lightninglabs/lightning-terminal/db"
1312
"github.com/lightninglabs/lightning-terminal/db/sqlc"
1413
"github.com/lightninglabs/lightning-terminal/session"
1514
"github.com/lightningnetwork/lnd/clock"
1615
"github.com/lightningnetwork/lnd/fn"
17-
"github.com/lightningnetwork/lnd/sqldb"
16+
"github.com/lightningnetwork/lnd/sqldb/v2"
1817
"github.com/stretchr/testify/require"
1918
"golang.org/x/exp/rand"
2019
)
@@ -54,7 +53,7 @@ func TestFirewallDBMigration(t *testing.T) {
5453
}
5554

5655
makeSQLDB := func(t *testing.T, sessionsStore session.Store) (*SQLDB,
57-
*db.TransactionExecutor[SQLQueries]) {
56+
*SQLQueriesExecutor[SQLQueries]) {
5857

5958
testDBStore := NewTestDBWithSessions(t, sessionsStore, clock)
6059

@@ -63,13 +62,9 @@ func TestFirewallDBMigration(t *testing.T) {
6362

6463
baseDB := store.BaseDB
6564

66-
genericExecutor := db.NewTransactionExecutor(
67-
baseDB, func(tx *sql.Tx) SQLQueries {
68-
return baseDB.WithTx(tx)
69-
},
70-
)
65+
queries := sqlc.NewForType(baseDB, baseDB.BackendType)
7166

72-
return store, genericExecutor
67+
return store, NewSQLQueriesExecutor(baseDB, queries)
7368
}
7469

7570
// The assertMigrationResults function will currently assert that
@@ -88,7 +83,9 @@ func TestFirewallDBMigration(t *testing.T) {
8883
getRuleID := func(ruleName string) int64 {
8984
ruleID, ok := ruleIDs[ruleName]
9085
if !ok {
91-
ruleID, err = store.GetRuleID(ctx, ruleName)
86+
ruleID, err = store.db.GetRuleID(
87+
ctx, ruleName,
88+
)
9289
require.NoError(t, err)
9390

9491
ruleIDs[ruleName] = ruleID
@@ -100,7 +97,7 @@ func TestFirewallDBMigration(t *testing.T) {
10097
getGroupID := func(groupAlias []byte) int64 {
10198
groupID, ok := groupIDs[string(groupAlias)]
10299
if !ok {
103-
groupID, err = store.GetSessionIDByAlias(
100+
groupID, err = store.db.GetSessionIDByAlias(
104101
ctx, groupAlias,
105102
)
106103
require.NoError(t, err)
@@ -114,7 +111,7 @@ func TestFirewallDBMigration(t *testing.T) {
114111
getFeatureID := func(featureName string) int64 {
115112
featureID, ok := featureIDs[featureName]
116113
if !ok {
117-
featureID, err = store.GetFeatureID(
114+
featureID, err = store.db.GetFeatureID(
118115
ctx, featureName,
119116
)
120117
require.NoError(t, err)
@@ -128,7 +125,7 @@ func TestFirewallDBMigration(t *testing.T) {
128125
// First we extract all migrated kv entries from the SQLDB,
129126
// in order to be able to compare them to the original kv
130127
// entries, to ensure that the migration was successful.
131-
sqlKvEntries, err := store.ListAllKVStoresRecords(ctx)
128+
sqlKvEntries, err := store.db.ListAllKVStoresRecords(ctx)
132129
require.NoError(t, err)
133130
require.Equal(t, len(kvEntries), len(sqlKvEntries))
134131

@@ -144,7 +141,7 @@ func TestFirewallDBMigration(t *testing.T) {
144141
ruleID := getRuleID(entry.ruleName)
145142

146143
if entry.groupAlias.IsNone() {
147-
sqlVal, err := store.GetGlobalKVStoreRecord(
144+
sqlVal, err := store.db.GetGlobalKVStoreRecord(
148145
ctx,
149146
sqlc.GetGlobalKVStoreRecordParams{
150147
Key: entry.key,
@@ -162,7 +159,7 @@ func TestFirewallDBMigration(t *testing.T) {
162159
groupAlias := entry.groupAlias.UnwrapOrFail(t)
163160
groupID := getGroupID(groupAlias[:])
164161

165-
v, err := store.GetGroupKVStoreRecord(
162+
v, err := store.db.GetGroupKVStoreRecord(
166163
ctx,
167164
sqlc.GetGroupKVStoreRecordParams{
168165
Key: entry.key,
@@ -187,7 +184,7 @@ func TestFirewallDBMigration(t *testing.T) {
187184
entry.featureName.UnwrapOrFail(t),
188185
)
189186

190-
sqlVal, err := store.GetFeatureKVStoreRecord(
187+
sqlVal, err := store.db.GetFeatureKVStoreRecord(
191188
ctx,
192189
sqlc.GetFeatureKVStoreRecordParams{
193190
Key: entry.key,
@@ -302,7 +299,7 @@ func TestFirewallDBMigration(t *testing.T) {
302299
return MigrateFirewallDBToSQL(
303300
ctx, firewallStore.DB, tx,
304301
)
305-
},
302+
}, sqldb.NoOpReset,
306303
)
307304
require.NoError(t, err)
308305

0 commit comments

Comments
 (0)