Available on crate features client and test-util only.
Expand description

Various fake/mock clients for testing.

Each test client is useful for different test use cases:

  • capture_request(): If you don’t care what the response is, but just want to check that the serialized request is what you expect, then use capture_request. Or, alternatively, if you don’t care what the request is, but want to always respond with a given response, then capture request can also be useful since you can optionally give it a response to return.
  • dvr: If you want to record real-world traffic and then replay it later, then DVR’s RecordingClient and ReplayingClient can accomplish this, and the recorded traffic can be saved to JSON and checked in. Note: if the traffic recording has sensitive information in it, such as signatures or authorization, you will need to manually scrub this out if you intend to store the recording alongside your tests.
  • StaticReplayClient: If you want to have a set list of requests and their responses in a test, then the static replay client will be useful. On construction, it takes a list of request/response pairs that represent each expected request and the response for that test. At the end of the test, you can ask the client to verify that the requests matched the expectations.
  • infallible_client_fn: Allows you to create a client from an infallible function that takes a request and returns a response.
  • NeverClient: Useful for testing timeouts, where you want the client to never respond.

There is also the NeverTcpConnector, which makes it easy to test connect/read timeouts.

Finally, for socket-level mocking, see the wire module.

Modules§

  • dvrconnector-hyper-0-14-x
    Extremely Experimental Test Connection
  • wireconnector-hyper-0-14-x and wire-mock
    Utilities for mocking at the socket level

Structs§

Functions§