Skip to main content

MemoryTransport

Struct MemoryTransport 

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

A Transport that answers from a script and records what it was asked.

use plexus_client::{collect_data, decode, MemoryTransport, MethodRef, Transport};

#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
struct Ev { n: u8 }

const COUNT: MethodRef = MethodRef::new("demo", "count");

let t = MemoryTransport::new().script_events(COUNT, &[Ev { n: 1 }, Ev { n: 2 }]);
let events = futures::executor::block_on(async {
    collect_data(decode::<Ev>(t.call(COUNT, serde_json::json!({})))).await
})
.unwrap();

assert_eq!(events, vec![Ev { n: 1 }, Ev { n: 2 }]);
assert_eq!(t.params_of(COUNT), Some(serde_json::json!({})));

Implementations§

Source§

impl MemoryTransport

Source

pub fn new() -> Self

Source

pub fn script(self, method: MethodRef, items: Vec<StreamItem>) -> Self

Script the raw wire items a method answers with. Use this to exercise the shapes only a real transport produces — progress, an in-band error, a data item with the wrong payload.

Source

pub fn script_failure(self, method: MethodRef, error: TransportError) -> Self

Script a transport failure — the connection dying instead of the server answering.

Source

pub fn script_events<E: Serialize>( self, method: MethodRef, events: &[E], ) -> Self

Script the happy path: each event becomes a data item stamped with the method’s content_type, followed by done.

Serialization uses the event type’s own Serialize, so a script written against the server’s event enum cannot drift from what the server would actually put on the wire.

Source

pub fn calls(&self) -> Vec<(String, Value)>

Every call this transport received, in order, as ("namespace.method", params).

Source

pub fn params_of(&self, method: MethodRef) -> Option<Value>

The params of the single call to method, or None if it was not called exactly once.

Trait Implementations§

Source§

impl Debug for MemoryTransport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MemoryTransport

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Transport for MemoryTransport

Source§

fn call(&self, method: MethodRef, params: Value) -> ItemStream<'_>

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, 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.