Struct LavaMock

Source
pub struct LavaMock { /* private fields */ }
Expand description

A mock server that provides access to a SharedState.

This provides the following endpoints from the v0.2 Lava REST API:

  • /api/v0.2/aliases/
  • /api/v0.2/devices/
  • /api/v0.2/devicetypes/
  • /api/v0.2/jobs/
  • /api/v0.2/tags/
  • /api/v0.2/workers/

It also provides the following nested endpoints for jobs:

  • /api/v0.2/jobs/<id>/tests/
  • /api/v0.2/jobs/<id>/suites/

You can use uri to find the initial portion of the URL for your test instance.

The mock object does not support the Lava mutation endpoints, but you can mutate the provided SharedState directly for testing. There are two ways to do this:

Implementations§

Source§

impl LavaMock

Source

pub async fn new(p: SharedState, limits: PaginationLimits) -> LavaMock

Create and start a new LavaMock

Here p is the SharedState becomes the underlying data source for the mock, and limits are the default pagination limits as a PaginationLimits object, which are applied when the client does not give any.

Source

pub async fn start() -> Self

Create and start a default new LavaMock.

This mock will have a default SharedState and default PaginationLimits. This gives a mock object with an empty data store, and no default pagination (so if the client does not request pagination, all matching data will be returned).

Source

pub fn uri(&self) -> String

Return the URI of the server.

This object is based on a wiremock server, and as such it will usually be bound to an ephemeral port.

Source

pub fn state(&self) -> Arc<State>

Read a read-only view of the current state of the data store.

Note that the data store is not currently prevented from evolving while this snapshot is held, because the underlying synchronisation mechanism is a CloneReplace.

Source

pub fn state_mut(&mut self) -> MutateGuard<State>

Read a mutable view of the current state of the data store.

Note that the data store is not currently prevented from evolving while this snapshot is held, because the underlying synchronisation mechanism is a CloneReplace. Other writers are not prevented from acting on the data store, and their changes will be lost when this guard is flushed. Note that changes from a MutateGuard only take effect when the guard is dropped.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,