diff --git a/.changelog/1758554358.md b/.changelog/1758554358.md new file mode 100644 index 00000000000..09e209c3972 --- /dev/null +++ b/.changelog/1758554358.md @@ -0,0 +1,14 @@ +--- +applies_to: +- client +- aws-sdk-rust +authors: +- aajtodd +references: +- smithy-rs#4265 +- smithy-rs#4189 +breaking: false +new_feature: false +bug_fix: true +--- +Apply `us-east-1` as default region if not set by user in `with_test_defaults()` for all clients supporting region allowing `aws-smithy-mocks` to work for non AWS SDK generated clients. Also clarify `test-util` feature requirement when using `aws-smithy-mocks`. diff --git a/aws/codegen-aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt b/aws/codegen-aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt index 9c2d611d887..62a107181a3 100644 --- a/aws/codegen-aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt +++ b/aws/codegen-aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt @@ -205,6 +205,17 @@ class RegionProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomi *codegenScope, ) } + is ServiceConfig.DefaultForTests -> { + // this was added later, for backwards compat we only set a default if a region hasn't already been set by user + rustTemplate( + """ + if ${section.configBuilderRef}.config.load::<#{Region}>().is_none() { + self.set_region(#{Some}(#{Region}::new("us-east-1"))); + } + """, + *codegenScope, + ) + } is ServiceConfig.BuilderFromConfigBag -> { rustTemplate("${section.builder}.set_region(${section.configBag}.load::<#{Region}>().cloned());", *codegenScope) diff --git a/aws/rust-runtime/aws-config/Cargo.lock b/aws/rust-runtime/aws-config/Cargo.lock index 810a3316c61..b75dcfc5ed3 100644 --- a/aws/rust-runtime/aws-config/Cargo.lock +++ b/aws/rust-runtime/aws-config/Cargo.lock @@ -50,7 +50,7 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "aws-config" -version = "1.8.6" +version = "1.8.7" dependencies = [ "aws-credential-types", "aws-runtime", @@ -84,7 +84,7 @@ dependencies = [ [[package]] name = "aws-credential-types" -version = "1.2.6" +version = "1.2.7" dependencies = [ "aws-smithy-async", "aws-smithy-runtime-api", @@ -117,7 +117,7 @@ dependencies = [ [[package]] name = "aws-runtime" -version = "1.5.10" +version = "1.5.11" dependencies = [ "aws-credential-types", "aws-sigv4", @@ -248,7 +248,7 @@ dependencies = [ [[package]] name = "aws-smithy-http-client" -version = "1.1.1" +version = "1.1.2" dependencies = [ "aws-smithy-async", "aws-smithy-protocol-test", diff --git a/rust-runtime/Cargo.lock b/rust-runtime/Cargo.lock index ff206ab16d0..39f788e01a9 100644 --- a/rust-runtime/Cargo.lock +++ b/rust-runtime/Cargo.lock @@ -548,7 +548,7 @@ dependencies = [ [[package]] name = "aws-smithy-mocks" -version = "0.1.2" +version = "0.2.0" dependencies = [ "aws-smithy-async", "aws-smithy-http-client", diff --git a/rust-runtime/aws-smithy-mocks/Cargo.toml b/rust-runtime/aws-smithy-mocks/Cargo.toml index 3beb460de24..b7757de85c2 100644 --- a/rust-runtime/aws-smithy-mocks/Cargo.toml +++ b/rust-runtime/aws-smithy-mocks/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-smithy-mocks" -version = "0.1.2" +version = "0.2.0" authors = ["AWS Rust SDK Team "] description = "Testing utilities for smithy-rs generated clients" edition = "2021" diff --git a/rust-runtime/aws-smithy-mocks/README.md b/rust-runtime/aws-smithy-mocks/README.md index 4925b162f4f..9a7c9c857b5 100644 --- a/rust-runtime/aws-smithy-mocks/README.md +++ b/rust-runtime/aws-smithy-mocks/README.md @@ -14,6 +14,30 @@ without mocking the entire client or using traits. - **Response Sequencing**: Define sequences of responses for testing retry behavior - **Rule Modes**: Control how rules are matched and applied +## Prerequisites + +
+You must enable the `test-util` feature of the service client crate in order to use the `mock_client` macro. +
+ +If the feature is not enabled a compilation error similar to the following will occur: + +```ignore +no method named with_test_defaults found for struct ::config::Builder in the current scope +method not found in Builder +``` + +Example `Cargo.toml` using the `aws-sdk-s3` crate as the service client crate under test: + +```toml +[dependencies] +aws-sdk-s3 = "1" + +[test-dependencies] +aws-smithy-mocks = "0.2" +aws-sdk-s3 = { version = "1", features = ["test-util"] } +``` + ## Basic Usage ```rust,ignore diff --git a/rust-runtime/aws-smithy-mocks/src/lib.rs b/rust-runtime/aws-smithy-mocks/src/lib.rs index eac760cddf0..67b8f604f6b 100644 --- a/rust-runtime/aws-smithy-mocks/src/lib.rs +++ b/rust-runtime/aws-smithy-mocks/src/lib.rs @@ -77,6 +77,9 @@ macro_rules! mock { /// `mock_client!` macro produces a Client configured with a number of Rules and appropriate test default configuration. /// +/// ## Prerequisites +/// You must enable the `test-util` feature of the service client crate in order to use the `mock_client` macro. +/// /// # Examples /// /// **Create a client that uses a mock failure and then a success**: @@ -143,7 +146,6 @@ macro_rules! mock_client { coerce($additional_configuration)( $aws_crate::config::Config::builder() .with_test_defaults() - .region($aws_crate::config::Region::from_static("us-east-1")) .http_client(mock_http_client) .interceptor(mock_response_interceptor), ) diff --git a/rust-runtime/aws-smithy-mocks/tests/macros.rs b/rust-runtime/aws-smithy-mocks/tests/macros.rs index dab21ddcfb0..523bbc0f699 100644 --- a/rust-runtime/aws-smithy-mocks/tests/macros.rs +++ b/rust-runtime/aws-smithy-mocks/tests/macros.rs @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -/// Basic test of using the mock_client macro from an "external" crate +//! Basic test of using the mock_client macro from an "external" crate mod fake_crate { pub(crate) mod client { @@ -32,9 +32,6 @@ mod fake_crate { pub fn build(self) -> Config { Config {} } - pub fn region(self, _region: crate::fake_crate::config::Region) -> Self { - Self {} - } pub fn with_test_defaults(self) -> Self { Self {} } @@ -46,13 +43,6 @@ mod fake_crate { self } } - - pub(crate) struct Region {} - impl Region { - pub fn from_static(_region: &'static str) -> Self { - Self {} - } - } } } #[test] diff --git a/tools/ci-build/publisher/Cargo.lock b/tools/ci-build/publisher/Cargo.lock index a8c985e83f3..3ccfc5fbb28 100644 --- a/tools/ci-build/publisher/Cargo.lock +++ b/tools/ci-build/publisher/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -973,7 +973,7 @@ dependencies = [ [[package]] name = "publisher" -version = "0.4.1" +version = "0.4.2" dependencies = [ "anyhow", "async-recursion",