# aws-smithy-mocks

This package allows testing clients generated by smithy-rs (including all packages of the AWS Rust SDK) by using interceptors to return stub responses. This approach is quite useful for testing both happy-path and simple error scenarios and avoids the need for mocking the entire client or using traits.

As an example, consider this simple usage with S3:

```rust
#[tokio::test]
async fn test_s3() {
     let s3_real_object = mock!(Client::get_object).then_output(|| {
         GetObjectOutput::builder()
             .body(ByteStream::from_static(b"test-test-test"))
             .build()
     });
    let s3 = mock_client!(aws_sdk_s3, [&s3_real_object]);
    let data = s3
        .get_object()
        .bucket("test-bucket")
        .key("correct-key")
        .send()
        .await
        .expect("success response")
        .body
        .collect()
        .await
        .expect("successful read")
        .to_vec();
    assert_eq!(data, b"test-test-test");
    assert_eq!(s3_real_object.num_calls(), 1);
}
```

You can find more examples in the `tests` folder of this crate.

## Shortcomings of this approach
This approach is not well suited for testing precise error handling, especially when considering retries or interactions with HTTP responses—This approach hijacks the request response flow entirely and is not a faithful model in these cases.

If you need to test behavior around retries or connection management, you should use HTTP-connection based mocking instead.

<!-- anchor_start:footer -->
This crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) and the [smithy-rs](https://github.com/smithy-lang/smithy-rs) code generator.
<!-- anchor_end:footer -->
