aws_smithy_http_client/test_util.rs
1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! Various fake/mock clients for testing.
7//!
8//! Each test client is useful for different test use cases:
9//! - [`capture_request()`]: If you don't care what the response is, but just want to
10//! check that the serialized request is what you expect, then use `capture_request`.
11//! Or, alternatively, if you don't care what the request is, but want to always
12//! respond with a given response, then capture request can also be useful since
13//! you can optionally give it a response to return.
14#![cfg_attr(
15 feature = "default-client",
16 doc = "- [`dvr`]: If you want to record real-world traffic and then replay it later, then DVR's"
17)]
18//! [`RecordingClient`](dvr::RecordingClient) and [`ReplayingClient`](dvr::ReplayingClient)
19//! can accomplish this, and the recorded traffic can be saved to JSON and checked in. Note: if
20//! the traffic recording has sensitive information in it, such as signatures or authorization,
21//! you will need to manually scrub this out if you intend to store the recording alongside
22//! your tests.
23//! - [`StaticReplayClient`]: If you want to have a set list of requests and their responses in a test,
24//! then the static replay client will be useful. On construction, it takes a list of request/response
25//! pairs that represent each expected request and the response for that test. At the end of the test,
26//! you can ask the client to verify that the requests matched the expectations.
27//! - [`infallible_client_fn`]: Allows you to create a client from an infallible function
28//! that takes a request and returns a response.
29//! - [`NeverClient`]: Useful for testing timeouts, where you want the client to never respond.
30//!
31#![cfg_attr(
32 any(feature = "hyper-014", feature = "default-client"),
33 doc = "
34There is also the [`NeverTcpConnector`], which makes it easy to test connect/read timeouts.
35
36Finally, for socket-level mocking, see the [`wire`] module.
37"
38)]
39
40mod capture_request;
41pub use capture_request::{capture_request, CaptureRequestHandler, CaptureRequestReceiver};
42
43#[cfg(feature = "legacy-test-util")]
44pub use capture_request::legacy_capture_request;
45
46pub mod dvr;
47
48mod replay;
49pub use replay::{ReplayEvent, StaticReplayClient};
50
51mod infallible;
52pub use infallible::infallible_client_fn;
53
54// infallible based on http_02x stack had to be duplicated to avoid breaking API changes
55#[allow(missing_docs)]
56#[cfg(feature = "legacy-test-util")]
57pub mod legacy_infallible;
58
59mod never;
60pub use never::NeverClient;
61
62#[cfg(any(feature = "hyper-014", feature = "default-client"))]
63pub use never::NeverTcpConnector;
64
65mod body;
66#[cfg(all(feature = "default-client", feature = "wire-mock"))]
67pub mod wire;