Skip to content

Commit abb4781

Browse files
firewalldb: refactor execution of mig test assert
Since the `assertMigrationResults` now expects a `*sqlcmig6.Queries` instance to be passed directly into the function, there is no need to create a separate *sqlcmig6.Queries instance than the one created when the `*sqlcmig6.TxExecutor` transaction is created. We therefore refactor the execution of the `assertMigrationResults` function to be called in the scope of that transaction. Due to this change, there's also no longer a need to return the `*SQLDB` instance from the `makeSQLDB` helper function.
1 parent 2c246ce commit abb4781

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

firewalldb/sql_migration_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func TestFirewallDBMigration(t *testing.T) {
5656
t.Skipf("Skipping Firewall DB migration test for kvdb build")
5757
}
5858

59-
makeSQLDB := func(t *testing.T, sStore session.Store) (*SQLDB,
60-
*sqlcmig6.TxExecutor[*sqlcmig6.Queries]) {
59+
makeSQLDB := func(t *testing.T,
60+
sStore session.Store) *sqlcmig6.TxExecutor[*sqlcmig6.Queries] {
6161

6262
testDBStore := NewTestDBWithSessions(t, sStore, clock)
6363

@@ -68,7 +68,7 @@ func TestFirewallDBMigration(t *testing.T) {
6868

6969
queries := sqlcmig6.NewForType(baseDB, baseDB.BackendType)
7070

71-
return store, sqlcmig6.NewTxExecutor(baseDB, queries)
71+
return sqlcmig6.NewTxExecutor(baseDB, queries)
7272
}
7373

7474
// The assertKvStoreMigrationResults function will currently assert that
@@ -384,23 +384,25 @@ func TestFirewallDBMigration(t *testing.T) {
384384

385385
// Create the SQL store that we will migrate the data
386386
// to.
387-
sqlStore, txEx := makeSQLDB(t, sessionsStore)
387+
txEx := makeSQLDB(t, sessionsStore)
388388

389389
// Perform the migration.
390390
err = txEx.ExecTx(ctx, sqldb.WriteTxOpt(),
391391
func(tx *sqlcmig6.Queries) error {
392-
return MigrateFirewallDBToSQL(
392+
err = MigrateFirewallDBToSQL(
393393
ctx, firewallStore.DB, tx,
394394
)
395+
if err != nil {
396+
return err
397+
}
398+
399+
// Assert migration results.
400+
assertMigrationResults(t, tx, entries)
401+
402+
return nil
395403
}, sqldb.NoOpReset,
396404
)
397405
require.NoError(t, err)
398-
399-
// Assert migration results.
400-
queries := sqlcmig6.NewForType(
401-
sqlStore, sqlStore.BackendType,
402-
)
403-
assertMigrationResults(t, queries, entries)
404406
})
405407
}
406408
}

0 commit comments

Comments
 (0)