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();
|
2024-11-11 07:20:25 +00:00
|
|
|
builder.target(pretty_env_logger::env_logger::Target::Stdout);
|
2024-11-11 02:01:46 +00:00
|
|
|
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-14 01:46:52 +00:00
|
|
|
|
2024-11-11 07:20:25 +00:00
|
|
|
macro_rules! test_discover_hostmeta {
|
2024-11-09 15:18:46 +00:00
|
|
|
($id:ident, $url:literal) => {
|
2024-11-11 07:20:25 +00:00
|
|
|
test_discover_hostmeta!($id, $url,);
|
2024-11-09 15:18:46 +00:00
|
|
|
};
|
|
|
|
($id:ident, $url:literal, $($tag:meta),*) => {
|
2024-11-14 02:05:47 +00:00
|
|
|
#[tokio::test]
|
|
|
|
$(#[$tag])*
|
|
|
|
async fn $id() {
|
|
|
|
init_log();
|
|
|
|
let client = make_client();
|
2024-11-09 12:33:08 +00:00
|
|
|
|
2024-11-14 02:05:47 +00:00
|
|
|
let base: reqwest::Url = $url.parse()
|
|
|
|
.expect("a valid URL");
|
2024-11-09 12:33:08 +00:00
|
|
|
|
2024-11-18 23:08:11 +00:00
|
|
|
let doc = acrate_rd::any::ResourceDescriptor::discover_hostmeta(&client, base)
|
2024-11-14 02:05:47 +00:00
|
|
|
.await
|
|
|
|
.expect("host-meta discovery to succeed");
|
2024-11-09 12:33:08 +00:00
|
|
|
|
2024-11-14 02:05:47 +00:00
|
|
|
log::info!("Parsed host-meta document: {doc:#?}");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-11-09 15:18:46 +00:00
|
|
|
|
2024-11-14 02:05:47 +00:00
|
|
|
macro_rules! test_de_ser_jrd {
|
|
|
|
($id:ident, $file:literal) => {
|
|
|
|
test_de_ser_jrd!($id, $file,);
|
|
|
|
};
|
|
|
|
($id:ident, $file:literal, $($tag:meta),*) => {
|
|
|
|
const JRD_DOCUMENT: &'static str = include_str!($file);
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
$(#[$tag])*
|
|
|
|
fn $id() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
log::info!("Starting document: {:#?}", JRD_DOCUMENT);
|
|
|
|
|
2024-11-18 23:08:11 +00:00
|
|
|
let de: acrate_rd::jrd::ResourceDescriptorJRD = serde_json::from_str(JRD_DOCUMENT)
|
2024-11-14 02:05:47 +00:00
|
|
|
.expect("document to be deserialized successfully");
|
|
|
|
|
|
|
|
log::info!("Serialized document: {de:#?}");
|
|
|
|
|
|
|
|
let ser = serde_json::to_string(&de)
|
|
|
|
.expect("document to be serialized successfully");
|
|
|
|
|
|
|
|
log::info!("Deserialized document: {ser:#?}");
|
2024-11-09 15:18:46 +00:00
|
|
|
}
|
|
|
|
};
|
2024-11-09 12:33:08 +00:00
|
|
|
}
|
2024-11-09 15:18:46 +00:00
|
|
|
|
2024-11-14 02:05:47 +00:00
|
|
|
macro_rules! test_de_ser_xrd {
|
|
|
|
($id:ident, $file:literal) => {
|
|
|
|
test_de_ser_xrd!($id, $file,);
|
|
|
|
};
|
|
|
|
($id:ident, $file:literal, $($tag:meta),*) => {
|
|
|
|
const XRD_DOCUMENT: &'static str = include_str!($file);
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
$(#[$tag])*
|
|
|
|
fn $id() {
|
|
|
|
init_log();
|
|
|
|
|
|
|
|
log::info!("Starting document: {:#?}", XRD_DOCUMENT);
|
|
|
|
|
2024-11-18 23:08:11 +00:00
|
|
|
let de: acrate_rd::xrd::ResourceDescriptorXRD = quick_xml::de::from_str(XRD_DOCUMENT)
|
2024-11-14 02:05:47 +00:00
|
|
|
.expect("document to be deserialized successfully");
|
|
|
|
|
|
|
|
log::info!("Serialized document: {de:#?}");
|
|
|
|
|
|
|
|
let ser = quick_xml::se::to_string(&de)
|
|
|
|
.expect("document to be serialized successfully");
|
|
|
|
|
|
|
|
log::info!("Deserialized document: {ser:#?}");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
test_discover_hostmeta!(test_discover_hostmeta_junimo_party, "https://junimo.party");
|
|
|
|
test_discover_hostmeta!(test_discover_hostmeta_mastodon_social, "https://mastodon.social");
|
|
|
|
test_discover_hostmeta!(test_discover_hostmeta_misskey_io, "https://misskey.io");
|
2024-12-16 00:57:58 +00:00
|
|
|
test_discover_hostmeta!(test_discover_hostmeta_meow_company, "https://meow.company");
|
2024-11-14 02:05:47 +00:00
|
|
|
test_discover_hostmeta!(test_discover_hostmeta_alpha_polymaths_social, "https://alpha.polymaths.social");
|
|
|
|
test_discover_hostmeta!(test_discover_hostmeta_fed_brid_gy, "https://fed.brid.gy");
|
|
|
|
test_discover_hostmeta!(test_discover_hostmeta_threads_net, "https://threads.net", ignore = "does not support host-meta");
|
|
|
|
test_discover_hostmeta!(test_discover_hostmeta_ngoa_giao_loan, "https://ngoa.giao.loan", ignore = "does not support host-meta");
|
|
|
|
test_discover_hostmeta!(test_discover_hostmeta_hollo_social, "https://hollo.social", ignore = "does not support host-meta");
|
|
|
|
|
2024-11-18 23:08:11 +00:00
|
|
|
test_de_ser_jrd!(test_de_ser_jrd_sample_junimo_party, "samples/junimo_party.nodeinfo.jrd.json");
|
|
|
|
test_de_ser_xrd!(test_de_ser_xrd_sample_junimo_party, "samples/junimo_party.host-meta.xrd.xml");
|