71 lines
1.9 KiB
Rust
71 lines
1.9 KiB
Rust
|
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!");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn make_client() -> reqwest::Client {
|
||
|
let user_agent = format!("{CARGO_PKG_NAME}/{CARGO_PKG_VERSION} ({CARGO_PKG_REPOSITORY})");
|
||
|
|
||
|
reqwest::Client::builder()
|
||
|
.user_agent(user_agent)
|
||
|
.build()
|
||
|
.expect("reqwest client to build")
|
||
|
}
|
||
|
|
||
|
|
||
|
macro_rules! test {
|
||
|
($id:ident, $url:literal, $version:literal) => {
|
||
|
test!($id, $url, $version,);
|
||
|
};
|
||
|
($id:ident, $url:literal, $version:literal, $($tag:meta),*) => {
|
||
|
mod $id {
|
||
|
use acrate_nodeinfo::*;
|
||
|
use super::*;
|
||
|
|
||
|
#[tokio::test]
|
||
|
$(#[$tag])*
|
||
|
async fn test_version() {
|
||
|
init_log();
|
||
|
let client = make_client();
|
||
|
|
||
|
let base: reqwest::Url = $url.parse()
|
||
|
.expect("a valid URL");
|
||
|
|
||
|
let doc = NodeInfo::get_latest_wellknown(&client, base)
|
||
|
.await
|
||
|
.expect("NodeInfo discovery to succeed");
|
||
|
|
||
|
log::info!("Parsed NodeInfo document: {doc:#?}");
|
||
|
|
||
|
let version = match doc {
|
||
|
NodeInfo::V1(d) => d.version,
|
||
|
NodeInfo::V2(d) => d.version,
|
||
|
};
|
||
|
|
||
|
assert_eq!(version, $version);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
test!(akkoma, "https://junimo.party", "2.1");
|
||
|
test!(mastodon, "https://mastodon.social", "2.0");
|
||
|
test!(misskey, "https://misskey.io", "2.1");
|
||
|
test!(iceshrimpnet, "https://ice.frieren.quest", "2.1");
|
||
|
test!(gotosocial, "https://alpha.polymaths.social", "2.0");
|
||
|
test!(bridgyfed, "https://fed.brid.gy", "2.1");
|
||
|
test!(threads, "https://threads.net", "", ignore = "does not support NodeInfo");
|
||
|
test!(snac, "https://ngoa.giao.loan", "2.0");
|
||
|
test!(hollo, "https://hollo.social", "2.1");
|