mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-28 21:44:13 +02:00
channeldb: add shouldFail param to ApplyMigrationWithDB
Add a shouldFail boolean parameter to the migtest ApplyMigrationWithDB in order to make it easier to test migration failures.
This commit is contained in:
@@ -108,6 +108,7 @@ func TestMigrateRevocationLog(t *testing.T) {
|
|||||||
beforeMigration,
|
beforeMigration,
|
||||||
afterMigration,
|
afterMigration,
|
||||||
MigrateRevocationLog,
|
MigrateRevocationLog,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
if !success {
|
if !success {
|
||||||
@@ -569,5 +570,6 @@ func BenchmarkMigration(b *testing.B) {
|
|||||||
|
|
||||||
return MigrateRevocationLog(db)
|
return MigrateRevocationLog(db)
|
||||||
},
|
},
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -90,7 +90,7 @@ func ApplyMigration(t *testing.T,
|
|||||||
// supplied migration functions to take a db instance and construct their own
|
// supplied migration functions to take a db instance and construct their own
|
||||||
// database transactions.
|
// database transactions.
|
||||||
func ApplyMigrationWithDb(t testing.TB, beforeMigration, afterMigration,
|
func ApplyMigrationWithDb(t testing.TB, beforeMigration, afterMigration,
|
||||||
migrationFunc func(db kvdb.Backend) error) {
|
migrationFunc func(db kvdb.Backend) error, shouldFail bool) {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@@ -106,8 +106,11 @@ func ApplyMigrationWithDb(t testing.TB, beforeMigration, afterMigration,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply migration.
|
// Apply migration.
|
||||||
if err := migrationFunc(cdb); err != nil {
|
err = migrationFunc(cdb)
|
||||||
t.Fatalf("migrationFunc error: %v", err)
|
if shouldFail {
|
||||||
|
require.Error(t, err)
|
||||||
|
} else {
|
||||||
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's no afterMigration, exit here.
|
// If there's no afterMigration, exit here.
|
||||||
|
Reference in New Issue
Block a user