Skip to content

Commit

Permalink
Update Smoketest codegen to be endpoint param aware (#3836)
Browse files Browse the repository at this point in the history
## 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]>
  • Loading branch information
landonxjames and ysaito1001 authored Sep 17, 2024
1 parent d288ef9 commit c622e5e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .changelog/smoketestcodegen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
applies_to:
- aws-sdk-rust
authors:
- landonxjames
references: [smithy-rs#3836]
breaking: false
new_feature: false
bug_fix: true
---

Update Smoketest codegeneration to be endpoint built-in aware.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.model.shapes.MemberShape
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameters
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointRulesetIndex
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.cfg
Expand Down Expand Up @@ -42,6 +44,7 @@ import software.amazon.smithy.smoketests.traits.SmokeTestCase
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait
import java.util.Optional
import java.util.logging.Logger
import kotlin.jvm.optionals.getOrElse

class SmokeTestsDecorator : ClientCodegenDecorator {
override val name: String = "SmokeTests"
Expand Down Expand Up @@ -134,7 +137,7 @@ fun renderPrologue(
they are disabled by default. To enable them, run the tests with
```sh
RUSTFLAGS="--cfg smoketests" cargo test.
RUSTFLAGS="--cfg smoketests" cargo test
```
""",
)
Expand Down Expand Up @@ -167,6 +170,17 @@ class SmokeTestsInstantiator(
) {
private val model = codegenContext.model
private val symbolProvider = codegenContext.symbolProvider
private val builtInParamNames: List<String> by lazy {
val index = EndpointRulesetIndex.of(codegenContext.model)
val rulesOrNull = index.endpointRulesForService(codegenContext.serviceShape)
val builtInParams: Parameters = (rulesOrNull?.parameters ?: Parameters.builder().build())
val temp: MutableList<String> = mutableListOf()
builtInParams.forEach { temp.add(it.builtIn.getOrElse { "" }) }
temp
}
private val fipsName = "AWS::UseFIPS"
private val dualStackName = "AWS::UseDualStack"
private val rc = codegenContext.runtimeConfig

fun render(
writer: RustWriter,
Expand All @@ -191,9 +205,18 @@ class SmokeTestsInstantiator(

val vendorParams = AwsSmokeTestModel.getAwsVendorParams(testCase)
vendorParams.orNull()?.let { params ->
rust(".region(config::Region::new(${params.region.dq()}))")
rust(".use_dual_stack(${params.useDualstack()})")
rust(".use_fips(${params.useFips()})")
rustTemplate(
".region(#{Region}::new(${params.region.dq()}))",
"Region" to AwsRuntimeType.awsTypes(rc).resolve("region::Region"),
)

if (builtInParamNames.contains(dualStackName)) {
rust(".use_dual_stack(${params.useDualstack()})")
}
if (builtInParamNames.contains(fipsName)) {
rust(".use_fips(${params.useFips()})")
}

params.uri.orNull()?.let { rust(".endpoint_url($it)") }
}

Expand Down

0 comments on commit c622e5e

Please sign in to comment.