//! Centralised mock definitions for test crates. //! Sections are grouped by domain to keep the mapping between mocks and //! their intended test areas obvious. #![allow(dead_code)] use async_trait::async_trait; use mockall::mock; use std::net::SocketAddr; use std::time::{Duration, Instant}; pub mod predicates { #![allow(unused_imports)] pub use mockall::predicate::*; } // --- Auth domain ----------------------------------------------------------- mock! { pub CredentialStore {} #[async_trait] impl niom_turn::traits::CredentialStore for CredentialStore { async fn get_password(&self, username: &str) -> Option; } } // --- Allocation domain ----------------------------------------------------- #[async_trait] pub trait RelayIo: Send + Sync { async fn recv_from(&self, buf: &mut [u8]) -> std::io::Result<(usize, SocketAddr)>; async fn send_to(&self, buf: &[u8], target: SocketAddr) -> std::io::Result; } mock! { pub RelayIo {} #[async_trait] impl RelayIo for RelayIo { async fn recv_from(&self, buf: &mut [u8]) -> std::io::Result<(usize, SocketAddr)>; async fn send_to(&self, buf: &[u8], target: SocketAddr) -> std::io::Result; } } pub trait AllocationClock: Send + Sync { fn now(&self) -> Instant; fn advance(&self, delta: Duration); } mock! { pub AllocationClock {} impl AllocationClock for AllocationClock { fn now(&self) -> Instant; fn advance(&self, delta: Duration); } } // --- Channel domain -------------------------------------------------------- #[async_trait] pub trait ChannelSink: Send + Sync { async fn send_channel_data(&self, channel: u16, payload: Vec) -> anyhow::Result<()>; async fn send_data_indication(&self, peer: SocketAddr, payload: Vec) -> anyhow::Result<()>; } mock! { pub ChannelSink {} #[async_trait] impl ChannelSink for ChannelSink { async fn send_channel_data(&self, channel: u16, payload: Vec) -> anyhow::Result<()>; async fn send_data_indication(&self, peer: SocketAddr, payload: Vec) -> anyhow::Result<()>; } } // --- Config domain --------------------------------------------------------- pub trait ConfigSource: Send + Sync { fn load(&self) -> Result; } mock! { pub ConfigSource {} impl ConfigSource for ConfigSource { fn load(&self) -> Result; } } // --- Error/Parser domain --------------------------------------------------- #[async_trait] pub trait FrameStream: Send + Sync { async fn next_frame(&self) -> Option>; } mock! { pub FrameStream {} #[async_trait] impl FrameStream for FrameStream { async fn next_frame(&self) -> Option>; } }