pub struct MockJobDispatch { /* private fields */ }Expand description
Mock job dispatcher for testing.
Records dispatched jobs for later verification.
§Example
ⓘ
let dispatch = MockJobDispatch::new();
dispatch.dispatch("send_email", json!({"to": "test@example.com"})).await?;
dispatch.assert_dispatched("send_email");
dispatch.assert_dispatched_with("send_email", |args| {
args["to"] == "test@example.com"
});Implementations§
Source§impl MockJobDispatch
impl MockJobDispatch
Sourcepub fn new() -> MockJobDispatch
pub fn new() -> MockJobDispatch
Create a new mock job dispatcher.
Sourcepub async fn dispatch<T>(
&self,
job_type: &str,
args: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
pub async fn dispatch<T>(
&self,
job_type: &str,
args: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
Dispatch a job (records for later verification).
Sourcepub fn dispatched_jobs(&self) -> Vec<DispatchedJob>
pub fn dispatched_jobs(&self) -> Vec<DispatchedJob>
Get all dispatched jobs.
Sourcepub fn jobs_of_type(&self, job_type: &str) -> Vec<DispatchedJob>
pub fn jobs_of_type(&self, job_type: &str) -> Vec<DispatchedJob>
Get jobs of a specific type.
Sourcepub fn assert_dispatched(&self, job_type: &str)
pub fn assert_dispatched(&self, job_type: &str)
Assert that a job type was dispatched.
Sourcepub fn assert_dispatched_with<F>(&self, job_type: &str, predicate: F)
pub fn assert_dispatched_with<F>(&self, job_type: &str, predicate: F)
Assert that a job was dispatched with matching arguments.
Sourcepub fn assert_not_dispatched(&self, job_type: &str)
pub fn assert_not_dispatched(&self, job_type: &str)
Assert that a job type was not dispatched.
Sourcepub fn assert_dispatch_count(&self, job_type: &str, expected: usize)
pub fn assert_dispatch_count(&self, job_type: &str, expected: usize)
Assert that a specific number of jobs were dispatched.
Sourcepub fn complete_job(&self, job_id: Uuid)
pub fn complete_job(&self, job_id: Uuid)
Mark a job as completed (for test simulation).
Trait Implementations§
Source§impl Default for MockJobDispatch
impl Default for MockJobDispatch
Source§fn default() -> MockJobDispatch
fn default() -> MockJobDispatch
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for MockJobDispatch
impl RefUnwindSafe for MockJobDispatch
impl Send for MockJobDispatch
impl Sync for MockJobDispatch
impl Unpin for MockJobDispatch
impl UnwindSafe for MockJobDispatch
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