tirocinio-canali-steffo-acrate/acrate_nodeinfo/tests/integration_tests.rs

70 lines
2 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_version {
($id:ident, $url:literal, $version:literal) => {
test_version!($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_version!(akkoma, "https://junimo.party", "2.1");
test_version!(mastodon, "https://mastodon.social", "2.0");
test_version!(misskey, "https://misskey.io", "2.1");
test_version!(iceshrimpnet, "https://meow_company", "2.1");
test_version!(gotosocial, "https://alpha.polymaths.social", "2.0");
test_version!(bridgyfed, "https://fed.brid.gy", "2.1");
test_version!(threads, "https://threads.net", "", ignore = "does not support NodeInfo");
test_version!(snac, "https://ngoa.giao.loan", "2.0");
test_version!(hollo, "https://hollo.social", "2.1");