-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersistence_test.cpp
More file actions
51 lines (45 loc) · 1.92 KB
/
persistence_test.cpp
File metadata and controls
51 lines (45 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "engine.h"
#include <filesystem>
#include <iostream>
#include <string>
int main() {
const std::filesystem::path original_cwd = std::filesystem::current_path();
const std::filesystem::path temp_root =
std::filesystem::temp_directory_path() / "flexql_persistence_test_workspace";
try {
std::filesystem::remove_all(temp_root);
std::filesystem::create_directories(temp_root);
std::filesystem::current_path(temp_root);
{
flexql::Engine engine;
engine.execute("CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR, score DECIMAL);");
engine.execute("INSERT INTO users VALUES (1, 'Alice', 91.5), (2, 'Bob', 88.0);");
}
{
flexql::Engine restarted_engine;
auto result = restarted_engine.execute("SELECT id, name FROM users;");
if (result.rows.size() != 2) {
std::cerr << "Expected 2 rows after restart, got " << result.rows.size() << "\n";
std::filesystem::current_path(original_cwd);
std::filesystem::remove_all(temp_root);
return 1;
}
if (result.rows[0][0] != "1" || result.rows[0][1] != "Alice" ||
result.rows[1][0] != "2" || result.rows[1][1] != "Bob") {
std::cerr << "Recovered rows do not match expected values\n";
std::filesystem::current_path(original_cwd);
std::filesystem::remove_all(temp_root);
return 1;
}
}
std::filesystem::current_path(original_cwd);
std::filesystem::remove_all(temp_root);
std::cout << "Persistence test passed\n";
return 0;
} catch (const std::exception &ex) {
std::filesystem::current_path(original_cwd);
std::filesystem::remove_all(temp_root);
std::cerr << "Persistence test failed: " << ex.what() << "\n";
return 1;
}
}