tests: always call db_migrate() with non-NULL ld.

This will be useful when we add hooks.  For the moment, ld's contents is
undefined, but this can easily be changed.
This commit is contained in:
Michael Schmoock 2019-03-05 00:39:21 +01:00 committed by Rusty Russell
parent 0d35a7111a
commit 624ec6da27
2 changed files with 10 additions and 7 deletions

View File

@ -51,14 +51,14 @@ static struct db *create_test_db(void)
return db; return db;
} }
static bool test_empty_db_migrate(void) static bool test_empty_db_migrate(struct lightningd *ld)
{ {
struct db *db = create_test_db(); struct db *db = create_test_db();
CHECK(db); CHECK(db);
db_begin_transaction(db); db_begin_transaction(db);
CHECK(db_get_version(db) == -1); CHECK(db_get_version(db) == -1);
db_commit_transaction(db); db_commit_transaction(db);
db_migrate(NULL, db, NULL); db_migrate(ld, db, NULL);
db_begin_transaction(db); db_begin_transaction(db);
CHECK(db_get_version(db) == ARRAY_SIZE(dbmigrations) - 1); CHECK(db_get_version(db) == ARRAY_SIZE(dbmigrations) - 1);
db_commit_transaction(db); db_commit_transaction(db);
@ -91,12 +91,12 @@ static bool test_primitives(void)
return true; return true;
} }
static bool test_vars(void) static bool test_vars(struct lightningd *ld)
{ {
struct db *db = create_test_db(); struct db *db = create_test_db();
char *varname = "testvar"; char *varname = "testvar";
CHECK(db); CHECK(db);
db_migrate(NULL, db, NULL); db_migrate(ld, db, NULL);
db_begin_transaction(db); db_begin_transaction(db);
/* Check default behavior */ /* Check default behavior */
@ -120,10 +120,13 @@ int main(void)
setup_locale(); setup_locale();
bool ok = true; bool ok = true;
/* Dummy for migration hooks */
struct lightningd *ld = tal(NULL, struct lightningd);
ok &= test_empty_db_migrate(); ok &= test_empty_db_migrate(ld);
ok &= test_vars(); ok &= test_vars(ld);
ok &= test_primitives(); ok &= test_primitives();
tal_free(ld);
return !ok; return !ok;
} }

View File

@ -671,7 +671,7 @@ static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx
w->bip32_base) == WALLY_OK); w->bip32_base) == WALLY_OK);
CHECK_MSG(w->db, "Failed opening the db"); CHECK_MSG(w->db, "Failed opening the db");
db_migrate(NULL, w->db, w->log); db_migrate(ld, w->db, w->log);
CHECK_MSG(!wallet_err, "DB migration failed"); CHECK_MSG(!wallet_err, "DB migration failed");
w->max_channel_dbid = 0; w->max_channel_dbid = 0;