Skip to content

Commit c622e5e

Browse files
Update Smoketest codegen to be endpoint param aware (#3836)
## 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 --> Smoketests for service were failing because the smoke test assumed that `use_dual_stack` would be present. But the service's endpoint rules did not use that bulit-in so it was not. ## Description <!--- Describe your changes in detail --> Check if the service actually uses the fips or dual stack built-ins before adding them to the test. ## Testing <!--- Please describe in detail how you tested your changes --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> Did not add tests for this because the current `SmokeTestsDecoratorTest` isn't actually working and fixing it is going to be a bit of work. Want to get this in to unblock customer ASAP and will go back and update the tests once they are unblocked. ## 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. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: ysaito1001 <[email protected]>
1 parent d288ef9 commit c622e5e

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

.changelog/smoketestcodegen.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
applies_to:
3+
- aws-sdk-rust
4+
authors:
5+
- landonxjames
6+
references: [smithy-rs#3836]
7+
breaking: false
8+
new_feature: false
9+
bug_fix: true
10+
---
11+
12+
Update Smoketest codegeneration to be endpoint built-in aware.

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import software.amazon.smithy.model.node.ObjectNode
1111
import software.amazon.smithy.model.shapes.MemberShape
1212
import software.amazon.smithy.model.shapes.OperationShape
1313
import software.amazon.smithy.model.shapes.StructureShape
14+
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameters
1415
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
1516
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
17+
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointRulesetIndex
1618
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator
1719
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
1820
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.cfg
@@ -42,6 +44,7 @@ import software.amazon.smithy.smoketests.traits.SmokeTestCase
4244
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait
4345
import java.util.Optional
4446
import java.util.logging.Logger
47+
import kotlin.jvm.optionals.getOrElse
4548

4649
class SmokeTestsDecorator : ClientCodegenDecorator {
4750
override val name: String = "SmokeTests"
@@ -134,7 +137,7 @@ fun renderPrologue(
134137
they are disabled by default. To enable them, run the tests with
135138
136139
```sh
137-
RUSTFLAGS="--cfg smoketests" cargo test.
140+
RUSTFLAGS="--cfg smoketests" cargo test
138141
```
139142
""",
140143
)
@@ -167,6 +170,17 @@ class SmokeTestsInstantiator(
167170
) {
168171
private val model = codegenContext.model
169172
private val symbolProvider = codegenContext.symbolProvider
173+
private val builtInParamNames: List<String> by lazy {
174+
val index = EndpointRulesetIndex.of(codegenContext.model)
175+
val rulesOrNull = index.endpointRulesForService(codegenContext.serviceShape)
176+
val builtInParams: Parameters = (rulesOrNull?.parameters ?: Parameters.builder().build())
177+
val temp: MutableList<String> = mutableListOf()
178+
builtInParams.forEach { temp.add(it.builtIn.getOrElse { "" }) }
179+
temp
180+
}
181+
private val fipsName = "AWS::UseFIPS"
182+
private val dualStackName = "AWS::UseDualStack"
183+
private val rc = codegenContext.runtimeConfig
170184

171185
fun render(
172186
writer: RustWriter,
@@ -191,9 +205,18 @@ class SmokeTestsInstantiator(
191205

192206
val vendorParams = AwsSmokeTestModel.getAwsVendorParams(testCase)
193207
vendorParams.orNull()?.let { params ->
194-
rust(".region(config::Region::new(${params.region.dq()}))")
195-
rust(".use_dual_stack(${params.useDualstack()})")
196-
rust(".use_fips(${params.useFips()})")
208+
rustTemplate(
209+
".region(#{Region}::new(${params.region.dq()}))",
210+
"Region" to AwsRuntimeType.awsTypes(rc).resolve("region::Region"),
211+
)
212+
213+
if (builtInParamNames.contains(dualStackName)) {
214+
rust(".use_dual_stack(${params.useDualstack()})")
215+
}
216+
if (builtInParamNames.contains(fipsName)) {
217+
rust(".use_fips(${params.useFips()})")
218+
}
219+
197220
params.uri.orNull()?.let { rust(".endpoint_url($it)") }
198221
}
199222

0 commit comments

Comments
 (0)