test: deepen and complete project-wide test coverage (#297)

* test: deepen coverage for health doctor provider and tunnels

* test: add broad trait and module re-export coverage
This commit is contained in:
Chummy 2026-02-16 18:58:24 +08:00 committed by GitHub
parent 79a6f180a8
commit 49fcc7a2c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 1156 additions and 0 deletions

View file

@ -38,3 +38,77 @@ pub trait Channel: Send + Sync {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
struct DummyChannel;
#[async_trait]
impl Channel for DummyChannel {
fn name(&self) -> &str {
"dummy"
}
async fn send(&self, _message: &str, _recipient: &str) -> anyhow::Result<()> {
Ok(())
}
async fn listen(
&self,
tx: tokio::sync::mpsc::Sender<ChannelMessage>,
) -> anyhow::Result<()> {
tx.send(ChannelMessage {
id: "1".into(),
sender: "tester".into(),
content: "hello".into(),
channel: "dummy".into(),
timestamp: 123,
})
.await
.map_err(|e| anyhow::anyhow!(e.to_string()))
}
}
#[test]
fn channel_message_clone_preserves_fields() {
let message = ChannelMessage {
id: "42".into(),
sender: "alice".into(),
content: "ping".into(),
channel: "dummy".into(),
timestamp: 999,
};
let cloned = message.clone();
assert_eq!(cloned.id, "42");
assert_eq!(cloned.sender, "alice");
assert_eq!(cloned.content, "ping");
assert_eq!(cloned.channel, "dummy");
assert_eq!(cloned.timestamp, 999);
}
#[tokio::test]
async fn default_trait_methods_return_success() {
let channel = DummyChannel;
assert!(channel.health_check().await);
assert!(channel.start_typing("bob").await.is_ok());
assert!(channel.stop_typing("bob").await.is_ok());
assert!(channel.send("hello", "bob").await.is_ok());
}
#[tokio::test]
async fn listen_sends_message_to_channel() {
let channel = DummyChannel;
let (tx, mut rx) = tokio::sync::mpsc::channel(1);
channel.listen(tx).await.unwrap();
let received = rx.recv().await.expect("message should be sent");
assert_eq!(received.sender, "tester");
assert_eq!(received.content, "hello");
assert_eq!(received.channel, "dummy");
}
}