New-Cli-Installer/gucc/tests/unit-fetch_file.cpp
2024-07-11 03:44:16 +04:00

46 lines
1.6 KiB
C++

#include "gucc/fetch_file.hpp"
#include "gucc/file_utils.hpp"
#include <cassert>
#include <filesystem>
#include <string_view>
#include <fmt/format.h>
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);
}
}