pub struct MatrixMock<'a> { /* private fields */ }
testing
and non-WebAssembly only.Expand description
A wrapper for a Mock
as well as a MockServer
, allowing us to call
Mock::mount
or Mock::mount_as_scoped
without having to pass the
MockServer
reference (i.e. call mount()
instead of mount(&server)
).
Implementations§
Source§impl MatrixMock<'_>
impl MatrixMock<'_>
Sourcepub fn expect<T: Into<Times>>(self, num_calls: T) -> Self
pub fn expect<T: Into<Times>>(self, num_calls: T) -> Self
Set an expectation on the number of times this MatrixMock
should
match in the current test case.
Expectations are verified when the server is shutting down: if
the expectation is not satisfied, the MatrixMockServer
will panic
and the error_message
is shown.
By default, no expectation is set for MatrixMock
s.
Sourcepub fn named(self, name: impl Into<String>) -> Self
pub fn named(self, name: impl Into<String>) -> Self
Assign a name to your mock.
The mock name will be used in error messages (e.g. if the mock expectation is not satisfied) and debug logs to help you identify what failed.
Sourcepub fn mock_once(self) -> Self
pub fn mock_once(self) -> Self
Respond to a response of this endpoint exactly once.
After it’s been called, subsequent responses will hit the next handler or a 404.
Also verifies that it’s been called once.
Sourcepub fn up_to_n_times(self, num: u64) -> Self
pub fn up_to_n_times(self, num: u64) -> Self
Specify an upper limit to the number of times you would like this
MatrixMock
to respond to incoming requests that satisfy the
conditions imposed by your matchers.
Sourcepub async fn mount(self)
pub async fn mount(self)
Mount a MatrixMock
on the attached server.
The MatrixMock
will remain active until the MatrixMockServer
is
shut down. If you want to control or limit how long your
MatrixMock
stays active, check out Self::mount_as_scoped
.
Sourcepub async fn mount_as_scoped(self) -> MockGuard
pub async fn mount_as_scoped(self) -> MockGuard
Mount a MatrixMock
as scoped on the attached server.
When using Self::mount
, your MatrixMock
s will be active until
the MatrixMockServer
is shut down.
When using mount_as_scoped
, your MatrixMock
s will be active as
long as the returned MockGuard
is not dropped.
When the returned MockGuard
is dropped, MatrixMockServer
will
verify that the expectations set on the scoped MatrixMock
were
verified - if not, it will panic.
Auto Trait Implementations§
impl<'a> Freeze for MatrixMock<'a>
impl<'a> !RefUnwindSafe for MatrixMock<'a>
impl<'a> Send for MatrixMock<'a>
impl<'a> Sync for MatrixMock<'a>
impl<'a> Unpin for MatrixMock<'a>
impl<'a> !UnwindSafe for MatrixMock<'a>
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
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§fn consume_handle(handle: Handle) -> Arc<T>
fn consume_handle(handle: Handle) -> Arc<T>
Arc<>
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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