pub struct MatrixMock<'a> { /* private fields */ }testing) and non-target_family=wasm 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 MatrixMocks.
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 MatrixMocks will be active until
the MatrixMockServer is shut down.
When using mount_as_scoped, your MatrixMocks 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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
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