refactor: typed errors in rss/import ports

This commit is contained in:
2026-10-25 20:30:28 +01:00
parent 18c179e14c
commit 59238a36d8
17 changed files with 410 additions and 392 deletions

View File

@@ -51,47 +51,5 @@ pub trait ApBackfillPort: Send + Sync {
}
#[cfg(test)]
mod tests {
use super::*;
use crate::ports::noop::{NoopApBackfill, NoopApDocument, NoopInstanceBlocklist};
#[tokio::test]
async fn noop_document_returns_empty_strings() {
let p = NoopApDocument;
assert_eq!(p.actor_json("anything").await.unwrap(), "");
assert_eq!(
p.followers_collection_json(uuid::Uuid::nil(), None)
.await
.unwrap(),
""
);
assert_eq!(
p.following_collection_json(uuid::Uuid::nil(), Some(2))
.await
.unwrap(),
""
);
}
#[tokio::test]
async fn noop_blocklist_returns_empty_and_ok() {
let p = NoopInstanceBlocklist;
assert!(p.get_blocked_domains().await.unwrap().is_empty());
p.add_blocked_domain("evil.example", Some("spam"))
.await
.unwrap();
p.remove_blocked_domain("evil.example").await.unwrap();
}
#[tokio::test]
async fn noop_backfill_returns_empty_and_ok() {
let p = NoopApBackfill;
assert!(p.get_following(uuid::Uuid::nil()).await.unwrap().is_empty());
p.import_remote_outbox("https://a/outbox", "https://a")
.await
.unwrap();
p.run_backfill_for_follower(uuid::Uuid::nil(), "https://a/inbox".into())
.await
.unwrap();
}
}
#[path = "tests/federation.rs"]
mod tests;

View File

@@ -1,3 +1,4 @@
use crate::errors::DomainError;
use crate::models::DiaryEntry;
/// Channel-level metadata for a rendered feed. Paths are site-relative
@@ -15,5 +16,5 @@ pub trait RssFeedRenderer: Send + Sync {
&self,
entries: &[DiaryEntry],
channel: &FeedChannel<'_>,
) -> Result<String, String>;
) -> Result<String, DomainError>;
}

View File

@@ -0,0 +1,42 @@
use super::*;
use crate::ports::noop::{NoopApBackfill, NoopApDocument, NoopInstanceBlocklist};
#[tokio::test]
async fn noop_document_returns_empty_strings() {
let p = NoopApDocument;
assert_eq!(p.actor_json("anything").await.unwrap(), "");
assert_eq!(
p.followers_collection_json(uuid::Uuid::nil(), None)
.await
.unwrap(),
""
);
assert_eq!(
p.following_collection_json(uuid::Uuid::nil(), Some(2))
.await
.unwrap(),
""
);
}
#[tokio::test]
async fn noop_blocklist_returns_empty_and_ok() {
let p = NoopInstanceBlocklist;
assert!(p.get_blocked_domains().await.unwrap().is_empty());
p.add_blocked_domain("evil.example", Some("spam"))
.await
.unwrap();
p.remove_blocked_domain("evil.example").await.unwrap();
}
#[tokio::test]
async fn noop_backfill_returns_empty_and_ok() {
let p = NoopApBackfill;
assert!(p.get_following(uuid::Uuid::nil()).await.unwrap().is_empty());
p.import_remote_outbox("https://a/outbox", "https://a")
.await
.unwrap();
p.run_backfill_for_follower(uuid::Uuid::nil(), "https://a/inbox".into())
.await
.unwrap();
}