1
Fork 0
tirocinio-canali-steffo-acrate/acrate-hostmeta/tests/hostmeta_tests.rs

63 lines
1.9 KiB
Rust
Raw Normal View History

const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
const CARGO_PKG_REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY");
fn init_log() {
let mut builder = pretty_env_logger::formatted_builder();
builder.target(pretty_env_logger::env_logger::Target::Stdout);
builder.filter_level(log::LevelFilter::max());
builder.is_test(true);
if builder.try_init().is_ok() {
log::debug!("Initialized logging!");
}
}
2024-11-09 15:18:46 +00:00
fn make_client() -> reqwest::Client {
let user_agent = format!("{CARGO_PKG_NAME}/{CARGO_PKG_VERSION} ({CARGO_PKG_REPOSITORY})");
2024-11-09 15:18:46 +00:00
reqwest::Client::builder()
.user_agent(user_agent)
.build()
.expect("reqwest client to build")
}
macro_rules! test_discover_hostmeta {
2024-11-09 15:18:46 +00:00
($id:ident, $url:literal) => {
test_discover_hostmeta!($id, $url,);
2024-11-09 15:18:46 +00:00
};
($id:ident, $url:literal, $($tag:meta),*) => {
mod $id {
2024-11-11 02:06:34 +00:00
use acrate_hostmeta::*;
2024-11-09 15:18:46 +00:00
use super::*;
2024-11-09 15:18:46 +00:00
#[tokio::test]
$(#[$tag])*
async fn test() {
init_log();
2024-11-09 15:18:46 +00:00
let client = make_client();
2024-11-09 15:18:46 +00:00
let base: reqwest::Url = $url.parse()
.expect("a valid URL");
let doc = ResourceDescriptor::discover_hostmeta(&client, base)
2024-11-09 15:18:46 +00:00
.await
.expect("host-meta discovery to succeed");
log::info!("Parsed host-meta document: {doc:#?}");
2024-11-09 15:18:46 +00:00
}
}
};
}
2024-11-09 15:18:46 +00:00
test_discover_hostmeta!(akkoma, "https://junimo.party");
test_discover_hostmeta!(mastodon, "https://mastodon.social");
test_discover_hostmeta!(misskey, "https://misskey.io");
test_discover_hostmeta!(iceshrimpnet, "https://ice.frieren.quest");
test_discover_hostmeta!(gotosocial, "https://alpha.polymaths.social");
test_discover_hostmeta!(bridgyfed, "https://fed.brid.gy");
test_discover_hostmeta!(threads, "https://threads.net", ignore = "does not support host-meta");
test_discover_hostmeta!(snac, "https://ngoa.giao.loan", ignore = "does not support host-meta");
test_discover_hostmeta!(hollo, "https://hollo.social", ignore = "does not support host-meta");