Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Smoketest codegen to be endpoint param aware #3836

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
- smithy-rs
landonxjames marked this conversation as resolved.
Show resolved Hide resolved
authors:
- landonxjames
references: []
landonxjames marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -134,7 +136,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 +169,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.get()) }
temp
}
private val fipsName = "AWS::UseFIPS"
private val dualStackName = "AWS::UseDualStack"
private val rc = codegenContext.runtimeConfig

fun render(
writer: RustWriter,
Expand All @@ -191,9 +204,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
Loading