Files
faumaray 053ee5b296
CI / GCC 16 / C++26 / sanitizers (push) Failing after 4s
CI / GCC 16 / C++26 / werror (push) Failing after 3s
CI / GCC 16 / C++26 / default (push) Failing after 1m48s
update
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-25 23:42:52 +03:00

59 lines
1.6 KiB
C++

#include <Void/ShortUrl/ShortUrl.hpp>
#include <Void/Testing/Assert.hpp>
#include <Void/Testing/Test.hpp>
#include <cstdint>
#include <string>
namespace
{
class Shortener final : public Void::ShortUrl::IShortener
{
public:
[[nodiscard]] std::string_view provider_id() const noexcept override
{
return "test";
}
[[nodiscard]] Void::ShortUrl::Health health() const override
{
return {.status = Void::ShortUrl::HealthStatus::healthy};
}
[[nodiscard]] Void::ShortUrl::ShortenResult
shorten(const Void::ShortUrl::ShortenRequest& request) override
{
return {
.short_url = "https://sho.rt/s/Ab3dE5fG7h",
.key = "Ab3dE5fG7h",
.expires_at_unix_seconds = request.expires_at_unix_seconds,
};
}
};
} // namespace
Void::Testing::Test short_url_service_contract()
{
Shortener shortener;
Void::Testing::expect_eq(shortener.service_name(),
Void::ShortUrl::kServiceId);
Void::Testing::expect_eq(shortener.service_version(), std::uint32_t{1});
Void::Testing::expect_eq(shortener.provider_id(), std::string_view{"test"});
Void::Testing::expect_eq(shortener.health().status,
Void::ShortUrl::HealthStatus::healthy);
auto result = shortener.shorten({.target_url = "https://example.com/a"});
Void::Testing::expect(result.ok());
Void::Testing::expect_eq(result.key, std::string{"Ab3dE5fG7h"});
}
Void::Testing::Test short_url_resolution_is_optional()
{
Shortener shortener;
auto result = shortener.resolve({.key = "Ab3dE5fG7h"});
Void::Testing::expect(!result.ok());
Void::Testing::expect_eq(result.error.code,
Void::ShortUrl::ErrorCode::unsupported);
}