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
impl MemoryTransport
pub fn new() -> Self
Sourcepub fn script(self, method: MethodRef, items: Vec<StreamItem>) -> Self
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.
Sourcepub fn script_failure(self, method: MethodRef, error: TransportError) -> Self
pub fn script_failure(self, method: MethodRef, error: TransportError) -> Self
Script a transport failure — the connection dying instead of the server answering.
Sourcepub fn script_events<E: Serialize>(
self,
method: MethodRef,
events: &[E],
) -> Self
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.
Trait Implementations§
Source§impl Debug for MemoryTransport
impl Debug for MemoryTransport
Source§impl Default for MemoryTransport
impl Default for MemoryTransport
Source§impl Transport for MemoryTransport
impl Transport for MemoryTransport
Auto Trait Implementations§
impl !Freeze for MemoryTransport
impl RefUnwindSafe for MemoryTransport
impl Send for MemoryTransport
impl Sync for MemoryTransport
impl Unpin for MemoryTransport
impl UnsafeUnpin for MemoryTransport
impl UnwindSafe for MemoryTransport
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