pub struct ChildTestHarness<C: Child> { /* private fields */ }Expand description
Test harness for Child trait implementations.
Provides signal handling and status testing for any Child.
For testing run(), use SyncChildTestHarness or AsyncChildTestHarness.
§Example
use orcs_component::testing::ChildTestHarness;
use orcs_component::{Child, Identifiable, SignalReceiver, Statusable, Status};
use orcs_event::{Signal, SignalResponse};
struct PassiveChild {
id: String,
status: Status,
}
impl Identifiable for PassiveChild {
fn id(&self) -> &str { &self.id }
}
impl SignalReceiver for PassiveChild {
fn on_signal(&mut self, signal: &Signal) -> SignalResponse {
if signal.is_veto() {
self.abort();
SignalResponse::Abort
} else {
SignalResponse::Handled
}
}
fn abort(&mut self) { self.status = Status::Aborted; }
}
impl Statusable for PassiveChild {
fn status(&self) -> Status { self.status }
}
impl Child for PassiveChild {}
let child = PassiveChild { id: "test".into(), status: Status::Idle };
let mut harness = ChildTestHarness::new(child);
assert_eq!(harness.status(), Status::Idle);
harness.veto();
assert_eq!(harness.status(), Status::Aborted);Implementations§
Source§impl<C: Child> ChildTestHarness<C>
impl<C: Child> ChildTestHarness<C>
Sourcepub fn send_signal(&mut self, signal: Signal) -> SignalResponse
pub fn send_signal(&mut self, signal: Signal) -> SignalResponse
Sends a signal to the child and logs the response.
Sourcepub fn veto(&mut self) -> SignalResponse
pub fn veto(&mut self) -> SignalResponse
Sends a Veto signal to the child.
Sourcepub fn cancel(&mut self) -> SignalResponse
pub fn cancel(&mut self) -> SignalResponse
Sends a Cancel signal to the child.
Sourcepub fn signal_log(&self) -> &[SignalRecord]
pub fn signal_log(&self) -> &[SignalRecord]
Returns the signal log for snapshot testing.
Sourcepub fn clear_logs(&mut self)
pub fn clear_logs(&mut self)
Clears all logs.
Auto Trait Implementations§
impl<C> Freeze for ChildTestHarness<C>where
C: Freeze,
impl<C> RefUnwindSafe for ChildTestHarness<C>where
C: RefUnwindSafe,
impl<C> Send for ChildTestHarness<C>
impl<C> Sync for ChildTestHarness<C>
impl<C> Unpin for ChildTestHarness<C>where
C: Unpin,
impl<C> UnsafeUnpin for ChildTestHarness<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for ChildTestHarness<C>where
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more