Skip to main content

ComponentTestHarness

Struct ComponentTestHarness 

Source
pub struct ComponentTestHarness<C: Component> { /* private fields */ }
Expand description

Test harness for Component implementations.

Provides a minimal testing environment for components without requiring OrcsEngine or EventBus.

Implementations§

Source§

impl<C: Component> ComponentTestHarness<C>

Source

pub fn new(component: C) -> Self

Creates a new test harness for the given component.

Source

pub fn component(&self) -> &C

Returns a reference to the component under test.

Source

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

Returns a mutable reference to the component under test.

Source

pub fn init(&mut self) -> Result<(), ComponentError>

Calls init() on the component with an empty config.

§Errors

Returns the component’s initialization error if any.

Source

pub fn init_with_config(&mut self, config: &Value) -> Result<(), ComponentError>

Calls init() on the component with the given config.

§Errors

Returns the component’s initialization error if any.

Source

pub fn send_request( &mut self, request: &Request, ) -> Result<Value, ComponentError>

Sends a request to the component and logs the result.

§Arguments
  • request - The request to send
§Returns

The result of the request.

Source

pub fn request( &mut self, category: EventCategory, operation: &str, payload: Value, ) -> Result<Value, ComponentError>

Sends a request with the given category, operation, and payload.

Convenience method that builds the request internally.

§Arguments
  • category - Event category
  • operation - Operation name
  • payload - Request payload
§Returns

The result of the request.

Source

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

Sends a signal to the component and logs the response.

§Arguments
  • signal - The signal to send
§Returns

The component’s response to the signal.

Source

pub fn veto(&mut self) -> SignalResponse

Sends a Veto signal to the component.

§Returns

The component’s response (should be Abort).

Source

pub fn cancel(&mut self) -> SignalResponse

Sends a Cancel signal for the test channel.

§Returns

The component’s response.

Source

pub fn cancel_channel(&mut self, channel: ChannelId) -> SignalResponse

Sends a Cancel signal for a specific channel.

§Arguments
  • channel - The channel to cancel
§Returns

The component’s response.

Source

pub fn approve(&mut self, approval_id: &str) -> SignalResponse

Sends an Approve signal.

§Arguments
  • approval_id - The approval request ID
§Returns

The component’s response.

Source

pub fn reject( &mut self, approval_id: &str, reason: Option<String>, ) -> SignalResponse

Sends a Reject signal.

§Arguments
  • approval_id - The approval request ID
  • reason - Optional rejection reason
§Returns

The component’s response.

Source

pub fn abort(&mut self)

Calls abort() on the component.

Source

pub fn shutdown(&mut self)

Calls shutdown() on the component.

Source

pub fn status(&self) -> Status

Returns the current status of the component.

Source

pub fn id(&self) -> &ComponentId

Returns the component ID.

Source

pub fn request_log(&self) -> &[RequestRecord]

Returns the request log for snapshot testing.

Source

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

Returns the signal log for snapshot testing.

Source

pub fn clear_logs(&mut self)

Clears all logs.

Source

pub fn test_channel(&self) -> ChannelId

Returns the test channel ID.

Source

pub fn with_channel(self, channel: ChannelId) -> Self

Sets a custom test channel ID.

Auto Trait Implementations§

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.