Module wire

Source
Available on crate features client and test-util and connector-hyper-0-14-x and wire-mock only.
Expand description

Utilities for mocking at the socket level

Other tools in this module actually operate at the http::Request / http::Response level. This is useful, but it shortcuts the HTTP implementation (e.g. Hyper). WireMockServer binds to an actual socket on the host.

§Examples

use aws_smithy_runtime_api::client::http::HttpConnectorSettings;
use aws_smithy_runtime::client::http::test_util::wire::{check_matches, ReplayedEvent, WireMockServer};
use aws_smithy_runtime::{match_events, ev};

// This connection binds to a local address
let mock = WireMockServer::start(vec![
    ReplayedEvent::status(503),
    ReplayedEvent::status(200)
]).await;

// Create a client using the wire mock
let config = my_generated_client::Config::builder()
    .http_client(mock.http_client())
    .build();
let client = Client::from_conf(config);

// ... do something with <client>

// assert that you got the events you expected
match_events!(ev!(dns), ev!(connect), ev!(http(200)))(&mock.events());

Macros§

ev
Helper to generate match expressions for events
match_events
Helper macro to generate a series of test expectations
matcher

Structs§

LoggingDnsResolver
DNS resolver that keeps a log of all lookups
WireMockServer
Test server that binds to 127.0.0.1:0

Enums§

RecordedEvent
An event recorded by WireMockServer.
ReplayedEvent

Functions§

check_matches
This method should only be used by the macro