1
Fork 0

hostmeta: Improve tests

This commit is contained in:
Steffo 2024-11-14 03:05:47 +01:00
parent 62a38f2ff0
commit 3a5794e7b8
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
3 changed files with 91 additions and 24 deletions

View file

@ -29,34 +29,88 @@ macro_rules! test_discover_hostmeta {
test_discover_hostmeta!($id, $url,); test_discover_hostmeta!($id, $url,);
}; };
($id:ident, $url:literal, $($tag:meta),*) => { ($id:ident, $url:literal, $($tag:meta),*) => {
mod $id { #[tokio::test]
use super::*; $(#[$tag])*
async fn $id() {
init_log();
let client = make_client();
#[tokio::test] let base: reqwest::Url = $url.parse()
$(#[$tag])* .expect("a valid URL");
async fn test() {
init_log();
let client = make_client();
let base: reqwest::Url = $url.parse() let doc = acrate_hostmeta::any::ResourceDescriptor::discover_hostmeta(&client, base)
.expect("a valid URL"); .await
.expect("host-meta discovery to succeed");
let doc = acrate_hostmeta::any::ResourceDescriptor::discover_hostmeta(&client, base) log::info!("Parsed host-meta document: {doc:#?}");
.await
.expect("host-meta discovery to succeed");
log::info!("Parsed host-meta document: {doc:#?}");
}
} }
}; };
} }
test_discover_hostmeta!(akkoma, "https://junimo.party"); macro_rules! test_de_ser_jrd {
test_discover_hostmeta!(mastodon, "https://mastodon.social"); ($id:ident, $file:literal) => {
test_discover_hostmeta!(misskey, "https://misskey.io"); test_de_ser_jrd!($id, $file,);
test_discover_hostmeta!(iceshrimpnet, "https://ice.frieren.quest"); };
test_discover_hostmeta!(gotosocial, "https://alpha.polymaths.social"); ($id:ident, $file:literal, $($tag:meta),*) => {
test_discover_hostmeta!(bridgyfed, "https://fed.brid.gy"); const JRD_DOCUMENT: &'static str = include_str!($file);
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]
test_discover_hostmeta!(hollo, "https://hollo.social", ignore = "does not support host-meta"); $(#[$tag])*
fn $id() {
init_log();
log::info!("Starting document: {:#?}", JRD_DOCUMENT);
let de: acrate_hostmeta::jrd::ResourceDescriptorJRD = serde_json::from_str(JRD_DOCUMENT)
.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:#?}");
}
};
}
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();
let client = make_client();
log::info!("Starting document: {:#?}", XRD_DOCUMENT);
let de: acrate_hostmeta::xrd::ResourceDescriptorXRD = quick_xml::de::from_str(XRD_DOCUMENT)
.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");
test_discover_hostmeta!(test_discover_hostmeta_ice_frieren_quest, "https://ice.frieren.quest");
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");
test_de_ser_jrd!(test_de_ser_sample_junimo_party, "samples/junimo_party.nodeinfo.jrd.json");

View file

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0"><Link type="application/xrd+xml" template="https://junimo.party/.well-known/webfinger?resource={uri}" rel="lrdd" /></XRD>

View file

@ -0,0 +1,12 @@
{
"links": [
{
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
"href": "https://junimo.party/nodeinfo/2.0.json"
},
{
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.1",
"href": "https://junimo.party/nodeinfo/2.1.json"
}
]
}