Skip to content

Commit f36458a

Browse files
authored
apply us-east-1 as default region if not set by user in with_test_defaults_v2() (#4312)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> * #4265 * #4189 ## Description * Adds a new `with_test_defaults_v2()` method to all clients supporting region configuration. This new method applies `us-east-1` as default region if not set by user. This allows `aws-smithy-mocks` to work for non AWS SDK generated clients. This is only set as the default if a user has not already supplied one. * NOTE: We are choosing to add a new method here for backwards compatibility concerns (our own generated endpoint tests break because of precedence problems between endpoint rules and with_test_defaults). * Clarify `test-util` feature requirement when using `aws-smithy-mocks`. ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "client," "server," or both in the `applies_to` key. - [x] For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "aws-sdk-rust" in the `applies_to` key. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 5e50dfe commit f36458a

File tree

12 files changed

+369
-177
lines changed

12 files changed

+369
-177
lines changed

.changelog/1758554358.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
applies_to:
3+
- client
4+
- aws-sdk-rust
5+
authors:
6+
- aajtodd
7+
references:
8+
- smithy-rs#4265
9+
- smithy-rs#4189
10+
breaking: false
11+
new_feature: false
12+
bug_fix: true
13+
---
14+
Adds new `with_test_defaults_v2()` for all clients supporting region configuration which applies `us-east-1` as default region if not set by user. This allows `aws-smithy-mocks` to work for non AWS SDK generated clients. Also clarify `test-util` feature requirement when using `aws-smithy-mocks`.

aws/codegen-aws-sdk/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ class RegionProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomi
205205
*codegenScope,
206206
)
207207
}
208+
is ServiceConfig.DefaultForTestsV2 -> {
209+
// this was added later, for backwards compat we only set a default if a region hasn't already been set by user
210+
rustTemplate(
211+
"""
212+
if ${section.configBuilderRef}.config.load::<#{Region}>().is_none() {
213+
self.set_region(#{Some}(#{Region}::new("us-east-1")));
214+
}
215+
""",
216+
*codegenScope,
217+
)
218+
}
208219

209220
is ServiceConfig.BuilderFromConfigBag -> {
210221
rustTemplate("${section.builder}.set_region(${section.configBag}.load::<#{Region}>().cloned());", *codegenScope)

0 commit comments

Comments
 (0)