diff --git a/acrate-hostmeta/tests/hostmeta_tests.rs b/acrate-hostmeta/tests/hostmeta_tests.rs index f183688..82ece6a 100644 --- a/acrate-hostmeta/tests/hostmeta_tests.rs +++ b/acrate-hostmeta/tests/hostmeta_tests.rs @@ -29,34 +29,88 @@ macro_rules! test_discover_hostmeta { test_discover_hostmeta!($id, $url,); }; ($id:ident, $url:literal, $($tag:meta),*) => { - mod $id { - use super::*; + #[tokio::test] + $(#[$tag])* + async fn $id() { + init_log(); + let client = make_client(); - #[tokio::test] - $(#[$tag])* - async fn test() { - init_log(); - let client = make_client(); + let base: reqwest::Url = $url.parse() + .expect("a valid URL"); - let base: reqwest::Url = $url.parse() - .expect("a valid URL"); + let doc = acrate_hostmeta::any::ResourceDescriptor::discover_hostmeta(&client, base) + .await + .expect("host-meta discovery to succeed"); - let doc = acrate_hostmeta::any::ResourceDescriptor::discover_hostmeta(&client, base) - .await - .expect("host-meta discovery to succeed"); - - log::info!("Parsed host-meta document: {doc:#?}"); - } + log::info!("Parsed host-meta document: {doc:#?}"); } }; } -test_discover_hostmeta!(akkoma, "https://junimo.party"); -test_discover_hostmeta!(mastodon, "https://mastodon.social"); -test_discover_hostmeta!(misskey, "https://misskey.io"); -test_discover_hostmeta!(iceshrimpnet, "https://ice.frieren.quest"); -test_discover_hostmeta!(gotosocial, "https://alpha.polymaths.social"); -test_discover_hostmeta!(bridgyfed, "https://fed.brid.gy"); -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_discover_hostmeta!(hollo, "https://hollo.social", ignore = "does not support host-meta"); +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); + + 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"); diff --git a/acrate-hostmeta/tests/samples/junimo_party.host-meta.xrd.xml b/acrate-hostmeta/tests/samples/junimo_party.host-meta.xrd.xml new file mode 100644 index 0000000..457a6cf --- /dev/null +++ b/acrate-hostmeta/tests/samples/junimo_party.host-meta.xrd.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/acrate-hostmeta/tests/samples/junimo_party.nodeinfo.jrd.json b/acrate-hostmeta/tests/samples/junimo_party.nodeinfo.jrd.json new file mode 100644 index 0000000..a3e7405 --- /dev/null +++ b/acrate-hostmeta/tests/samples/junimo_party.nodeinfo.jrd.json @@ -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" + } + ] +}