2024-11-11 02:01:46 +00:00
|
|
|
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.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 {
|
2024-11-11 02:01:46 +00:00
|
|
|
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")
|
|
|
|
}
|
2024-11-09 12:33:08 +00:00
|
|
|
|
2024-11-09 15:18:46 +00:00
|
|
|
macro_rules! test {
|
|
|
|
($id:ident, $url:literal) => {
|
|
|
|
test!($id, $url,);
|
|
|
|
};
|
|
|
|
($id:ident, $url:literal, $($tag:meta),*) => {
|
|
|
|
mod $id {
|
|
|
|
use acrate_nodeinfo::*;
|
|
|
|
use super::*;
|
2024-11-09 12:33:08 +00:00
|
|
|
|
2024-11-09 15:18:46 +00:00
|
|
|
#[tokio::test]
|
|
|
|
$(#[$tag])*
|
|
|
|
async fn test_hostmeta() {
|
2024-11-11 02:01:46 +00:00
|
|
|
init_log();
|
2024-11-09 15:18:46 +00:00
|
|
|
let client = make_client();
|
2024-11-09 12:33:08 +00:00
|
|
|
|
2024-11-09 15:18:46 +00:00
|
|
|
let base: reqwest::Url = $url.parse()
|
|
|
|
.expect("a valid URL");
|
2024-11-09 12:33:08 +00:00
|
|
|
|
2024-11-09 15:18:46 +00:00
|
|
|
let doc = HostMetaDocument::discover_hostmeta(&client, base)
|
|
|
|
.await
|
|
|
|
.expect("host-meta discovery to succeed");
|
|
|
|
|
2024-11-11 02:01:46 +00:00
|
|
|
log::info!("Parsed host-meta document: {doc:#?}");
|
2024-11-09 15:18:46 +00:00
|
|
|
}
|
2024-11-09 12:33:08 +00:00
|
|
|
|
2024-11-09 15:18:46 +00:00
|
|
|
#[tokio::test]
|
|
|
|
$(#[$tag])*
|
|
|
|
async fn test_nodeinfo() {
|
2024-11-11 02:01:46 +00:00
|
|
|
init_log();
|
2024-11-09 15:18:46 +00:00
|
|
|
let client = make_client();
|
2024-11-09 12:33:08 +00:00
|
|
|
|
2024-11-09 15:18:46 +00:00
|
|
|
let base: reqwest::Url = $url.parse()
|
|
|
|
.expect("a valid URL");
|
|
|
|
|
|
|
|
let doc = HostMetaDocument::discover_nodeinfo(&client, base)
|
|
|
|
.await
|
2024-11-11 01:33:24 +00:00
|
|
|
.expect("nodeinfo discovery to succeed");
|
2024-11-09 15:18:46 +00:00
|
|
|
|
2024-11-11 02:01:46 +00:00
|
|
|
log::info!("Parsed nodeinfo document: {doc:#?}");
|
2024-11-09 15:18:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2024-11-09 12:33:08 +00:00
|
|
|
}
|
2024-11-09 15:18:46 +00:00
|
|
|
|
|
|
|
test!(akkoma, "https://junimo.party");
|
|
|
|
|
|
|
|
test!(mastodon, "https://mastodon.social");
|
|
|
|
|
|
|
|
test!(misskey, "https://misskey.io");
|
|
|
|
|
|
|
|
test!(iceshrimpnet, "https://ice.frieren.quest");
|
|
|
|
|
|
|
|
test!(gotosocial, "https://alpha.polymaths.social");
|
|
|
|
|
2024-11-11 01:18:57 +00:00
|
|
|
test!(bridgyfed, "https://fed.brid.gy");
|
2024-11-09 15:18:46 +00:00
|
|
|
|
|
|
|
test!(threads, "https://threads.net", ignore = "Not implemented on their end");
|
2024-11-11 01:12:36 +00:00
|
|
|
|
|
|
|
test!(snac, "https://ngoa.giao.loan", ignore = "Does not support host-meta");
|
2024-11-11 01:13:58 +00:00
|
|
|
|
2024-11-11 01:18:57 +00:00
|
|
|
test!(hollo, "https://hollo.social", ignore = "Does not support host-meta");
|