From 842ebad83f1bfd0ebb1d750a36575f6be81383ac Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Mon, 7 Nov 2022 09:14:03 -0500 Subject: [PATCH 1/7] Add clientIntegration test and fix event stream signing test --- .../client/smithy/RustCodegenPlugin.kt | 16 ++- .../NoOpEventStreamSigningDecorator.kt | 2 +- .../smithy/customize/RustCodegenDecorator.kt | 3 +- .../client/testutil/CodegenIntegrationTest.kt | 98 ++++++++++++++ .../HttpVersionListGeneratorTest.kt | 123 +++++++++--------- .../smithy/rust/codegen/core/testutil/Rust.kt | 22 +++- 6 files changed, 195 insertions(+), 69 deletions(-) create mode 100644 codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt index 9a30b3cafe..225575938e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt @@ -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() { override fun getName(): String = "rust-codegen" - - override fun execute(context: PluginContext) { + override fun executeWithDecorator( + context: PluginContext, + vararg decorator: RustCodegenDecorator, + ) { // 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 @@ -42,7 +46,7 @@ class RustCodegenPlugin : SmithyBuildPlugin { // - location (e.g. the mutate section of an operation) // - context (e.g. the of the operation) // - writer: The active RustWriter at the given location - val codegenDecorator = + var codegenDecorator = CombinedCodegenDecorator.fromClasspath( context, ClientCustomizations(), @@ -51,6 +55,8 @@ class RustCodegenPlugin : SmithyBuildPlugin { NoOpEventStreamSigningDecorator(), ) + codegenDecorator = codegenDecorator.withDecorator(*decorator) + // CodegenVisitor is the main driver of code generation that traverses the model and generates code CodegenVisitor(context, codegenDecorator).execute() } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt index f4cfce3898..4652ce8177 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt @@ -21,7 +21,7 @@ import software.amazon.smithy.rust.codegen.core.util.hasEventStreamOperations */ open class NoOpEventStreamSigningDecorator : RustCodegenDecorator { override val name: String = "NoOpEventStreamSigning" - override val order: Byte = Byte.MIN_VALUE + override val order: Byte = 0 private fun applies(codegenContext: CodegenContext, baseCustomizations: List): Boolean = codegenContext.serviceShape.hasEventStreamOperations(codegenContext.model) && diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt index bfaae9c871..d5f4e4e9a3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt @@ -85,7 +85,8 @@ open class CombinedCodegenDecorator(decorators: List) = CombinedCodegenDecorator(orderedDecorators + decorator) + fun withDecorator(vararg decorator: RustCodegenDecorator) = + CombinedCodegenDecorator(orderedDecorators + decorator) override fun configCustomizations( codegenContext: C, diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt new file mode 100644 index 0000000000..29a155384f --- /dev/null +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt @@ -0,0 +1,98 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.client.testutil + +import software.amazon.smithy.build.PluginContext +import software.amazon.smithy.build.SmithyBuildPlugin +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.node.ObjectNode +import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin +import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.printGeneratedFiles +import software.amazon.smithy.rust.codegen.core.util.runCommand +import java.io.File +import java.nio.file.Path + +/** + * Run cargo test on a true, end-to-end, codegen product of a given model. + * + * For test purposes, additional codegen decorators can also be composed. + */ +fun clientIntegrationTest( + model: Model, + addtionalDecorators: List> = listOf(), + addModuleToEventStreamAllowList: Boolean = false, + test: (ClientCodegenContext, RustCrate) -> Unit, +): Path { + return codegenIntegrationTest( + model, + RustCodegenPlugin(), + addtionalDecorators, + addModuleToEventStreamAllowList = addModuleToEventStreamAllowList, + test = test, + ) +} + +/** + * A Smithy BuildPlugin that accepts an additional decorator + * + * This exists to allow tests to easily customize the _real_ build without needing to list out customizations + * or attempt to manually discover them from the path + */ +abstract class DecoratableBuildPlugin : SmithyBuildPlugin { + abstract fun executeWithDecorator( + context: PluginContext, + vararg decorator: RustCodegenDecorator, + ) + + override fun execute(context: PluginContext) { + executeWithDecorator(context) + } +} + +// TODO: move to core once CodgenDecorator is in core +private inline fun codegenIntegrationTest( + model: Model, + buildPlugin: DecoratableBuildPlugin, + additionalDecorators: List>, + additionalSettings: ObjectNode = ObjectNode.builder().build(), + addModuleToEventStreamAllowList: Boolean = false, + service: String? = null, + runtimeConfig: RuntimeConfig? = null, + overrideTestDir: File? = null, crossinline test: (C, RustCrate) -> Unit, +): Path { + val (ctx, testDir) = generatePluginContext( + model, + additionalSettings, + addModuleToEventStreamAllowList, + service, + runtimeConfig, + overrideTestDir, + ) + + val codegenDecorator = object : RustCodegenDecorator { + override val name: String = "Add tests" + override val order: Byte = 0 + override fun supportsCodegenContext(clazz: Class): Boolean { + // never discoverable on the classpath + return false + } + + override fun extras(codegenContext: C, rustCrate: RustCrate) { + test(codegenContext, rustCrate) + } + } + buildPlugin.executeWithDecorator(ctx, codegenDecorator, *additionalDecorators.toTypedArray()) + ctx.fileManifest.printGeneratedFiles() + "cargo test".runCommand(testDir) + return testDir +} diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt index 6b07db5cc4..db18d441e0 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt @@ -10,20 +10,25 @@ 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.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.config.EventStreamSigningConfig import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.testutil.AddRustTestsDecorator +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.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.testutil.TokioTest 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.integrationTest import software.amazon.smithy.rust.codegen.core.util.runCommand // If any of these tests fail, and you want to understand why, run them with logging: @@ -57,33 +62,28 @@ internal class HttpVersionListGeneratorTest { greeting: String } """.asSmithyModel() - val (ctx, testDir) = generatePluginContext(model) - val moduleName = ctx.settings.expectStringMember("module").value.replace('-', '_') - val combinedCodegenDecorator: CombinedCodegenDecorator = - CombinedCodegenDecorator.fromClasspath(ctx, RequiredCustomizations()) - .withDecorator( - AddRustTestsDecorator("validate_defaults") { - TokioTest.render(this) - rust( - """ - async fn test_http_version_list_defaults() { - let conf = $moduleName::Config::builder().build(); - let op = $moduleName::operation::SayHello::builder() - .greeting("hello") - .build().expect("valid operation") - .make_operation(&conf).await.expect("hello is a valid prefix"); - let properties = op.properties(); - let actual_http_versions = properties.get::>() - .expect("http versions list should be in property bag"); - let expected_http_versions = &vec![http::Version::HTTP_11]; - assert_eq!(actual_http_versions, expected_http_versions); - } - """, - ) - }, + clientIntegrationTest(model) { clientCodegenContext, rustCrate -> + val moduleName = clientCodegenContext.moduleUseName() + rustCrate.integrationTest("http_version_list") { + TokioTest.render(this) + rust( + """ + async fn test_http_version_list_defaults() { + let conf = $moduleName::Config::builder().build(); + let op = $moduleName::operation::SayHello::builder() + .greeting("hello") + .build().expect("valid operation") + .make_operation(&conf).await.expect("hello is a valid prefix"); + let properties = op.properties(); + let actual_http_versions = properties.get::>() + .expect("http versions list should be in property bag"); + let expected_http_versions = &vec![http::Version::HTTP_11]; + assert_eq!(actual_http_versions, expected_http_versions); + } + """, ) - CodegenVisitor(ctx, combinedCodegenDecorator).execute() - "cargo test".runCommand(testDir) + } + } } @Test @@ -182,39 +182,44 @@ internal class HttpVersionListGeneratorTest { } """.asSmithyModel() - val (ctx, testDir) = generatePluginContext(model, addModuleToEventStreamAllowList = true) - val moduleName = ctx.settings.expectStringMember("module").value.replace('-', '_') - - val combinedCodegenDecorator: CombinedCodegenDecorator = - CombinedCodegenDecorator.fromClasspath(ctx, RequiredCustomizations()) - .withDecorator(object : AddRustTestsDecorator("validate_eventstream_http", { - TokioTest.render(this) - rust( - """ - async fn test_http_version_list_defaults() { - let conf = $moduleName::Config::builder().build(); - let op = $moduleName::operation::SayHello::builder() - .build().expect("valid operation") - .make_operation(&conf).await.unwrap(); - let properties = op.properties(); - let actual_http_versions = properties.get::>() - .expect("http versions list should be in property bag"); - let expected_http_versions = &vec![http::Version::HTTP_2]; - assert_eq!(actual_http_versions, expected_http_versions); - } - """, - ) - },) { - override fun configCustomizations( - codegenContext: ClientCodegenContext, - baseCustomizations: List, - ): List { - return super.configCustomizations(codegenContext, baseCustomizations) + FakeSigningConfig(codegenContext.runtimeConfig) - } - }, + clientIntegrationTest( + model, + listOf(FakeSigningDecorator()), + addModuleToEventStreamAllowList = true, + ) { clientCodegenContext, rustCrate -> + val moduleName = clientCodegenContext.moduleUseName() + rustCrate.integrationTest("validate_eventstream_http") { + TokioTest.render(this) + rust( + """ + async fn test_http_version_list_defaults() { + let conf = $moduleName::Config::builder().build(); + let op = $moduleName::operation::SayHello::builder() + .build().expect("valid operation") + .make_operation(&conf).await.unwrap(); + let properties = op.properties(); + let actual_http_versions = properties.get::>() + .expect("http versions list should be in property bag"); + let expected_http_versions = &vec![http::Version::HTTP_2]; + assert_eq!(actual_http_versions, expected_http_versions); + } + """, ) - CodegenVisitor(ctx, combinedCodegenDecorator).execute() - "cargo test".runCommand(testDir) + } + } + } +} + +class FakeSigningDecorator : RustCodegenDecorator { + override val name: String = "fakesigning" + override val order: Byte = -1 + override fun supportsCodegenContext(clazz: Class): Boolean = false + override fun configCustomizations( + codegenContext: ClientCodegenContext, + baseCustomizations: List, + ): List { + println(baseCustomizations) + return baseCustomizations.filterNot { it is EventStreamSigningConfig } + FakeSigningConfig(codegenContext.runtimeConfig) } } @@ -260,6 +265,7 @@ class FakeSigningConfig( *codegenScope, ) } + is ServiceConfig.Extras -> writable { rustTemplate( """ @@ -287,6 +293,7 @@ class FakeSigningConfig( *codegenScope, ) } + else -> emptySection } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index b8868151ae..c5bc50ed42 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -216,11 +216,14 @@ class TestWriterDelegator( ) { val baseDir: Path = fileManifest.baseDir - fun generatedFiles(): List = fileManifest.files.toList().sorted() fun printGeneratedFiles() { - generatedFiles().forEach { path -> - println("file:///$path") - } + fileManifest.printGeneratedFiles() + } +} + +fun FileManifest.printGeneratedFiles() { + this.files.forEach { path -> + println("file:///$path") } } @@ -385,3 +388,14 @@ fun String.compileAndRun(vararg strings: String) { val binary = contents.shouldCompile() binary.absolutePath.runCommand() } + +fun RustCrate.integrationTest(name: String, writable: Writable) = this.withFile("tests/$name.rs", writable) + +fun TestWriterDelegator.unitTest(test: Writable): TestWriterDelegator { + lib { + unitTest(safeName("test")) { + test(this) + } + } + return this +} From 9fcef70263273c1b053e378f411937180f34c9e8 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Mon, 7 Nov 2022 10:53:39 -0500 Subject: [PATCH 2/7] Update AWS Endpoint tests --- .../smithy/rustsdk/AwsRuntimeDependency.kt | 1 + .../rustsdk/IntegrationTestDependencies.kt | 3 +- .../EndpointConfigCustomizationTest.kt | 71 ++++++++----------- .../NoOpEventStreamSigningDecorator.kt | 2 +- .../client/testutil/CodegenIntegrationTest.kt | 6 ++ .../HttpVersionListGeneratorTest.kt | 57 ++++++--------- 6 files changed, 61 insertions(+), 79 deletions(-) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt index eb87bf56dd..4009f63b39 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt @@ -54,6 +54,7 @@ object AwsRuntimeType { CargoDependency.SmithyHttpTower(this), CargoDependency.SmithyClient(this), CargoDependency.Tower, + sigAuth(), awsHttp(), awsEndpoint(), ), diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt index bc23413ba1..df68a0a041 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt @@ -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 { override val name: String = "IntegrationTest" @@ -32,7 +33,7 @@ class IntegrationTestDecorator : RustCodegenDecorator { 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." } diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt index 99185116f3..167c6b4159 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt @@ -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 { - override val name: String = "tests and config" - override val order: Byte = 0 - override fun configCustomizations( - codegenContext: ClientCodegenContext, - baseCustomizations: List, - ): List = - baseCustomizations + stubConfigCustomization("a") + EndpointConfigCustomization( - codegenContext, - endpointConfig, - ) + stubConfigCustomization("b") - - override fun libRsCustomizations( - codegenContext: ClientCodegenContext, - baseCustomizations: List, - ): List = - baseCustomizations + PubUseEndpoint(AwsTestRuntimeConfig) + AllowLintsGenerator(listOf("dead_code"), listOf(), listOf()) - - override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { - if (test != null) { - test(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): Boolean = - clazz.isAssignableFrom(ClientCodegenContext::class.java) } - val customization = CombinedCodegenDecorator(listOf(RequiredCustomizations(), codegenDecorator)) - CodegenVisitor(context, customization).execute() - println("file:///$testDir") - "cargo test".runCommand(testDir) } @Test diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt index 4652ce8177..f4cfce3898 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt @@ -21,7 +21,7 @@ import software.amazon.smithy.rust.codegen.core.util.hasEventStreamOperations */ open class NoOpEventStreamSigningDecorator : RustCodegenDecorator { override val name: String = "NoOpEventStreamSigning" - override val order: Byte = 0 + override val order: Byte = Byte.MIN_VALUE private fun applies(codegenContext: CodegenContext, baseCustomizations: List): Boolean = codegenContext.serviceShape.hasEventStreamOperations(codegenContext.model) && diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt index 29a155384f..a3da5f4593 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt @@ -31,6 +31,9 @@ fun clientIntegrationTest( model: Model, addtionalDecorators: List> = listOf(), addModuleToEventStreamAllowList: Boolean = false, + service: String? = null, + runtimeConfig: RuntimeConfig? = null, + additionalSettings: ObjectNode = ObjectNode.builder().build(), test: (ClientCodegenContext, RustCrate) -> Unit, ): Path { return codegenIntegrationTest( @@ -38,6 +41,9 @@ fun clientIntegrationTest( RustCodegenPlugin(), addtionalDecorators, addModuleToEventStreamAllowList = addModuleToEventStreamAllowList, + service = service, + runtimeConfig = runtimeConfig, + additionalSettings = additionalSettings, test = test, ) } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt index db18d441e0..3a20dbd9e5 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt @@ -7,15 +7,11 @@ package software.amazon.smithy.rust.codegen.client.customizations import org.junit.jupiter.api.Test 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.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.config.EventStreamSigningConfig import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator -import software.amazon.smithy.rust.codegen.client.testutil.AddRustTestsDecorator 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.Writable @@ -27,9 +23,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.testutil.TokioTest 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.integrationTest -import software.amazon.smithy.rust.codegen.core.util.runCommand // If any of these tests fail, and you want to understand why, run them with logging: // ``` @@ -113,33 +107,28 @@ internal class HttpVersionListGeneratorTest { greeting: String } """.asSmithyModel() - val (ctx, testDir) = generatePluginContext(model) - val moduleName = ctx.settings.expectStringMember("module").value.replace('-', '_') - val combinedCodegenDecorator: CombinedCodegenDecorator = - CombinedCodegenDecorator.fromClasspath(ctx, RequiredCustomizations()) - .withDecorator( - AddRustTestsDecorator("validate_http") { - TokioTest.render(this) - rust( - """ - async fn test_http_version_list_defaults() { - let conf = $moduleName::Config::builder().build(); - let op = $moduleName::operation::SayHello::builder() - .greeting("hello") - .build().expect("valid operation") - .make_operation(&conf).await.expect("hello is a valid prefix"); - let properties = op.properties(); - let actual_http_versions = properties.get::>() - .expect("http versions list should be in property bag"); - let expected_http_versions = &vec![http::Version::HTTP_11, http::Version::HTTP_2]; - assert_eq!(actual_http_versions, expected_http_versions); - } - """, - ) - }, + clientIntegrationTest(model) { clientCodegenContext, rustCrate -> + val moduleName = clientCodegenContext.moduleUseName() + rustCrate.integrationTest("validate_http") { + TokioTest.render(this) + rust( + """ + async fn test_http_version_list_defaults() { + let conf = $moduleName::Config::builder().build(); + let op = $moduleName::operation::SayHello::builder() + .greeting("hello") + .build().expect("valid operation") + .make_operation(&conf).await.expect("hello is a valid prefix"); + let properties = op.properties(); + let actual_http_versions = properties.get::>() + .expect("http versions list should be in property bag"); + let expected_http_versions = &vec![http::Version::HTTP_11, http::Version::HTTP_2]; + assert_eq!(actual_http_versions, expected_http_versions); + } + """, ) - CodegenVisitor(ctx, combinedCodegenDecorator).execute() - "cargo test".runCommand(testDir) + } + } } @Test @@ -212,7 +201,7 @@ internal class HttpVersionListGeneratorTest { class FakeSigningDecorator : RustCodegenDecorator { override val name: String = "fakesigning" - override val order: Byte = -1 + override val order: Byte = 0 override fun supportsCodegenContext(clazz: Class): Boolean = false override fun configCustomizations( codegenContext: ClientCodegenContext, @@ -225,7 +214,7 @@ class FakeSigningDecorator : RustCodegenDecorator Date: Mon, 7 Nov 2022 11:02:37 -0500 Subject: [PATCH 3/7] Clean up more integration-style-tests --- .../generators/EndpointTraitBindingsTest.kt | 72 +++++++------------ .../generators/PaginatorGeneratorTest.kt | 14 ++-- .../client/smithy/protocols/AwsQueryTest.kt | 8 +-- .../client/smithy/protocols/Ec2QueryTest.kt | 8 +-- .../client/smithy/protocols/RestJsonTest.kt | 8 +-- .../client/smithy/protocols/RestXmlTest.kt | 8 +-- 6 files changed, 41 insertions(+), 77 deletions(-) diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt index 872402c6ef..41aa7eacb9 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt @@ -9,19 +9,12 @@ import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.EndpointTrait -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.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.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock -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.implBlock import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig @@ -29,10 +22,9 @@ import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.core.testutil.TokioTest import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.integrationTest import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.lookup -import software.amazon.smithy.rust.codegen.core.util.runCommand import kotlin.io.path.ExperimentalPathApi internal class EndpointTraitBindingsTest { @@ -145,44 +137,30 @@ internal class EndpointTraitBindingsTest { greeting: String } """.asSmithyModel() - val (ctx, testDir) = generatePluginContext(model) - val moduleName = ctx.settings.expectStringMember("module").value.replace('-', '_') - val codegenDecorator = object : RustCodegenDecorator { - override val name: String = "add tests" - override val order: Byte = 0 - - override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { - rustCrate.withFile("tests/validate_errors.rs") { - TokioTest.render(this) - rust( - """ - async fn test_endpoint_prefix() { - let conf = $moduleName::Config::builder().build(); - $moduleName::operation::SayHello::builder() - .greeting("hey there!").build().expect("input is valid") - .make_operation(&conf).await.expect_err("no spaces or exclamation points in ep prefixes"); - let op = $moduleName::operation::SayHello::builder() - .greeting("hello") - .build().expect("valid operation") - .make_operation(&conf).await.expect("hello is a valid prefix"); - let properties = op.properties(); - let prefix = properties.get::() - .expect("prefix should be in config") - .as_str(); - assert_eq!(prefix, "test123.hello."); - } - """, - ) - } + clientIntegrationTest(model) { clientCodegenContext, rustCrate -> + val moduleName = clientCodegenContext.moduleUseName() + rustCrate.integrationTest("test_endpoint_prefix") { + TokioTest.render(this) + rust( + """ + async fn test_endpoint_prefix() { + let conf = $moduleName::Config::builder().build(); + $moduleName::operation::SayHello::builder() + .greeting("hey there!").build().expect("input is valid") + .make_operation(&conf).await.expect_err("no spaces or exclamation points in ep prefixes"); + let op = $moduleName::operation::SayHello::builder() + .greeting("hello") + .build().expect("valid operation") + .make_operation(&conf).await.expect("hello is a valid prefix"); + let properties = op.properties(); + let prefix = properties.get::() + .expect("prefix should be in config") + .as_str(); + assert_eq!(prefix, "test123.hello."); + } + """, + ) } - - override fun supportsCodegenContext(clazz: Class): Boolean = - clazz.isAssignableFrom(ClientCodegenContext::class.java) } - val combinedCodegenDecorator: CombinedCodegenDecorator = - CombinedCodegenDecorator.fromClasspath(ctx, RequiredCustomizations()).withDecorator(codegenDecorator) - val visitor = CodegenVisitor(ctx, combinedCodegenDecorator) - visitor.execute() - "cargo test".runCommand(testDir) } } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt index fd6fa27a3a..ff000d5b9f 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt @@ -6,10 +6,10 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin +import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest +import software.amazon.smithy.rust.codegen.core.rustlang.rust 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.util.runCommand +import software.amazon.smithy.rust.codegen.core.testutil.integrationTest internal class PaginatorGeneratorTest { private val model = """ @@ -68,8 +68,10 @@ internal class PaginatorGeneratorTest { @Test fun `generate paginators that compile`() { - val (ctx, testDir) = generatePluginContext(model) - RustCodegenPlugin().execute(ctx) - "cargo test".runCommand(testDir) + clientIntegrationTest(model) { clientCodegenContext, rustCrate -> + rustCrate.integrationTest("paginators_generated") { + rust("use ${clientCodegenContext.moduleUseName()}::paginator::PaginatedListPaginator;") + } + } } } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQueryTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQueryTest.kt index 5445d403fa..0e5f22ec70 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQueryTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQueryTest.kt @@ -6,10 +6,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin +import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest 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.util.runCommand class AwsQueryTest { private val model = """ @@ -37,8 +35,6 @@ class AwsQueryTest { @Test fun `generate an aws query service that compiles`() { - val (pluginContext, testDir) = generatePluginContext(model) - RustCodegenPlugin().execute(pluginContext) - "cargo check".runCommand(testDir) + clientIntegrationTest(model) { _, _ -> } } } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2QueryTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2QueryTest.kt index 80a5f9f2fd..13779ca09f 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2QueryTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2QueryTest.kt @@ -6,10 +6,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin +import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest 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.util.runCommand class Ec2QueryTest { private val model = """ @@ -37,8 +35,6 @@ class Ec2QueryTest { @Test fun `generate an aws query service that compiles`() { - val (pluginContext, testDir) = generatePluginContext(model) - RustCodegenPlugin().execute(pluginContext) - "cargo check".runCommand(testDir) + clientIntegrationTest(model) { _, _ -> } } } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJsonTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJsonTest.kt index 0ac380f983..99a6b3a01c 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJsonTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJsonTest.kt @@ -6,10 +6,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin +import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest 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.util.runCommand internal class RestJsonTest { val model = """ @@ -42,8 +40,6 @@ internal class RestJsonTest { @Test fun `generate a rest json service that compiles`() { - val (pluginContext, testDir) = generatePluginContext(model) - RustCodegenPlugin().execute(pluginContext) - "cargo check".runCommand(testDir) + clientIntegrationTest(model) { _, _ -> } } } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXmlTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXmlTest.kt index 17400defb2..aad9e1d17f 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXmlTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXmlTest.kt @@ -6,10 +6,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin +import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest 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.util.runCommand internal class RestXmlTest { @@ -87,8 +85,6 @@ internal class RestXmlTest { @Test fun `generate a rest xml service that compiles`() { - val (pluginContext, testDir) = generatePluginContext(model) - RustCodegenPlugin().execute(pluginContext) - "cargo check".runCommand(testDir) + clientIntegrationTest(model) { _, _ -> } } } From 20cc1ec1b4c673dffccb04c0a5cd40a7811ddc04 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Mon, 7 Nov 2022 11:04:20 -0500 Subject: [PATCH 4/7] Delete unused test --- .../client/smithy/RustCodegenPlugin.kt | 5 ++-- .../client/testutil/AddRustTestsDecorator.kt | 27 ------------------- 2 files changed, 2 insertions(+), 30 deletions(-) delete mode 100644 codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt index 225575938e..6b31380578 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt @@ -46,17 +46,16 @@ class RustCodegenPlugin : DecoratableBuildPlugin( - private val testsFileName: String, - private val testWritable: Writable, -) : RustCodegenDecorator { - override val name: String = "add tests" - override val order: Byte = 0 - - override fun extras(codegenContext: C, rustCrate: RustCrate) { - rustCrate.withFile("tests/$testsFileName.rs") { - testWritable() - } - } - - // Don't allow this class to be discovered on the classpath; always return false - override fun supportsCodegenContext(clazz: Class): Boolean = false -} From f5342c429e6920b0ea689472a0bf1191edab984a Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Mon, 7 Nov 2022 11:40:15 -0500 Subject: [PATCH 5/7] Smithy upgrade --- .../rust/codegen/client/testutil/CodegenIntegrationTest.kt | 6 +++--- gradle.properties | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt index a3da5f4593..ca4f158e35 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt @@ -65,8 +65,8 @@ abstract class DecoratableBuildPlugin : SmithyBuildPlugin } } -// TODO: move to core once CodgenDecorator is in core -private inline fun codegenIntegrationTest( +// TODO(https://github.com/awslabs/smithy-rs/issues/1864): move to core once CodegenDecorator is in core +private fun codegenIntegrationTest( model: Model, buildPlugin: DecoratableBuildPlugin, additionalDecorators: List>, @@ -74,7 +74,7 @@ private inline fun codegenIntegrationTest( addModuleToEventStreamAllowList: Boolean = false, service: String? = null, runtimeConfig: RuntimeConfig? = null, - overrideTestDir: File? = null, crossinline test: (C, RustCrate) -> Unit, + overrideTestDir: File? = null, test: (C, RustCrate) -> Unit, ): Path { val (ctx, testDir) = generatePluginContext( model, diff --git a/gradle.properties b/gradle.properties index 091ab5acd8..074e1b37c3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ kotlin.code.style=official # codegen smithyGradlePluginVersion=0.6.0 -smithyVersion=1.26.0 +smithyVersion=1.26.1 # kotlin kotlinVersion=1.6.21 From 41faabfd72a05992988833e054165bf1d925e404 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Mon, 7 Nov 2022 15:46:50 -0500 Subject: [PATCH 6/7] Set warnings & fix unit test --- .../rust/codegen/client/testutil/CodegenIntegrationTest.kt | 2 +- .../codegen/client/smithy/generators/PaginatorGeneratorTest.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt index ca4f158e35..7df96c119a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/CodegenIntegrationTest.kt @@ -99,6 +99,6 @@ private fun codegenIntegrationTest( } buildPlugin.executeWithDecorator(ctx, codegenDecorator, *additionalDecorators.toTypedArray()) ctx.fileManifest.printGeneratedFiles() - "cargo test".runCommand(testDir) + "cargo test".runCommand(testDir, environment = mapOf("RUSTFLAGS" to "-D warnings")) return testDir } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt index ff000d5b9f..9108415f02 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt @@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.integrationTest @@ -70,6 +71,7 @@ internal class PaginatorGeneratorTest { fun `generate paginators that compile`() { clientIntegrationTest(model) { clientCodegenContext, rustCrate -> rustCrate.integrationTest("paginators_generated") { + Attribute.Custom("allow(unused_imports)").render(this) rust("use ${clientCodegenContext.moduleUseName()}::paginator::PaginatedListPaginator;") } } From 40f7c39e241caa52f32d1ee7a29f89e7b30a9b90 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Wed, 9 Nov 2022 11:54:09 -0500 Subject: [PATCH 7/7] Rollback smithy upgrade --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 074e1b37c3..091ab5acd8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,7 +15,7 @@ kotlin.code.style=official # codegen smithyGradlePluginVersion=0.6.0 -smithyVersion=1.26.1 +smithyVersion=1.26.0 # kotlin kotlinVersion=1.6.21