Unverified Commit c4a14d7c authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Client integration test (#1956)

* Add clientIntegration test and fix event stream signing test

* Update AWS Endpoint tests

* Clean up more integration-style-tests

* Delete unused test

* Smithy upgrade

* Set warnings & fix unit test
parent 1844660c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ object AwsRuntimeType {
            CargoDependency.SmithyHttpTower(this),
            CargoDependency.SmithyClient(this),
            CargoDependency.Tower,
            sigAuth(),
            awsHttp(),
            awsEndpoint(),
        ),
+2 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomiza
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection
import java.nio.file.Files
import java.nio.file.Paths
import kotlin.io.path.absolute

class IntegrationTestDecorator : RustCodegenDecorator<ClientProtocolGenerator, ClientCodegenContext> {
    override val name: String = "IntegrationTest"
@@ -32,7 +33,7 @@ class IntegrationTestDecorator : RustCodegenDecorator<ClientProtocolGenerator, C
    ): List<LibRsCustomization> {
        val integrationTestPath = Paths.get(SdkSettings.from(codegenContext.settings).integrationTestPath)
        check(Files.exists(integrationTestPath)) {
            "Failed to find the AWS SDK integration tests. Make sure the integration test path is configured " +
            "Failed to find the AWS SDK integration tests (${integrationTestPath.absolute()}). Make sure the integration test path is configured " +
                "correctly in the smithy-build.json."
        }

+28 −43
Original line number Diff line number Diff line
@@ -6,26 +6,16 @@
package software.amazon.smithy.rustsdk

import org.junit.jupiter.api.Test
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.CodegenVisitor
import software.amazon.smithy.rust.codegen.client.smithy.customizations.AllowLintsGenerator
import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations
import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator
import software.amazon.smithy.rust.codegen.client.testutil.stubConfigCustomization
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.asType
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext
import software.amazon.smithy.rust.codegen.core.testutil.unitTest
import software.amazon.smithy.rust.codegen.core.util.runCommand
import java.io.File

internal class EndpointConfigCustomizationTest {
    private val placeholderEndpointParams = AwsTestRuntimeConfig.awsEndpoint().asType().member("Params")
@@ -52,6 +42,7 @@ internal class EndpointConfigCustomizationTest {
        }

        @aws.api#service(sdkId: "Test", endpointPrefix: "iam")
        @title("test")
        @restJson1
        service NoRegions {
            version: "123",
@@ -59,6 +50,7 @@ internal class EndpointConfigCustomizationTest {
        }

        @aws.api#service(sdkId: "Test")
        @title("test")
        @restJson1
        service NoEndpointPrefix {
            version: "123",
@@ -127,38 +119,31 @@ internal class EndpointConfigCustomizationTest {
    """.let { ObjectNode.parse(it).expectObjectNode() }

    private fun validateEndpointCustomizationForService(service: String, test: ((RustCrate) -> Unit)? = null) {
        val (context, testDir) = generatePluginContext(model, service = service, runtimeConfig = AwsTestRuntimeConfig)
        val codegenDecorator = object : RustCodegenDecorator<ClientProtocolGenerator, ClientCodegenContext> {
            override val name: String = "tests and config"
            override val order: Byte = 0
            override fun configCustomizations(
                codegenContext: ClientCodegenContext,
                baseCustomizations: List<ConfigCustomization>,
            ): List<ConfigCustomization> =
                baseCustomizations + stubConfigCustomization("a") + EndpointConfigCustomization(
                    codegenContext,
                    endpointConfig,
                ) + stubConfigCustomization("b")

            override fun libRsCustomizations(
                codegenContext: ClientCodegenContext,
                baseCustomizations: List<LibRsCustomization>,
            ): List<LibRsCustomization> =
                baseCustomizations + PubUseEndpoint(AwsTestRuntimeConfig) + AllowLintsGenerator(listOf("dead_code"), listOf(), listOf())

            override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) {
        val endpointsFile = File.createTempFile("endpoints", ".json")
        endpointsFile.writeText(Node.printJson(endpointConfig))
        clientIntegrationTest(
            model,
            listOf(),
            service = service,
            runtimeConfig = AwsTestRuntimeConfig,
            additionalSettings = ObjectNode.builder()
                .withMember(
                    "customizationConfig",
                    ObjectNode.builder()
                        .withMember(
                            "awsSdk",
                            ObjectNode.builder()
                                .withMember("integrationTestPath", "../sdk/integration-tests")
                                .withMember("endpointsConfigPath", endpointsFile.absolutePath)
                                .build(),
                        ).build(),
                )
                .withMember("codegen", ObjectNode.builder().withMember("includeFluentClient", false).build()).build(),
        ) { _, rustCrate ->
            if (test != null) {
                test(rustCrate)
            }
        }

            override fun supportsCodegenContext(clazz: Class<out CodegenContext>): Boolean =
                clazz.isAssignableFrom(ClientCodegenContext::class.java)
        }
        val customization = CombinedCodegenDecorator(listOf(RequiredCustomizations(), codegenDecorator))
        CodegenVisitor(context, customization).execute()
        println("file:///$testDir")
        "cargo test".runCommand(testDir)
    }

    @Test
+9 −4
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
package software.amazon.smithy.rust.codegen.client.smithy

import software.amazon.smithy.build.PluginContext
import software.amazon.smithy.build.SmithyBuildPlugin
import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
@@ -14,7 +13,10 @@ import software.amazon.smithy.rust.codegen.client.smithy.customizations.ClientCu
import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator
import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations
import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator
import software.amazon.smithy.rust.codegen.client.testutil.DecoratableBuildPlugin
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.NonExhaustive
import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider
@@ -31,10 +33,12 @@ import java.util.logging.Logger
 * `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which
 * enables the smithy-build plugin to invoke `execute` with all of the Smithy plugin context + models.
 */
class RustCodegenPlugin : SmithyBuildPlugin {
class RustCodegenPlugin : DecoratableBuildPlugin<ClientProtocolGenerator, ClientCodegenContext>() {
    override fun getName(): String = "rust-codegen"

    override fun execute(context: PluginContext) {
    override fun executeWithDecorator(
        context: PluginContext,
        vararg decorator: RustCodegenDecorator<ClientProtocolGenerator, ClientCodegenContext>,
    ) {
        // Suppress extremely noisy logs about reserved words
        Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF
        // Discover `RustCodegenDecorators` on the classpath. `RustCodegenDecorator` returns different types of
@@ -49,6 +53,7 @@ class RustCodegenPlugin : SmithyBuildPlugin {
                RequiredCustomizations(),
                FluentClientDecorator(),
                NoOpEventStreamSigningDecorator(),
                *decorator,
            )

        // CodegenVisitor is the main driver of code generation that traverses the model and generates code
+2 −1
Original line number Diff line number Diff line
@@ -85,7 +85,8 @@ open class CombinedCodegenDecorator<T, C : CodegenContext>(decorators: List<Rust
    override val order: Byte
        get() = 0

    fun withDecorator(decorator: RustCodegenDecorator<T, C>) = CombinedCodegenDecorator(orderedDecorators + decorator)
    fun withDecorator(vararg decorator: RustCodegenDecorator<T, C>) =
        CombinedCodegenDecorator(orderedDecorators + decorator)

    override fun configCustomizations(
        codegenContext: C,
Loading