pub struct SnapshotRequestor { /* private fields */ }
Expand description
Replays an RPC response to a request if it is found in the snapshot YAML file.
If no such request has been seen before,
it captures the new request/response pair obtained from the inner HttpRequestor
and stores it into the snapshot file.
This is useful for snapshot testing only and should NOT be used in production.
Implementations§
Source§impl SnapshotRequestor
impl SnapshotRequestor
Sourcepub fn new(snapshot_file: &str) -> Self
pub fn new(snapshot_file: &str) -> Self
Creates a new instance by wrapping an existing HttpRequestor
and capturing
the request/response pairs.
The constructor does not load any snapshot entries from
the snapshot_file
.
The [SnapshotRequestorLayer::load
] method must be used after construction to do that.
Sourcepub fn snapshot_path(&self) -> &str
pub fn snapshot_path(&self) -> &str
Gets the path to the snapshot disk file.
Sourcepub fn clear(&self)
pub fn clear(&self)
Clears all entries from the snapshot in memory. The snapshot file is not changed.
Sourcepub async fn try_load(&mut self, fail_on_miss: bool) -> Result<(), Error>
pub async fn try_load(&mut self, fail_on_miss: bool) -> Result<(), Error>
Clears all entries and loads them from the snapshot file.
If fail_on_miss
is set and the data is successfully loaded, all later
requests that miss the loaded snapshot will result in HTTP error 404.
Sourcepub async fn load(self, fail_on_miss: bool) -> Self
pub async fn load(self, fail_on_miss: bool) -> Self
Similar as [SnapshotRequestorLayer::try_load
], except that no entries are cleared if the load fails.
This method consumes and returns self for easier call chaining.
Sourcepub fn with_aggresive_save(self) -> Self
pub fn with_aggresive_save(self) -> Self
Forces saving to disk on each newly inserted entry.
Use this only when the expected number of entries in the snapshot is small.
Sourcepub fn with_ignore_snapshot(self, ignore_snapshot: bool) -> Self
pub fn with_ignore_snapshot(self, ignore_snapshot: bool) -> Self
Trait Implementations§
Source§impl Clone for SnapshotRequestor
impl Clone for SnapshotRequestor
Source§fn clone(&self) -> SnapshotRequestor
fn clone(&self) -> SnapshotRequestor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SnapshotRequestor
impl Debug for SnapshotRequestor
Auto Trait Implementations§
impl Freeze for SnapshotRequestor
impl !RefUnwindSafe for SnapshotRequestor
impl Send for SnapshotRequestor
impl Sync for SnapshotRequestor
impl Unpin for SnapshotRequestor
impl !UnwindSafe for SnapshotRequestor
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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