pub struct MockInterceptor { /* private fields */ }Expand description
A StepInterceptor built from closures.
Built by TestEngine; a step kind with no
mock attached falls through to the real executor.
§Examples
use ironflow_engine::config::{ShellConfig, StepConfig};
use ironflow_engine::executor::StepInterceptor;
use ironflow_engine::testing::{MockInterceptor, MockShellOutput};
let interceptor = MockInterceptor::new().shell(|_cfg| Ok(MockShellOutput::ok("mocked")));
let config = StepConfig::Shell(ShellConfig::new("./deploy.sh"));
let output = interceptor
.intercept(&config)
.expect("shell steps are mocked")
.expect("the mock succeeded");
assert_eq!(output.stdout(), "mocked");Implementations§
Source§impl MockInterceptor
impl MockInterceptor
Sourcepub fn new() -> Self
pub fn new() -> Self
An interceptor that mocks nothing.
§Examples
use ironflow_engine::config::{ShellConfig, StepConfig};
use ironflow_engine::executor::StepInterceptor;
use ironflow_engine::testing::MockInterceptor;
let interceptor = MockInterceptor::new();
let config = StepConfig::Shell(ShellConfig::new("echo hi"));
assert!(interceptor.intercept(&config).is_none());Sourcepub fn shell(
self,
f: impl Fn(&ShellConfig) -> Result<MockShellOutput, OperationError> + Send + Sync + 'static,
) -> Self
pub fn shell( self, f: impl Fn(&ShellConfig) -> Result<MockShellOutput, OperationError> + Send + Sync + 'static, ) -> Self
Answer every shell step with f.
§Examples
use ironflow_engine::testing::{MockInterceptor, MockShellOutput};
let interceptor = MockInterceptor::new()
.shell(|cfg| Ok(MockShellOutput::ok(&format!("ran {}", cfg.command))));Sourcepub fn http(
self,
f: impl Fn(&HttpConfig) -> Result<MockHttpResponse, OperationError> + Send + Sync + 'static,
) -> Self
pub fn http( self, f: impl Fn(&HttpConfig) -> Result<MockHttpResponse, OperationError> + Send + Sync + 'static, ) -> Self
Answer every HTTP step with f.
§Examples
use ironflow_engine::testing::{MockHttpResponse, MockInterceptor};
use serde_json::json;
let interceptor = MockInterceptor::new()
.http(|_cfg| Ok(MockHttpResponse::ok(&json!({"ok": true}))));Sourcepub fn approval(self, outcome: ApprovalOutcome) -> Self
pub fn approval(self, outcome: ApprovalOutcome) -> Self
Resolve every approval gate with outcome.
§Examples
use ironflow_engine::testing::{ApprovalOutcome, MockInterceptor};
let interceptor = MockInterceptor::new().approval(ApprovalOutcome::Approved);Sourcepub fn human_input(
self,
f: impl Fn(&str, &HumanInputConfig) -> HumanInputOutcome + Send + Sync + 'static,
) -> Self
pub fn human_input( self, f: impl Fn(&str, &HumanInputConfig) -> HumanInputOutcome + Send + Sync + 'static, ) -> Self
Answer every human input step with f.
§Examples
use ironflow_engine::testing::{HumanInputOutcome, MockInterceptor};
use serde_json::json;
let interceptor = MockInterceptor::new()
.human_input(|_name, _cfg| HumanInputOutcome::Provided(json!({"answers": ["yes"]})));Trait Implementations§
Source§impl Clone for MockInterceptor
impl Clone for MockInterceptor
Source§impl Debug for MockInterceptor
impl Debug for MockInterceptor
Source§impl Default for MockInterceptor
impl Default for MockInterceptor
Source§impl StepInterceptor for MockInterceptor
impl StepInterceptor for MockInterceptor
Source§fn intercept(
&self,
config: &StepConfig,
) -> Option<Result<StepOutput, EngineError>>
fn intercept( &self, config: &StepConfig, ) -> Option<Result<StepOutput, EngineError>>
Return
Some(result) to short-circuit this step, None to execute it
for real.Source§fn intercept_approval(
&self,
_name: &str,
_config: &ApprovalConfig,
) -> Option<ApprovalOutcome>
fn intercept_approval( &self, _name: &str, _config: &ApprovalConfig, ) -> Option<ApprovalOutcome>
Resolve an approval gate instead of suspending the run. Read more
Source§fn intercept_human_input(
&self,
name: &str,
config: &HumanInputConfig,
_schema: &Value,
) -> Option<HumanInputOutcome>
fn intercept_human_input( &self, name: &str, config: &HumanInputConfig, _schema: &Value, ) -> Option<HumanInputOutcome>
Answer a human input step instead of suspending the run. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for MockInterceptor
impl !UnwindSafe for MockInterceptor
impl Freeze for MockInterceptor
impl Send for MockInterceptor
impl Sync for MockInterceptor
impl Unpin for MockInterceptor
impl UnsafeUnpin for MockInterceptor
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