Unverified Commit c622e5e9 authored by Landon James's avatar Landon James Committed by GitHub
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: default avatarysaito1001 <awsaito@amazon.com>
parent d288ef9d
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
---
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.
+27 −4
Original line number Diff line number Diff line
@@ -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
@@ -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"
@@ -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
        ```
        """,
    )
@@ -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,
@@ -191,9 +205,18 @@ class SmokeTestsInstantiator(

        val vendorParams = AwsSmokeTestModel.getAwsVendorParams(testCase)
        vendorParams.orNull()?.let { params ->
            rust(".region(config::Region::new(${params.region.dq()}))")
            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)") }
        }