pub struct StaticReplayClient { /* private fields */ }
Available on crate features client and test-util only.
Expand description

Request/response replaying client for use in tests.

This mock client takes a list of request/response pairs named ReplayEvent. While the client is in use, the responses will be given in the order they appear in the list regardless of what the actual request was. The actual request is recorded, but otherwise not validated against what is in the ReplayEvent. Later, after the client is finished being used, the assert_requests_match method can be used to validate the requests.

This utility is simpler than DVR, and thus, is good for tests that don’t need to record and replay real traffic.

§Example

use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient};
use aws_smithy_types::body::SdkBody;

let http_client = StaticReplayClient::new(vec![
    // Event that covers the first request/response
    ReplayEvent::new(
        // If `assert_requests_match` is called later, then this request will be matched
        // against the actual request that was made.
        http::Request::builder().uri("http://localhost:1234/foo").body(SdkBody::empty()).unwrap(),
        // This response will be given to the first request regardless of whether it matches the request above.
        http::Response::builder().status(200).body(SdkBody::empty()).unwrap(),
    ),
    // The next ReplayEvent covers the second request/response pair...
]);

let config = my_generated_client::Config::builder()
    .http_client(http_client.clone())
    .build();
let client = my_generated_client::Client::from_conf(config);

// Do stuff with client...

// When you're done, assert the requests match what you expected
http_client.assert_requests_match(&[]);

Implementations§

source§

impl StaticReplayClient

source

pub fn new(data: Vec<ReplayEvent>) -> Self

Creates a new event connector.

source

pub fn actual_requests(&self) -> impl Iterator<Item = &HttpRequest> + '_

Returns an iterator over the actual requests that were made.

source

pub fn assert_requests_match(&self, ignore_headers: &[&str])

Asserts the expected requests match the actual requests.

The expected requests are given as the connection events when the EventConnector is created. The EventConnector will record the actual requests and assert that they match the expected requests.

A list of headers that should be ignored when comparing requests can be passed for cases where headers are non-deterministic or are irrelevant to the test.

Trait Implementations§

source§

impl Clone for StaticReplayClient

source§

fn clone(&self) -> StaticReplayClient

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for StaticReplayClient

source§

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

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

impl HttpClient for StaticReplayClient

source§

fn http_connector( &self, _: &HttpConnectorSettings, _: &RuntimeComponents ) -> SharedHttpConnector

Returns a HTTP connector based on the requested connector settings. Read more
source§

fn validate_base_client_config( &self, runtime_components: &RuntimeComponentsBuilder, cfg: &ConfigBag ) -> Result<(), Box<dyn Error + Sync + Send>>

Validate the base client configuration. Read more
source§

fn validate_final_config( &self, runtime_components: &RuntimeComponents, cfg: &ConfigBag ) -> Result<(), Box<dyn Error + Sync + Send>>

Validate the final client configuration. Read more
source§

impl HttpConnector for StaticReplayClient

source§

fn call(&self, request: HttpRequest) -> HttpConnectorFuture

Asynchronously converts a request into a response.

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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

§

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<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