Line data Source code
1 : // SPDX-FileCopyrightText: 2025 PairInteraction Developers 2 : // SPDX-License-Identifier: LGPL-3.0-or-later 3 : 4 : #include "pairinteraction/database/GitHubDownloader.hpp" 5 : 6 : #include "pairinteraction/database/Database.hpp" 7 : 8 : #include <ctime> 9 : #include <doctest/doctest.h> 10 : #include <httplib.h> 11 : 12 : namespace pairinteraction { 13 1 : DOCTEST_TEST_CASE("Get rate limit with GitHubDownloader") { 14 1 : if (!Database::get_global_instance().get_download_missing()) { 15 1 : DOCTEST_MESSAGE("Skipping test because download_missing is false."); 16 1 : return; 17 : } 18 0 : GitHubDownloader downloader; 19 0 : int current_time = static_cast<int>(std::time(nullptr)); 20 : 21 0 : auto result = downloader.download("/rate_limit", "", false).get(); 22 : 23 0 : DOCTEST_CHECK(result.status_code == 200); 24 0 : DOCTEST_CHECK(result.rate_limit.reset_time > current_time); 25 0 : DOCTEST_CHECK(result.rate_limit.remaining >= 0); 26 0 : DOCTEST_MESSAGE("Number of remaining requests: ", result.rate_limit.remaining); 27 0 : } 28 : 29 0 : DOCTEST_TEST_CASE("Download content with GitHubDownloader" * doctest::skip(true)) { 30 : // This test is skipped by default because the request always counts towards the GitHub rate 31 : // limit because it is never cached 32 : 33 0 : if (!Database::get_global_instance().get_download_missing()) { 34 0 : DOCTEST_MESSAGE("Skipping test because download_missing is false."); 35 0 : return; 36 : } 37 0 : GitHubDownloader downloader; 38 0 : int current_time = static_cast<int>(std::time(nullptr)); 39 : 40 0 : auto future = downloader.download("/octocat"); 41 0 : auto result = future.get(); 42 : 43 0 : DOCTEST_CHECK(result.status_code == 200); 44 0 : DOCTEST_CHECK(result.rate_limit.reset_time > current_time); 45 0 : DOCTEST_CHECK(result.rate_limit.remaining >= 0); 46 0 : DOCTEST_MESSAGE("Number of remaining requests: ", result.rate_limit.remaining); 47 0 : } 48 : } // namespace pairinteraction