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 rate_limit = downloader.get_rate_limit(); 22 : 23 0 : DOCTEST_CHECK(rate_limit.reset_time > current_time); 24 0 : DOCTEST_CHECK(rate_limit.remaining >= 0); 25 0 : DOCTEST_MESSAGE("Number of remaining requests: ", rate_limit.remaining); 26 0 : } 27 : 28 0 : DOCTEST_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 0 : if (!Database::get_global_instance().get_download_missing()) { 33 0 : DOCTEST_MESSAGE("Skipping test because download_missing is false."); 34 0 : return; 35 : } 36 0 : GitHubDownloader downloader; 37 0 : int current_time = static_cast<int>(std::time(nullptr)); 38 : 39 0 : auto future = downloader.download("/octocat"); 40 0 : auto result = future.get(); 41 : 42 0 : DOCTEST_CHECK(result.status_code == 200); 43 0 : DOCTEST_CHECK(result.rate_limit.reset_time > current_time); 44 0 : DOCTEST_CHECK(result.rate_limit.remaining >= 0); 45 0 : DOCTEST_MESSAGE("Number of remaining requests: ", result.rate_limit.remaining); 46 0 : } 47 : } // namespace pairinteraction