mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-07 16:14:26 +01:00
unittests: Test some more of the db primitives.
This commit is contained in:
committed by
Rusty Russell
parent
40165ba6d5
commit
1522eee528
@@ -44,6 +44,7 @@ bool PRINTF_FMT(3, 4)
|
||||
|
||||
err = sqlite3_exec(db->sql, cmd, NULL, NULL, &errmsg);
|
||||
if (err != SQLITE_OK) {
|
||||
db->in_transaction = false;
|
||||
tal_free(db->err);
|
||||
db->err = tal_fmt(db, "%s:%s:%s:%s", caller,
|
||||
sqlite3_errstr(err), cmd, errmsg);
|
||||
@@ -72,6 +73,7 @@ sqlite3_stmt *PRINTF_FMT(3, 4)
|
||||
|
||||
err = sqlite3_prepare_v2(db->sql, query, -1, &stmt, NULL);
|
||||
if (err != SQLITE_OK) {
|
||||
db->in_transaction = false;
|
||||
db->err = tal_fmt(db, "%s:%s:%s:%s", caller,
|
||||
sqlite3_errstr(err), query, sqlite3_errmsg(db->sql));
|
||||
}
|
||||
|
||||
@@ -31,6 +31,25 @@ static bool test_empty_db_migrate(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool test_primitives(void)
|
||||
{
|
||||
struct db *db = create_test_db(__func__);
|
||||
CHECK_MSG(db_begin_transaction(db), "Starting a new transaction");
|
||||
CHECK(db->in_transaction);
|
||||
CHECK_MSG(db_commit_transaction(db), "Committing a transaction");
|
||||
CHECK(!db->in_transaction);
|
||||
CHECK_MSG(db_begin_transaction(db), "Starting a transaction after commit");
|
||||
CHECK(db_rollback_transaction(db));
|
||||
|
||||
CHECK_MSG(db_exec(__func__, db, "SELECT name FROM sqlite_master WHERE type='table';"), "Simple correct SQL command");
|
||||
CHECK_MSG(!db_exec(__func__, db, "not a valid SQL statement"), "Failing SQL command");
|
||||
CHECK(!db->in_transaction);
|
||||
CHECK_MSG(db_begin_transaction(db), "Starting a transaction after a failed transaction");
|
||||
tal_free(db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool test_vars(void)
|
||||
{
|
||||
struct db *db = create_test_db(__func__);
|
||||
@@ -59,6 +78,7 @@ int main(void)
|
||||
|
||||
ok &= test_empty_db_migrate();
|
||||
ok &= test_vars();
|
||||
ok &= test_primitives();
|
||||
|
||||
return !ok;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user