Skip to main content

ChildTestHarness

Struct ChildTestHarness 

Source
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>

Source

pub fn new(child: C) -> Self

Creates a new test harness for the given child.

Source

pub fn child(&self) -> &C

Returns a reference to the child under test.

Source

pub fn child_mut(&mut self) -> &mut C

Returns a mutable reference to the child under test.

Source

pub fn id(&self) -> &str

Returns the child’s ID.

Source

pub fn status(&self) -> Status

Returns the current status of the child.

Source

pub fn send_signal(&mut self, signal: Signal) -> SignalResponse

Sends a signal to the child and logs the response.

Source

pub fn veto(&mut self) -> SignalResponse

Sends a Veto signal to the child.

Source

pub fn cancel(&mut self) -> SignalResponse

Sends a Cancel signal to the child.

Source

pub fn abort(&mut self)

Calls abort() on the child.

Source

pub fn signal_log(&self) -> &[SignalRecord]

Returns the signal log for snapshot testing.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.