9#include <doctest/doctest.h>
14#include <nlohmann/json.hpp>
19 std::future<GitHubDownloader::Result>
20 download(
const std::string &remote_url,
const std::string & =
"",
21 bool =
false)
const override {
27 if (remote_url ==
"/test/repo/path") {
31 asset[
"name"] =
"misc_v1.2.zip";
32 asset[
"url"] =
"https://api.github.com/test/path/misc_v1.2.zip";
33 assets.push_back(asset);
35 response[
"assets"] = assets;
36 result.
body = response.dump();
37 }
else if (remote_url ==
"/rate_limit") {
42 std::string content =
"updated_file_content";
43 std::string filename =
"misc_v1.2/wigner.parquet";
45 mz_zip_archive zip_archive{};
47 void *zip_data =
nullptr;
49 mz_zip_writer_init_heap(&zip_archive, 0, 0);
50 mz_zip_writer_add_mem(&zip_archive, filename.c_str(), content.data(), content.size(),
52 mz_zip_writer_finalize_heap_archive(&zip_archive, &zip_data, &zip_size);
54 result.
body = std::string(
static_cast<char *
>(zip_data), zip_size);
57 mz_zip_writer_end(&zip_archive);
60 return std::async(std::launch::deferred, [result]() {
return result; });
64TEST_CASE(
"ParquetManager functionality with mocked downloader") {
66 auto test_dir = std::filesystem::temp_directory_path() /
"pairinteraction_test_db";
67 std::filesystem::create_directories(test_dir /
"tables" /
"misc_v1.0");
68 std::filesystem::create_directories(test_dir /
"tables" /
"misc_v1.1");
69 std::ofstream(test_dir /
"tables" /
"misc_v1.0" /
"wigner.parquet").close();
70 std::ofstream(test_dir /
"tables" /
"misc_v1.1" /
"wigner.parquet").close();
71 duckdb::DuckDB db(
nullptr);
72 duckdb::Connection con(db);
74 SUBCASE(
"Check missing table") {
75 std::vector<std::string> repo_paths;
76 ParquetManager manager(test_dir, downloader, repo_paths, con,
false);
80 CHECK_THROWS_WITH_AS(manager.
get_path(
"misc",
"missing_table"),
81 "Table misc_missing_table not found.", std::runtime_error);
84 SUBCASE(
"Check version parsing") {
85 std::vector<std::string> repo_paths;
86 ParquetManager manager(test_dir, downloader, repo_paths, con,
false);
90 std::string expected = (test_dir /
"tables" /
"misc_v1.1" /
"wigner.parquet").
string();
91 CHECK(manager.
get_path(
"misc",
"wigner") == expected);
94 SUBCASE(
"Check update table") {
95 std::vector<std::string> repo_paths = {
"/test/repo/path"};
96 ParquetManager manager(test_dir, downloader, repo_paths, con,
false);
100 std::string expected = (test_dir /
"tables" /
"misc_v1.2" /
"wigner.parquet").
string();
101 CHECK(manager.
get_path(
"misc",
"wigner") == expected);
103 std::ifstream in(expected, std::ios::binary);
104 std::stringstream buffer;
105 buffer << in.rdbuf();
106 CHECK(buffer.str() ==
"updated_file_content");
109 std::filesystem::remove_all(test_dir);
114 DOCTEST_MESSAGE(
"Skipping test because download_missing is false.");
118 duckdb::DuckDB db(
nullptr);
119 duckdb::Connection con(db);
121 std::vector<std::string> repo_paths = {
"/repos/pairinteraction/database-sqdt/releases/latest",
122 "/repos/pairinteraction/database-mqdt/releases/latest"};
131 std::vector<std::string> should_contain = {
132 "Cs",
"K",
"Li",
"Na",
133 "Rb",
"Sr87_mqdt",
"Sr88_singlet",
"Sr88_triplet",
134 "Sr88_mqdt",
"Yb171_mqdt",
"Yb173_mqdt",
"Yb174_mqdt",
136 for (
const auto &substr : should_contain) {
137 DOCTEST_CHECK(info.find(substr) != std::string::npos);
static Database & get_global_instance()
std::future< GitHubDownloader::Result > download(const std::string &remote_url, const std::string &="", bool=false) const override
std::string get_versions_info() const
std::string get_path(const std::string &key, const std::string &table)
TEST_CASE("ParquetManager functionality with mocked downloader")
DOCTEST_TEST_CASE("create a basis for strontium 88")