#include "gucc/fetch_file.hpp" #include "gucc/file_utils.hpp" #include #include #include #include namespace fs = std::filesystem; using namespace std::string_view_literals; int main() { // existing remote url, non existent fallback url static constexpr std::string_view LICENSE_PATH = GUCC_TOP_DIR "/LICENSE"; { static constexpr auto remote_url = "https://github.com/CachyOS/New-Cli-Installer/raw/master/LICENSE"sv; const auto& file_content = gucc::fetch::fetch_file_from_url(remote_url, "file:///ter-testunit"); assert(file_content); assert(!file_content->empty()); const auto& expected_file_content = gucc::file_utils::read_whole_file(LICENSE_PATH); assert(file_content == expected_file_content); } // non existent remote url, existing fallback url { static constexpr auto remote_url = "https://github.com/CachyOS/New-Cli-Installer/raw/master/LCNS"sv; const auto& file_content = gucc::fetch::fetch_file_from_url(remote_url, fmt::format("file://{}", LICENSE_PATH)); assert(file_content); assert(!file_content->empty()); const auto& expected_file_content = gucc::file_utils::read_whole_file(LICENSE_PATH); assert(file_content == expected_file_content); } // non existent remote url, non existent fallback url { static constexpr auto remote_url = "https://github.com/CachyOS/New-Cli-Installer/raw/master/LCNS"sv; const auto& file_content = gucc::fetch::fetch_file_from_url(remote_url, "file:///ter-testunit"); assert(!file_content); } }