17 breaking releases

0.48.0 Apr 25, 2022
0.47.0 Jun 30, 2021
0.46.0 Jan 6, 2021
0.45.0 Jul 22, 2020
0.25.0 Jun 25, 2017

#241 in Testing

Download history 2753/week @ 2023-12-08 2389/week @ 2023-12-15 1406/week @ 2023-12-22 2899/week @ 2023-12-29 3361/week @ 2024-01-05 2447/week @ 2024-01-12 2962/week @ 2024-01-19 3177/week @ 2024-01-26 3021/week @ 2024-02-02 3310/week @ 2024-02-09 2571/week @ 2024-02-16 2971/week @ 2024-02-23 2934/week @ 2024-03-01 2798/week @ 2024-03-08 2934/week @ 2024-03-15 2465/week @ 2024-03-22

11,648 downloads per month
Used in fewer than 227 crates

MIT license

105KB
2.5K SLoC

Mock request dispatcher and credentials for unit testing rusoto AWS service clients

All rusoto generated service clients come with a constuctor function named new_with which accepts three arguments

  • A rusoto_core::DispatchSignedRequest implementation
  • A rusoto_core::credential::ProvideAwsCredentials implementation
  • A rusoto_core::Region

This crate provides mock implementations to satisfy the first two.

Example

The following is an example for the rusoto_s3 crate but should work for all service crates just the same. The code is commented out for illustration but also to avoid a cyclic dependency in this crate.

extern crate rusoto_mock;
// extern crate rusoto_s3;

use rusoto_mock::{MockCredentialsProvider, MockRequestDispatcher, MockResponseReader};

fn main() {
   // let s3 = rusoto_s3::S3Client::new_with(
   //   MockRequestDispatcher::default().with_body(
   //      MockResponseReader::read_response("test-data", "s3-response.json")
   //   ),
   //   MockCredentialsProvider,
   //   Default::default()
   // );
}

Note regarding XML-based AWS Services

Some AWS services such as SQS and STS return responses in XML format rather than JSON.

In these cases, parsing may fail with ParseError("Expected StartElement got None").

Valid XML examples can be found in the API documentation for an API call such as this one for STS AssumeRole.

These can be used to create a MockRequestDispatcher like so:

MockRequestDispatcher::default().with_body(r#"
<AssumeRoleResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">
  ... etc
</AssumeRoleResponse>
"#)

Dependencies

~9–24MB
~331K SLoC