pub struct TestWorkflowContext {
pub run_id: Uuid,
pub workflow_name: String,
pub version: u32,
pub started_at: DateTime<Utc>,
pub auth: AuthContext,
/* private fields */
}Expand description
Test context for workflow functions.
Provides an isolated testing environment for workflows with step tracking, resume simulation, and durable sleep verification.
§Example
ⓘ
let ctx = TestWorkflowContext::builder("account_verification")
.with_run_id(Uuid::new_v4())
.build();
ctx.record_step_start("validate_email");
ctx.record_step_complete("validate_email", json!({"valid": true}));
assert!(ctx.is_step_completed("validate_email"));Fields§
§run_id: UuidWorkflow run ID.
workflow_name: StringWorkflow name.
version: u32Workflow version.
started_at: DateTime<Utc>When the workflow started.
auth: AuthContextAuthentication context.
Implementations§
Source§impl TestWorkflowContext
impl TestWorkflowContext
Sourcepub fn builder(workflow_name: impl Into<String>) -> TestWorkflowContextBuilder
pub fn builder(workflow_name: impl Into<String>) -> TestWorkflowContextBuilder
Create a new builder.
Sourcepub fn is_resumed(&self) -> bool
pub fn is_resumed(&self) -> bool
Check if this is a resumed execution.
Sourcepub fn workflow_time(&self) -> DateTime<Utc>
pub fn workflow_time(&self) -> DateTime<Utc>
Get the deterministic workflow time.
Sourcepub fn is_step_completed(&self, name: &str) -> bool
pub fn is_step_completed(&self, name: &str) -> bool
Check if a step is completed.
Sourcepub fn is_step_started(&self, name: &str) -> bool
pub fn is_step_started(&self, name: &str) -> bool
Check if a step has been started (exists in step states).
Sourcepub fn get_step_result<T>(&self, name: &str) -> Option<T>where
T: DeserializeOwned,
pub fn get_step_result<T>(&self, name: &str) -> Option<T>where
T: DeserializeOwned,
Get the result of a completed step.
Sourcepub fn record_step_start(&self, name: &str)
pub fn record_step_start(&self, name: &str)
Record step start.
Sourcepub fn record_step_complete(&self, name: &str, result: Value)
pub fn record_step_complete(&self, name: &str, result: Value)
Record step completion.
Sourcepub async fn record_step_complete_async(&self, name: &str, result: Value)
pub async fn record_step_complete_async(&self, name: &str, result: Value)
Record step completion (async version for API compatibility).
Sourcepub fn completed_step_names(&self) -> Vec<String>
pub fn completed_step_names(&self) -> Vec<String>
Get completed step names in order.
Sourcepub async fn sleep(&self, _duration: Duration) -> Result<(), ForgeError>
pub async fn sleep(&self, _duration: Duration) -> Result<(), ForgeError>
Durable sleep (no-op in tests, but records the intent).
Sourcepub fn sleep_called(&self) -> bool
pub fn sleep_called(&self) -> bool
Check if sleep was called.
Sourcepub fn env_mock(&self) -> &MockEnvProvider
pub fn env_mock(&self) -> &MockEnvProvider
Get the mock env provider for verification.
Trait Implementations§
Source§impl EnvAccess for TestWorkflowContext
impl EnvAccess for TestWorkflowContext
Source§fn env_provider(&self) -> &dyn EnvProvider
fn env_provider(&self) -> &dyn EnvProvider
Get the environment provider.
Source§fn env_or(&self, key: &str, default: &str) -> String
fn env_or(&self, key: &str, default: &str) -> String
Get an environment variable with a default value. Read more
Source§fn env_require(&self, key: &str) -> Result<String, ForgeError>
fn env_require(&self, key: &str) -> Result<String, ForgeError>
Get a required environment variable. Read more
Source§fn env_parse<T>(&self, key: &str) -> Result<T, ForgeError>
fn env_parse<T>(&self, key: &str) -> Result<T, ForgeError>
Get an environment variable and parse it to the specified type. Read more
Source§fn env_parse_or<T>(&self, key: &str, default: T) -> Result<T, ForgeError>
fn env_parse_or<T>(&self, key: &str, default: T) -> Result<T, ForgeError>
Get an environment variable and parse it, with a default. Read more
Source§fn env_contains(&self, key: &str) -> bool
fn env_contains(&self, key: &str) -> bool
Check if an environment variable is set.
Auto Trait Implementations§
impl Freeze for TestWorkflowContext
impl !RefUnwindSafe for TestWorkflowContext
impl Send for TestWorkflowContext
impl Sync for TestWorkflowContext
impl Unpin for TestWorkflowContext
impl !UnwindSafe for TestWorkflowContext
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more