feat(backend): add sqlite migrations + app state + tests
这个提交包含在:
33
backend/tests/sqlite_db_test.cc
普通文件
33
backend/tests/sqlite_db_test.cc
普通文件
@@ -0,0 +1,33 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "csp/db/sqlite_db.h"
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
namespace {
|
||||
|
||||
int CountTable(sqlite3* db, const char* table_name) {
|
||||
sqlite3_stmt* stmt = nullptr;
|
||||
const char* sql =
|
||||
"SELECT COUNT(1) FROM sqlite_master WHERE type='table' AND name=?";
|
||||
REQUIRE(sqlite3_prepare_v2(db, sql, -1, &stmt, nullptr) == SQLITE_OK);
|
||||
REQUIRE(sqlite3_bind_text(stmt, 1, table_name, -1, SQLITE_TRANSIENT) ==
|
||||
SQLITE_OK);
|
||||
REQUIRE(sqlite3_step(stmt) == SQLITE_ROW);
|
||||
const int v = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
return v;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("migrations create core tables") {
|
||||
auto db = csp::db::SqliteDb::OpenMemory();
|
||||
csp::db::ApplyMigrations(db);
|
||||
|
||||
REQUIRE(CountTable(db.raw(), "users") == 1);
|
||||
REQUIRE(CountTable(db.raw(), "sessions") == 1);
|
||||
REQUIRE(CountTable(db.raw(), "problems") == 1);
|
||||
REQUIRE(CountTable(db.raw(), "submissions") == 1);
|
||||
REQUIRE(CountTable(db.raw(), "wrong_book") == 1);
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户