pairinteraction
A Rydberg Interaction Calculator
GitHubDownloader.test.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Pairinteraction Developers
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
5
7
8#include <ctime>
9#include <doctest/doctest.h>
10#include <httplib.h>
11
12namespace pairinteraction {
13DOCTEST_TEST_CASE("Get rate limit with GitHubDownloader") {
14 if (!Database::get_global_instance().get_download_missing()) {
15 DOCTEST_MESSAGE("Skipping test because download_missing is false.");
16 return;
17 }
18 GitHubDownloader downloader;
19 int current_time = static_cast<int>(std::time(nullptr));
20
21 auto rate_limit = downloader.get_rate_limit();
22
23 DOCTEST_CHECK(rate_limit.reset_time > current_time);
24 DOCTEST_CHECK(rate_limit.remaining >= 0);
25 DOCTEST_MESSAGE("Number of remaining requests: ", rate_limit.remaining);
26}
27
28DOCTEST_TEST_CASE("Download content with GitHubDownloader" * doctest::skip(true)) {
29 // This test is skipped by default because the request always counts towards the GitHub rate
30 // limit because it is never cached
31
32 if (!Database::get_global_instance().get_download_missing()) {
33 DOCTEST_MESSAGE("Skipping test because download_missing is false.");
34 return;
35 }
36 GitHubDownloader downloader;
37 int current_time = static_cast<int>(std::time(nullptr));
38
39 auto future = downloader.download("/octocat");
40 auto result = future.get();
41
42 DOCTEST_CHECK(result.status_code == 200);
43 DOCTEST_CHECK(result.rate_limit.reset_time > current_time);
44 DOCTEST_CHECK(result.rate_limit.remaining >= 0);
45 DOCTEST_MESSAGE("Number of remaining requests: ", result.rate_limit.remaining);
46}
47} // namespace pairinteraction
static Database & get_global_instance()
Definition: Database.cpp:1068
virtual std::future< Result > download(const std::string &remote_url, const std::string &if_modified_since="", bool use_octet_stream=false) const
DOCTEST_TEST_CASE("create a basis for strontium 88")