pub struct TestJobContext {
pub job_id: Uuid,
pub job_type: String,
pub attempt: u32,
pub max_attempts: u32,
pub auth: AuthContext,
/* private fields */
}Expand description
Test context for job functions.
Provides an isolated testing environment for jobs with progress tracking, retry simulation, and HTTP mocking.
§Example
ⓘ
let ctx = TestJobContext::builder("export_users")
.with_job_id(Uuid::new_v4())
.build();
// Simulate progress
ctx.progress(50, "Halfway there")?;
// Verify progress was recorded
assert_eq!(ctx.progress_updates().len(), 1);Fields§
§job_id: UuidJob ID.
job_type: StringJob type name.
attempt: u32Current attempt number (1-based).
max_attempts: u32Maximum attempts allowed.
auth: AuthContextAuthentication context.
Implementations§
Source§impl TestJobContext
impl TestJobContext
Sourcepub fn builder(job_type: impl Into<String>) -> TestJobContextBuilder
pub fn builder(job_type: impl Into<String>) -> TestJobContextBuilder
Create a new builder.
Sourcepub fn progress(
&self,
percent: u8,
message: impl Into<String>,
) -> Result<(), ForgeError>
pub fn progress( &self, percent: u8, message: impl Into<String>, ) -> Result<(), ForgeError>
Report job progress.
Sourcepub fn progress_updates(&self) -> Vec<TestProgressUpdate>
pub fn progress_updates(&self) -> Vec<TestProgressUpdate>
Get all progress updates.
Sourcepub fn is_last_attempt(&self) -> bool
pub fn is_last_attempt(&self) -> bool
Check if this is the last attempt.
Sourcepub async fn heartbeat(&self) -> Result<(), ForgeError>
pub async fn heartbeat(&self) -> Result<(), ForgeError>
Simulate heartbeat (no-op in tests, but records the intent).
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 TestJobContext
impl EnvAccess for TestJobContext
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 TestJobContext
impl !RefUnwindSafe for TestJobContext
impl Send for TestJobContext
impl Sync for TestJobContext
impl Unpin for TestJobContext
impl !UnwindSafe for TestJobContext
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