Add LemmyResult to sitemap tests

This commit is contained in:
netbrum 2024-09-30 21:48:43 +02:00
parent 0e594be1f0
commit 23ac0c1b86

View File

@ -49,14 +49,15 @@ pub(crate) mod tests {
use chrono::{DateTime, NaiveDate, Utc};
use elementtree::Element;
use lemmy_db_schema::newtypes::DbUrl;
use lemmy_utils::error::LemmyResult;
use pretty_assertions::assert_eq;
use url::Url;
#[tokio::test]
async fn test_generate_urlset() {
async fn test_generate_urlset() -> LemmyResult<()> {
let posts: Vec<(DbUrl, DateTime<Utc>)> = vec![
(
Url::parse("https://example.com").unwrap().into(),
Url::parse("https://example.com")?.into(),
NaiveDate::from_ymd_opt(2022, 12, 1)
.unwrap()
.and_hms_opt(9, 10, 11)
@ -64,7 +65,7 @@ pub(crate) mod tests {
.and_utc(),
),
(
Url::parse("https://lemmy.ml").unwrap().into(),
Url::parse("https://lemmy.ml")?.into(),
NaiveDate::from_ymd_opt(2023, 1, 1)
.unwrap()
.and_hms_opt(1, 2, 3)
@ -74,12 +75,8 @@ pub(crate) mod tests {
];
let mut buf = Vec::<u8>::new();
generate_urlset(posts)
.await
.unwrap()
.write(&mut buf)
.unwrap();
let root = Element::from_reader(buf.as_slice()).unwrap();
generate_urlset(posts).await?.write(&mut buf)?;
let root = Element::from_reader(buf.as_slice())?;
assert_eq!(root.tag().name(), "urlset");
assert_eq!(root.child_count(), 2);
@ -139,5 +136,7 @@ pub(crate) mod tests {
.text(),
"2023-01-01T01:02:03+00:00"
);
Ok(())
}
}