Commit 0fc20ad2 authored by ysaito1001's avatar ysaito1001
Browse files

Merge branch 'main' into track-features-for-account-based-endpoints

parents 1a8d08b0 7b54e540
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
---
applies_to: ["client"]
authors: ["greenwoodcm"]
references: ["smithy-rs#4299"]
breaking: false
new_feature: true
bug_fix: false
---
Added a new `then_compute_output` to `aws-smithy-mocks` rule builder that allows using the input type when computing a mocked response, e.g. 
```rs
// Return a computed output based on the input
let compute_rule = mock!(Client::get_object)
    .then_compute_output(|req| {
        let key = req.key().unwrap_or("unknown");
        GetObjectOutput::builder()
            .body(ByteStream::from_static(format!("content for {}", key).as_bytes()))
            .build()
    });
```
+9 −0
Original line number Diff line number Diff line
---
applies_to: ["client"]
authors: ["haydenbaker"]
references: ["smithy-rs#4226"]
breaking: false
new_feature: false
bug_fix: true
---
Fixed problematic assertion on HttpApiKeyAuthTrait `scheme`, which was causing client-codegen to fail when the correct settings for api-key based auth were set.
 No newline at end of file
+33 −0
Original line number Diff line number Diff line
@@ -89,6 +89,39 @@ async fn test_mock_client() {
    assert_eq!(err.code(), Some("InvalidAccessKey"));
}

#[tokio::test]
async fn test_mock_client_compute() {
    let s3_computed = mock!(aws_sdk_s3::Client::get_object)
        .match_requests(|inp| {
            inp.bucket() == Some("test-bucket") && inp.key() == Some("correct-key")
        })
        .then_compute_output(|input| {
            let content =
                format!("{}.{}", input.bucket().unwrap(), input.key().unwrap()).into_bytes();
            GetObjectOutput::builder()
                .body(ByteStream::from(content))
                .build()
        });

    let s3 = mock_client!(aws_sdk_s3, &[&s3_computed]);

    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-bucket.correct-key");
    assert_eq!(s3_computed.num_calls(), 1);
}

#[tokio::test]
async fn test_mock_client_sequence() {
    let rule = mock!(aws_sdk_s3::Client::get_object)
+1 −7
Original line number Diff line number Diff line
@@ -180,13 +180,7 @@ private class HttpAuthServiceRuntimePluginCustomization(
                        val trait = serviceShape.getTrait<HttpApiKeyAuthTrait>()!!
                        val location =
                            when (trait.`in`!!) {
                                HttpApiKeyAuthTrait.Location.HEADER -> {
                                    check(trait.scheme.isPresent) {
                                        "A scheme is required for `@httpApiKey` when `in` is set to `header`"
                                    }
                                    "Header"
                                }

                                HttpApiKeyAuthTrait.Location.HEADER -> "Header"
                                HttpApiKeyAuthTrait.Location.QUERY -> "Query"
                            }

+1 −1
Original line number Diff line number Diff line
@@ -560,7 +560,7 @@ dependencies = [

[[package]]
name = "aws-smithy-mocks"
version = "0.1.1"
version = "0.1.2"
dependencies = [
 "aws-smithy-async",
 "aws-smithy-http-client",
Loading