From 602bac1c61ae3fd7efda49d0aab2c0fcffa4b452 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 23 Aug 2024 10:16:49 -0400 Subject: [PATCH 01/41] feat: smoke tests --- .../ab4f3405-e013-4caf-89d7-1d820bcdd228.json | 5 ++ codegen/aws-sdk-codegen/build.gradle.kts | 1 + .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 56 +++++++++++++++++++ codegen/sdk/build.gradle.kts | 4 ++ services/build.gradle.kts | 4 ++ 5 files changed, 70 insertions(+) create mode 100644 .changes/ab4f3405-e013-4caf-89d7-1d820bcdd228.json diff --git a/.changes/ab4f3405-e013-4caf-89d7-1d820bcdd228.json b/.changes/ab4f3405-e013-4caf-89d7-1d820bcdd228.json new file mode 100644 index 00000000000..8cac6e3a4e5 --- /dev/null +++ b/.changes/ab4f3405-e013-4caf-89d7-1d820bcdd228.json @@ -0,0 +1,5 @@ +{ + "id": "ab4f3405-e013-4caf-89d7-1d820bcdd228", + "type": "feature", + "description": "Add support for smoke tests" +} \ No newline at end of file diff --git a/codegen/aws-sdk-codegen/build.gradle.kts b/codegen/aws-sdk-codegen/build.gradle.kts index 719643eabc8..aa404d7a4cb 100644 --- a/codegen/aws-sdk-codegen/build.gradle.kts +++ b/codegen/aws-sdk-codegen/build.gradle.kts @@ -29,6 +29,7 @@ dependencies { api(libs.smithy.aws.cloudformation.traits) api(libs.smithy.protocol.test.traits) implementation(libs.smithy.aws.endpoints) + implementation(libs.smithy.smoke.test.traits) testImplementation(libs.junit.jupiter) testImplementation(libs.junit.jupiter.params) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index 0cae160ab7b..1e2d317b63c 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -4,9 +4,16 @@ */ package aws.sdk.kotlin.codegen +import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.* import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.model.hasTrait import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.smokeTestDenyList +import software.amazon.smithy.kotlin.codegen.utils.operations +import software.amazon.smithy.model.Model +import software.amazon.smithy.smoketests.traits.SmokeTestsTrait +import java.util.concurrent.atomic.AtomicBoolean // TODO - would be nice to allow integrations to define custom settings in the plugin // e.g. we could then more consistently apply this integration if we could define a property like: `build.isAwsSdk: true` @@ -16,6 +23,14 @@ import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter */ class GradleGenerator : KotlinIntegration { + private var hasSmokeTests = AtomicBoolean(false) + + // Only used to access settings - will always be true + override fun enabledForService(model: Model, settings: KotlinSettings): Boolean { + hasSmokeTests.set(model.operations(settings.service).any { it.hasTrait() }) + return super.enabledForService(model, settings) + } + // Specify to run last, to ensure all other integrations have had a chance to register dependencies. override val order: Byte get() = 127 @@ -50,6 +65,10 @@ class GradleGenerator : KotlinIntegration { writer .write("") .withBlock("kotlin {", "}") { + if (hasSmokeTests.get() && !smokeTestDenyList.contains(ctx.settings.sdkId)) { + generateSmokeTestJarTask(writer) + generateSmokeTestTask(writer) + } withBlock("sourceSets {", "}") { allDependencies .sortedWith(compareBy({ it.config }, { it.artifact })) @@ -69,4 +88,41 @@ class GradleGenerator : KotlinIntegration { val contents = writer.toString() delegator.fileManifest.writeFile("build.gradle.kts", contents) } + + private fun generateSmokeTestJarTask(writer: GradleWriter) { + val moneySign = "$" + writer.withBlock("jvm {", "}") { + withBlock("compilations {", "}") { + write("val main = getByName(\"main\")") + withBlock("tasks {", "}") { + withBlock("register(\"smokeTestJar\") {", "}") { + write("description = \"Creates smoke tests jar\"") + write("group = \"application\"") + write("dependsOn(build)") + withBlock("manifest {", "}") { + write("attributes[\"Main-Class\"] = \"smoketests.SmokeTestsKt\"") + } + write("duplicatesStrategy = DuplicatesStrategy.EXCLUDE") + write("from(configurations.getByName(\"jvmRuntimeClasspath\").map { if (it.isDirectory) it else zipTree(it) }, main.output.classesDirs)") + write("archiveBaseName.set(\"$moneySign{project.name}-smoketests\")") + } + } + } + } + writer.emptyLine() + } + + private fun generateSmokeTestTask(writer: GradleWriter) { + val moneySign = "$" + writer.withBlock("tasks.register(\"smokeTest\") {", "}") { + write("description = \"Runs smoke tests jar\"") + write("group = \"verification\"") + write("dependsOn(tasks.getByName(\"smokeTestJar\"))") + emptyLine() + write("val sdkVersion: String by project") + write("val jarFile = file(\"build/libs/$moneySign{project.name}-smoketests-\$sdkVersion.jar\")") + write("classpath = files(jarFile)") + } + writer.emptyLine() + } } diff --git a/codegen/sdk/build.gradle.kts b/codegen/sdk/build.gradle.kts index 2ef66603b3b..a25e87efbc6 100644 --- a/codegen/sdk/build.gradle.kts +++ b/codegen/sdk/build.gradle.kts @@ -176,6 +176,10 @@ val stageSdks = tasks.register("stageSdks") { from("$projectionOutputDir/src") into("${it.destinationDir}/generated-src") } + copy { + from("$projectionOutputDir/jvm-src") + into("${it.destinationDir}/generated-src-jvm") + } copy { from("$projectionOutputDir/build.gradle.kts") into(it.destinationDir) diff --git a/services/build.gradle.kts b/services/build.gradle.kts index d6749594dc9..d528bad88d3 100644 --- a/services/build.gradle.kts +++ b/services/build.gradle.kts @@ -50,6 +50,10 @@ subprojects { kotlin.srcDir("generated-src/main/kotlin") } + getByName("jvmMain") { + kotlin.srcDir("generated-src-jvm/main/java") + } + getByName("commonTest") { kotlin.srcDir("generated-src/test") From 9ca8f2e128e52d72bcd9e966065256ce2287d24b Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 23 Aug 2024 11:28:11 -0400 Subject: [PATCH 02/41] Sending verified commit to trigger CI From b00ec1f879ed632decccd10321dc40af38f5ac50 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 23 Aug 2024 11:28:45 -0400 Subject: [PATCH 03/41] Actually sign commit message[B From 35708dffd294b09b7ab14b11147f3d9f2cd1c112 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 28 Aug 2024 11:13:02 -0400 Subject: [PATCH 04/41] PR feedback --- .../ab4f3405-e013-4caf-89d7-1d820bcdd228.json | 5 -- .../.kotlin/errors/errors-1723484995593.log | 4 ++ .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 68 ++++++++++--------- .../codegen/SmokeTestsDenyListIntegration.kt | 36 ++++++++++ ...tlin.codegen.integration.KotlinIntegration | 1 + services/build.gradle.kts | 4 +- 6 files changed, 78 insertions(+), 40 deletions(-) delete mode 100644 .changes/ab4f3405-e013-4caf-89d7-1d820bcdd228.json create mode 100644 build-support/.kotlin/errors/errors-1723484995593.log create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt diff --git a/.changes/ab4f3405-e013-4caf-89d7-1d820bcdd228.json b/.changes/ab4f3405-e013-4caf-89d7-1d820bcdd228.json deleted file mode 100644 index 8cac6e3a4e5..00000000000 --- a/.changes/ab4f3405-e013-4caf-89d7-1d820bcdd228.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "id": "ab4f3405-e013-4caf-89d7-1d820bcdd228", - "type": "feature", - "description": "Add support for smoke tests" -} \ No newline at end of file diff --git a/build-support/.kotlin/errors/errors-1723484995593.log b/build-support/.kotlin/errors/errors-1723484995593.log new file mode 100644 index 00000000000..b27a1850216 --- /dev/null +++ b/build-support/.kotlin/errors/errors-1723484995593.log @@ -0,0 +1,4 @@ +kotlin version: 2.0.10 +error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output: + 1. Kotlin compile daemon is ready + diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index 1e2d317b63c..36193103600 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -4,16 +4,13 @@ */ package aws.sdk.kotlin.codegen -import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.* import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.model.hasTrait import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.smokeTestDenyList +import software.amazon.smithy.kotlin.codegen.utils.dq import software.amazon.smithy.kotlin.codegen.utils.operations -import software.amazon.smithy.model.Model import software.amazon.smithy.smoketests.traits.SmokeTestsTrait -import java.util.concurrent.atomic.AtomicBoolean // TODO - would be nice to allow integrations to define custom settings in the plugin // e.g. we could then more consistently apply this integration if we could define a property like: `build.isAwsSdk: true` @@ -23,14 +20,6 @@ import java.util.concurrent.atomic.AtomicBoolean */ class GradleGenerator : KotlinIntegration { - private var hasSmokeTests = AtomicBoolean(false) - - // Only used to access settings - will always be true - override fun enabledForService(model: Model, settings: KotlinSettings): Boolean { - hasSmokeTests.set(model.operations(settings.service).any { it.hasTrait() }) - return super.enabledForService(model, settings) - } - // Specify to run last, to ensure all other integrations have had a chance to register dependencies. override val order: Byte get() = 127 @@ -65,10 +54,6 @@ class GradleGenerator : KotlinIntegration { writer .write("") .withBlock("kotlin {", "}") { - if (hasSmokeTests.get() && !smokeTestDenyList.contains(ctx.settings.sdkId)) { - generateSmokeTestJarTask(writer) - generateSmokeTestTask(writer) - } withBlock("sourceSets {", "}") { allDependencies .sortedWith(compareBy({ it.config }, { it.artifact })) @@ -83,46 +68,63 @@ class GradleGenerator : KotlinIntegration { } } } + if (ctx.model.operations(ctx.settings.service).any { it.hasTrait() }) { + emptyLine() + generateSmokeTestConfig(writer, ctx.settings.sdkId, ctx) + } } val contents = writer.toString() delegator.fileManifest.writeFile("build.gradle.kts", contents) } - private fun generateSmokeTestJarTask(writer: GradleWriter) { - val moneySign = "$" + private fun generateSmokeTestConfig(writer: GradleWriter, sdkId: String, ctx: CodegenContext) { + val formattedDenyList = smokeTestDenyList.joinToString(",", "setOf(", ")") { it.dq() } + writer.withBlock("if (#S !in #L) {", "}", sdkId, formattedDenyList) { + generateSmokeTestJarTask(writer, ctx) + emptyLine() + generateSmokeTestTask(writer) + } + } + + /** + * Generates a gradle task to create smoke test runner JARs + */ + private fun generateSmokeTestJarTask(writer: GradleWriter, ctx: CodegenContext) { writer.withBlock("jvm {", "}") { withBlock("compilations {", "}") { - write("val main = getByName(\"main\")") + write("val runtimePath = configurations.getByName(#S).map { if (it.isDirectory) it else zipTree(it) }", "jvmRuntimeClasspath") + write("val mainPath = getByName(#S).output.classesDirs", "main") + write("val testPath = getByName(#S).output.classesDirs", "test") withBlock("tasks {", "}") { - withBlock("register(\"smokeTestJar\") {", "}") { - write("description = \"Creates smoke tests jar\"") - write("group = \"application\"") + withBlock("register(#S) {", "}", "smokeTestJar") { + write("description = #S", "Creates smoke tests jar") + write("group = #S", "application") write("dependsOn(build)") withBlock("manifest {", "}") { - write("attributes[\"Main-Class\"] = \"smoketests.SmokeTestsKt\"") + write("attributes[#S] = #S", "Main-Class", "${ctx.settings.pkg.name}.smoketests.SmokeTestsKt") } write("duplicatesStrategy = DuplicatesStrategy.EXCLUDE") - write("from(configurations.getByName(\"jvmRuntimeClasspath\").map { if (it.isDirectory) it else zipTree(it) }, main.output.classesDirs)") - write("archiveBaseName.set(\"$moneySign{project.name}-smoketests\")") + write("from(runtimePath, mainPath, testPath)") + write("archiveBaseName.set(#S)", "\${project.name}-smoketests") } } } } - writer.emptyLine() } + /** + * Generates a gradle task to run smoke tests + */ private fun generateSmokeTestTask(writer: GradleWriter) { - val moneySign = "$" - writer.withBlock("tasks.register(\"smokeTest\") {", "}") { - write("description = \"Runs smoke tests jar\"") - write("group = \"verification\"") - write("dependsOn(tasks.getByName(\"smokeTestJar\"))") + writer.withBlock("tasks.register(#S) {", "}", "smokeTest") { + write("description = #S", "Runs smoke tests jar") + write("group = #S", "verification") + write("dependsOn(tasks.getByName(#S))", "smokeTestJar") emptyLine() write("val sdkVersion: String by project") - write("val jarFile = file(\"build/libs/$moneySign{project.name}-smoketests-\$sdkVersion.jar\")") + write("val jarFile = file(#S)", "build/libs/\${project.name}-smoketests-\$sdkVersion.jar") write("classpath = files(jarFile)") } - writer.emptyLine() } } diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt new file mode 100644 index 00000000000..217e6ea9601 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt @@ -0,0 +1,36 @@ +package aws.sdk.kotlin.codegen + +import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionWriter +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunner +import software.amazon.smithy.model.Model + +/** + * Will wipe the smoke test runner file for services that are deny listed. + * + * Some services model smoke tests incorrectly and the code generated smoke test runner file will not compile. + */ +class SmokeTestsDenyListIntegration : KotlinIntegration { + override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = + smokeTestDenyList.contains(settings.sdkId) + + override val sectionWriters: List + get() = listOf( + SectionWriterBinding(SmokeTestsRunner, endpointBusinessMetricsSectionWriter), + ) + + private val endpointBusinessMetricsSectionWriter = SectionWriter { writer, _ -> + writer.write("// Smoke tests for service deny listed until model is fixed") + } +} + +/** + * SDK ID's of services that model smoke tests incorrectly + */ +val smokeTestDenyList = setOf( + "Application Auto Scaling", + "SWF", + "WAFV2", +) diff --git a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration index 876fbb45758..c66b5b097bc 100644 --- a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +++ b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -43,3 +43,4 @@ aws.sdk.kotlin.codegen.customization.s3.express.SigV4S3ExpressAuthSchemeIntegrat aws.sdk.kotlin.codegen.customization.s3.express.S3ExpressIntegration aws.sdk.kotlin.codegen.customization.s3.S3ExpiresIntegration aws.sdk.kotlin.codegen.BusinessMetricsIntegration +aws.sdk.kotlin.codegen.SmokeTestsDenyListIntegration diff --git a/services/build.gradle.kts b/services/build.gradle.kts index d528bad88d3..a13597aed2e 100644 --- a/services/build.gradle.kts +++ b/services/build.gradle.kts @@ -50,8 +50,8 @@ subprojects { kotlin.srcDir("generated-src/main/kotlin") } - getByName("jvmMain") { - kotlin.srcDir("generated-src-jvm/main/java") + getByName("jvmTest") { + kotlin.srcDir("generated-src-jvm/test/java") } getByName("commonTest") { From 2399355a13e1b8e4dd54b17ca3571bdb345e9dec Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 28 Aug 2024 11:14:02 -0400 Subject: [PATCH 05/41] Remove error log commited by accident --- build-support/.kotlin/errors/errors-1723484995593.log | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 build-support/.kotlin/errors/errors-1723484995593.log diff --git a/build-support/.kotlin/errors/errors-1723484995593.log b/build-support/.kotlin/errors/errors-1723484995593.log deleted file mode 100644 index b27a1850216..00000000000 --- a/build-support/.kotlin/errors/errors-1723484995593.log +++ /dev/null @@ -1,4 +0,0 @@ -kotlin version: 2.0.10 -error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output: - 1. Kotlin compile daemon is ready - From 2d98a99fe6ffb3a93a15f304aa099a6f0dab3955 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 28 Aug 2024 11:15:27 -0400 Subject: [PATCH 06/41] Add TODO --- .../aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt index 217e6ea9601..7271c38a806 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt @@ -28,6 +28,7 @@ class SmokeTestsDenyListIntegration : KotlinIntegration { /** * SDK ID's of services that model smoke tests incorrectly + * TODO: Add GH issue links */ val smokeTestDenyList = setOf( "Application Auto Scaling", From d7a4877515ccb0aad6fa5405d49b39ae01d6fa87 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 13 Sep 2024 14:06:41 -0400 Subject: [PATCH 07/41] Added E2E tests --- .gitignore | 9 +- .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 17 ++- .../codegen/SmokeTestsDenyListIntegration.kt | 5 +- settings.gradle.kts | 9 ++ tests/codegen/smoke-tests/build.gradle.kts | 113 ++++++++++++++++++ .../smoke-tests/services/build.gradle.kts | 36 ++++++ .../src/test/kotlin/SmokeTestE2ETest.kt | 63 ++++++++++ .../test/resources/smoke-tests-failure.smithy | 62 ++++++++++ .../test/resources/smoke-tests-success.smithy | 76 ++++++++++++ 9 files changed, 382 insertions(+), 8 deletions(-) create mode 100644 tests/codegen/smoke-tests/build.gradle.kts create mode 100644 tests/codegen/smoke-tests/services/build.gradle.kts create mode 100644 tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt create mode 100644 tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy create mode 100644 tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy diff --git a/.gitignore b/.gitignore index 740eefaf436..865830349b3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,13 @@ build/ .idea/ __pycache__/ local.properties +.kotest/ +*.klib + # ignore generated files services/*/generated-src +services/*/generated-src-jvm services/*/build.gradle.kts -.kotest/ -*.klib \ No newline at end of file +tests/codegen/smoke-tests/services/*/generated-src +tests/codegen/smoke-tests/services/*/generated-src-jvm +tests/codegen/smoke-tests/services/*/build.gradle.kts \ No newline at end of file diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index 36193103600..27b8ba3744c 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -6,10 +6,14 @@ package aws.sdk.kotlin.codegen import software.amazon.smithy.kotlin.codegen.core.* import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait +import software.amazon.smithy.kotlin.codegen.model.traits.FailedResponseTrait +import software.amazon.smithy.kotlin.codegen.model.traits.SuccessResponseTrait import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter import software.amazon.smithy.kotlin.codegen.utils.dq import software.amazon.smithy.kotlin.codegen.utils.operations +import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.smoketests.traits.SmokeTestsTrait // TODO - would be nice to allow integrations to define custom settings in the plugin @@ -83,7 +87,7 @@ class GradleGenerator : KotlinIntegration { writer.withBlock("if (#S !in #L) {", "}", sdkId, formattedDenyList) { generateSmokeTestJarTask(writer, ctx) emptyLine() - generateSmokeTestTask(writer) + generateSmokeTestTask(writer, ctx) } } @@ -116,14 +120,21 @@ class GradleGenerator : KotlinIntegration { /** * Generates a gradle task to run smoke tests */ - private fun generateSmokeTestTask(writer: GradleWriter) { + private fun generateSmokeTestTask(writer: GradleWriter, ctx: CodegenContext) { + val hasSuccessResponseTrait = ctx.model.expectShape(ctx.settings.service).hasTrait(SuccessResponseTrait.ID) + val hasFailedResponseTrait = ctx.model.expectShape(ctx.settings.service).hasTrait(FailedResponseTrait.ID) + + // E2E tests don't have sdkVersion in jar names + val inTestingEnvironment = hasFailedResponseTrait || hasSuccessResponseTrait + val jarName = if (inTestingEnvironment) "\${project.name}-smoketests.jar" else "\${project.name}-smoketests-\$sdkVersion.jar" + writer.withBlock("tasks.register(#S) {", "}", "smokeTest") { write("description = #S", "Runs smoke tests jar") write("group = #S", "verification") write("dependsOn(tasks.getByName(#S))", "smokeTestJar") emptyLine() write("val sdkVersion: String by project") - write("val jarFile = file(#S)", "build/libs/\${project.name}-smoketests-\$sdkVersion.jar") + write("val jarFile = file(#S)", "build/libs/$jarName") write("classpath = files(jarFile)") } } diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt index 7271c38a806..09b057f7d3d 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt @@ -10,11 +10,11 @@ import software.amazon.smithy.model.Model /** * Will wipe the smoke test runner file for services that are deny listed. * - * Some services model smoke tests incorrectly and the code generated smoke test runner file will not compile. + * Some services model smoke tests incorrectly and the code generated file will not compile. */ class SmokeTestsDenyListIntegration : KotlinIntegration { override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = - smokeTestDenyList.contains(settings.sdkId) + settings.sdkId in smokeTestDenyList override val sectionWriters: List get() = listOf( @@ -28,7 +28,6 @@ class SmokeTestsDenyListIntegration : KotlinIntegration { /** * SDK ID's of services that model smoke tests incorrectly - * TODO: Add GH issue links */ val smokeTestDenyList = setOf( "Application Auto Scaling", diff --git a/settings.gradle.kts b/settings.gradle.kts index 7a29b53784f..2098033de24 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -43,6 +43,8 @@ include(":services") include(":tests") include(":tests:codegen:event-stream") include(":tests:e2e-test-util") +include(":tests:codegen:smoke-tests") +include(":tests:codegen:smoke-tests:services") // generated services val File.isServiceDir: Boolean @@ -57,6 +59,13 @@ file("services").listFiles().forEach { } } +// generated services by smoke tests - test suite +file("tests/codegen/smoke-tests/services").listFiles().forEach { + if (it.isServiceDir) { + include(":tests:codegen:smoke-tests:services:${it.name}") + } +} + // Service benchmarks project val benchmarkServices = listOf( // keep this list in sync with tests/benchmarks/service-benchmarks/build.gradle.kts diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts new file mode 100644 index 00000000000..84a4cd5d16c --- /dev/null +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -0,0 +1,113 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +import aws.sdk.kotlin.gradle.codegen.dsl.generateSmithyProjections +import aws.sdk.kotlin.gradle.codegen.dsl.smithyKotlinPlugin +import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionPath + +description = "Tests for smoke tests runner" +plugins { + alias(libs.plugins.aws.kotlin.repo.tools.smithybuild) + alias(libs.plugins.kotlin.jvm) +} + +val projections = listOf( + ProjectionMetadata("successService", "smoke-tests-success.smithy", "com.test#SuccessService"), + ProjectionMetadata("failureService", "smoke-tests-failure.smithy", "com.test#FailureService"), +) + +configureProject() +configureSmithyProjections() +configureTasks() + +fun configureProject() { + val codegen by configurations.getting + + dependencies { + codegen(project(":codegen:aws-sdk-codegen")) + implementation(libs.smithy.kotlin.codegen) + codegen(libs.smithy.cli) + codegen(libs.smithy.model) + + testImplementation(libs.kotlin.test) + } +} + +fun configureSmithyProjections() { + smithyBuild { + val pathToSmithyModels = "src/test/resources/" + + this@Build_gradle.projections.forEach { projection -> + projections.register(projection.name) { + imports = listOf(layout.projectDirectory.file(pathToSmithyModels + projection.modelFile).asFile.absolutePath) + smithyKotlinPlugin { + serviceShapeId = projection.serviceShapeId + packageName = "aws.sdk.kotlin.test.smoketests" + packageVersion = "1.0" + buildSettings { + generateFullProject = false + generateDefaultBuildFiles = false + optInAnnotations = listOf( + "aws.smithy.kotlin.runtime.InternalApi", + "aws.sdk.kotlin.runtime.InternalSdkApi", + ) + } + } + } + } + } + + tasks.withType { + dependsOn(tasks.generateSmithyProjections) + kotlinOptions.allWarningsAsErrors = false + } +} + +fun configureTasks() { + tasks.register("stageServices") { + dependsOn(tasks.generateSmithyProjections) + + doLast { + this@Build_gradle.projections.forEach { projection -> + val projectionPath = smithyBuild.smithyKotlinProjectionPath(projection.name).get() + val destinationPath = layout.projectDirectory.asFile.absolutePath + "/services/${projection.name}" + + copy { + from("$projectionPath/src") + into("$destinationPath/generated-src") + } + copy { + from("$projectionPath/jvm-src") + into("$destinationPath/generated-src-jvm") + } + copy { + from("$projectionPath/build.gradle.kts") + into(destinationPath) + } + } + } + } + + tasks.build { + dependsOn(tasks.getByName("stageServices")) + } + + tasks.register("unstageServices") { + commandLine("git", "clean", "-fdx", "services") + } + + tasks.clean { + dependsOn(tasks.getByName("unstageServices")) + } +} + +/** + * Holds metadata about a smithy projection + */ +data class ProjectionMetadata( + val name: String, + val modelFile: String, + val serviceShapeId: String, +) diff --git a/tests/codegen/smoke-tests/services/build.gradle.kts b/tests/codegen/smoke-tests/services/build.gradle.kts new file mode 100644 index 00000000000..f4ec4cb784a --- /dev/null +++ b/tests/codegen/smoke-tests/services/build.gradle.kts @@ -0,0 +1,36 @@ +import aws.sdk.kotlin.gradle.kmp.kotlin + +plugins { + alias(libs.plugins.aws.kotlin.repo.tools.kmp) apply false +} + +// capture locally - scope issue with custom KMP plugin +val libraries = libs + +subprojects { + apply { + plugin(libraries.plugins.kotlin.multiplatform.get().pluginId) + plugin(libraries.plugins.aws.kotlin.repo.tools.kmp.get().pluginId) + } + + kotlin { + + jvm() + + sourceSets { + all { + languageSettings.optIn("kotlin.RequiresOptIn") + languageSettings.optIn("aws.smithy.kotlin.runtime.InternalApi") + languageSettings.optIn("aws.sdk.kotlin.runtime.InternalSdkApi") + } + + commonMain { + kotlin.srcDir("generated-src/main/kotlin") + } + + jvmTest { + kotlin.srcDir("generated-src-jvm/test/java") + } + } + } +} diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt new file mode 100644 index 00000000000..be643d987c0 --- /dev/null +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -0,0 +1,63 @@ +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SERVICE_FILTER +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SKIP_TAGS +import java.io.File +import kotlin.test.* + +class SmokeTestE2ETest { + @Test + fun successService() { + val smokeTestRunnerOutput = runSmokeTests("successService") + + assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service") + assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTestWithTags - no error expected from service") + } + + @Test + fun failureService() { + val smokeTestRunnerOutput = runSmokeTests("failureService") + + assertContains(smokeTestRunnerOutput, "ok FailureService FailuresTest - error expected from service") + } + + @Test + fun successServiceSkipTags() { + val envVars = mapOf(SKIP_TAGS to "success") + val smokeTestRunnerOutput = runSmokeTests("successService", envVars) + + assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service") + assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTestWithTags - no error expected from service # skip") + } + + @Test + fun successServiceServiceFilter() { + val envVars = mapOf(SERVICE_FILTER to "Failure") // Only run tests for services with this SDK ID + val smokeTestRunnerOutput = runSmokeTests("successService", envVars) + + assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service # skip") + assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTestWithTags - no error expected from service # skip") + } +} + +private fun runSmokeTests(service: String, envVars: Map = emptyMap()): String { + val sdkRootDir = System.getProperty("user.dir") + "/../../../" + + val output = StringBuilder() + val smokeTests = ProcessBuilder() + .command("./gradlew", ":tests:codegen:smoke-tests:services:$service:smokeTest") + .directory(File(sdkRootDir)) + .redirectErrorStream(true) + + envVars.forEach { (key, value) -> + smokeTests + .environment() + .put(key, value) + } + + smokeTests + .start() + .inputStream + .bufferedReader() + .forEachLine { output.append("$it\n") } + + return output.toString() +} diff --git a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy new file mode 100644 index 00000000000..39f96fad4e9 --- /dev/null +++ b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy @@ -0,0 +1,62 @@ +$version: "2" +namespace com.test + +use aws.protocols#awsJson1_0 +use aws.api#service +use smithy.test#smokeTests +use smithy.rules#endpointRuleSet + +@trait(selector: "service") +structure failedResponseTrait { } + +@failedResponseTrait +@awsJson1_0 +@service(sdkId: "Failure") +@endpointRuleSet( + version: "1.0", + parameters: {}, + rules: [ + { + "type": "endpoint", + "conditions": [], + "endpoint": { + "url": "https://static.endpoint" + } + } + ] +) +service FailureService { + version: "1.0.0", + operations: [ TestOperation ], +} + +@smokeTests( + [ + { + id: "FailuresTest" + params: {bar: "2"} + expect: { + failure: {} + } + vendorParamsShape: AwsVendorParams, + vendorParams: { + region: "eu-central-1" + } + } + ] +) +operation TestOperation { + input := { + bar: String + } + errors: [ + InvalidMessageError + ] +} + +@error("client") +structure InvalidMessageError {} + +structure AwsVendorParams { + region: String +} \ No newline at end of file diff --git a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy new file mode 100644 index 00000000000..e5e6d3d2e5f --- /dev/null +++ b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy @@ -0,0 +1,76 @@ +$version: "2" +namespace com.test + +use aws.protocols#awsJson1_0 +use aws.api#service +use smithy.test#smokeTests +use smithy.rules#endpointRuleSet + +@trait(selector: "service") +structure successResponseTrait { } + +@successResponseTrait +@awsJson1_0 +@service(sdkId: "Success") +@endpointRuleSet( + version: "1.0", + parameters: {}, + rules: [ + { + "type": "endpoint", + "conditions": [], + "endpoint": { + "url": "https://static.endpoint" + } + } + ] +) +service SuccessService { + version: "1.0.0", + operations: [ TestOperation ], +} + +@smokeTests( + [ + { + id: "SuccessTest" + params: {bar: "2"} + expect: { + success: {} + } + vendorParamsShape: AwsVendorParams, + vendorParams: { + region: "eu-central-1" + } + }, + { + id: "SuccessTestWithTags" + params: {bar: "2"} + tags: [ + "success" + ] + expect: { + success: {} + } + vendorParamsShape: AwsVendorParams, + vendorParams: { + region: "eu-central-1" + } + } + ] +) +operation TestOperation { + input := { + bar: String + } + errors: [ + InvalidMessageError + ] +} + +@error("client") +structure InvalidMessageError {} + +structure AwsVendorParams { + region: String +} \ No newline at end of file From f390f6a99f3b510c0473119643c67ccb38d8d9ec Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 17 Sep 2024 12:07:24 -0400 Subject: [PATCH 08/41] Remove dangerous gradle task, move sdk denylist check to codegen instead of runtime --- .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 6 ++---- tests/codegen/smoke-tests/build.gradle.kts | 14 +++----------- .../src/test/resources/smoke-tests-failure.smithy | 2 +- .../src/test/resources/smoke-tests-success.smithy | 2 +- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index 27b8ba3744c..04427ec52b4 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -11,7 +11,6 @@ import software.amazon.smithy.kotlin.codegen.model.hasTrait import software.amazon.smithy.kotlin.codegen.model.traits.FailedResponseTrait import software.amazon.smithy.kotlin.codegen.model.traits.SuccessResponseTrait import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter -import software.amazon.smithy.kotlin.codegen.utils.dq import software.amazon.smithy.kotlin.codegen.utils.operations import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.smoketests.traits.SmokeTestsTrait @@ -83,10 +82,9 @@ class GradleGenerator : KotlinIntegration { } private fun generateSmokeTestConfig(writer: GradleWriter, sdkId: String, ctx: CodegenContext) { - val formattedDenyList = smokeTestDenyList.joinToString(",", "setOf(", ")") { it.dq() } - writer.withBlock("if (#S !in #L) {", "}", sdkId, formattedDenyList) { + if (sdkId !in smokeTestDenyList) { generateSmokeTestJarTask(writer, ctx) - emptyLine() + writer.emptyLine() generateSmokeTestTask(writer, ctx) } } diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index 84a4cd5d16c..891a16b5ecd 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -7,15 +7,15 @@ import aws.sdk.kotlin.gradle.codegen.dsl.generateSmithyProjections import aws.sdk.kotlin.gradle.codegen.dsl.smithyKotlinPlugin import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionPath -description = "Tests for smoke tests runner" +description = "Tests for smoke tests runners" plugins { alias(libs.plugins.aws.kotlin.repo.tools.smithybuild) alias(libs.plugins.kotlin.jvm) } val projections = listOf( - ProjectionMetadata("successService", "smoke-tests-success.smithy", "com.test#SuccessService"), - ProjectionMetadata("failureService", "smoke-tests-failure.smithy", "com.test#FailureService"), + ProjectionMetadata("successService", "smoke-tests-success.smithy", "smithy.kotlin.traits#SuccessService"), + ProjectionMetadata("failureService", "smoke-tests-failure.smithy", "smithy.kotlin.traits#FailureService"), ) configureProject() @@ -93,14 +93,6 @@ fun configureTasks() { tasks.build { dependsOn(tasks.getByName("stageServices")) } - - tasks.register("unstageServices") { - commandLine("git", "clean", "-fdx", "services") - } - - tasks.clean { - dependsOn(tasks.getByName("unstageServices")) - } } /** diff --git a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy index 39f96fad4e9..0a903a77303 100644 --- a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy +++ b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy @@ -1,5 +1,5 @@ $version: "2" -namespace com.test +namespace smithy.kotlin.traits use aws.protocols#awsJson1_0 use aws.api#service diff --git a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy index e5e6d3d2e5f..45a8f425881 100644 --- a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy +++ b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy @@ -1,5 +1,5 @@ $version: "2" -namespace com.test +namespace smithy.kotlin.traits use aws.protocols#awsJson1_0 use aws.api#service From 90a93ac71a00ee2a9658aecae2fd8ff12afab1a1 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 18 Sep 2024 10:51:57 -0400 Subject: [PATCH 09/41] Fix kotlin native builds failing --- .../src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index 04427ec52b4..8d6d75b6bef 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -95,7 +95,6 @@ class GradleGenerator : KotlinIntegration { private fun generateSmokeTestJarTask(writer: GradleWriter, ctx: CodegenContext) { writer.withBlock("jvm {", "}") { withBlock("compilations {", "}") { - write("val runtimePath = configurations.getByName(#S).map { if (it.isDirectory) it else zipTree(it) }", "jvmRuntimeClasspath") write("val mainPath = getByName(#S).output.classesDirs", "main") write("val testPath = getByName(#S).output.classesDirs", "test") withBlock("tasks {", "}") { @@ -106,6 +105,7 @@ class GradleGenerator : KotlinIntegration { withBlock("manifest {", "}") { write("attributes[#S] = #S", "Main-Class", "${ctx.settings.pkg.name}.smoketests.SmokeTestsKt") } + write("val runtimePath = configurations.getByName(#S).map { if (it.isDirectory) it else zipTree(it) }", "jvmRuntimeClasspath") write("duplicatesStrategy = DuplicatesStrategy.EXCLUDE") write("from(runtimePath, mainPath, testPath)") write("archiveBaseName.set(#S)", "\${project.name}-smoketests") From 6b288ed9dd07fe2e975900a807cb5a467fcbf07e Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 18 Sep 2024 11:45:36 -0400 Subject: [PATCH 10/41] Temp print statement to debug --- tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index be643d987c0..a0bb3525f71 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -59,5 +59,6 @@ private fun runSmokeTests(service: String, envVars: Map = emptyM .bufferedReader() .forEachLine { output.append("$it\n") } + println(output.toString()) // TODO: Remove - this is here only for debugging CI tests return output.toString() } From c6701cbf93e9b8b0bf3f4433a046e2cfd1d22b72 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 18 Sep 2024 11:59:15 -0400 Subject: [PATCH 11/41] Change debugging print to exception --- tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index a0bb3525f71..8b9a812cd77 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -59,6 +59,6 @@ private fun runSmokeTests(service: String, envVars: Map = emptyM .bufferedReader() .forEachLine { output.append("$it\n") } - println(output.toString()) // TODO: Remove - this is here only for debugging CI tests + throw Exception(output.toString()) // TODO: Remove - this is here only for debugging CI tests return output.toString() } From 95b553dbbc020ceff8cb3496568dfc5a65c88b56 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 18 Sep 2024 13:33:37 -0400 Subject: [PATCH 12/41] chmod gradlew before tests --- .../smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index 8b9a812cd77..53895c83b72 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -41,6 +41,8 @@ class SmokeTestE2ETest { private fun runSmokeTests(service: String, envVars: Map = emptyMap()): String { val sdkRootDir = System.getProperty("user.dir") + "/../../../" + setUpGradlew(sdkRootDir) + val output = StringBuilder() val smokeTests = ProcessBuilder() .command("./gradlew", ":tests:codegen:smoke-tests:services:$service:smokeTest") @@ -59,6 +61,12 @@ private fun runSmokeTests(service: String, envVars: Map = emptyM .bufferedReader() .forEachLine { output.append("$it\n") } - throw Exception(output.toString()) // TODO: Remove - this is here only for debugging CI tests return output.toString() } + +private fun setUpGradlew(sdkRootDir: String) { + ProcessBuilder() + .command("chmod", "+x", "gradlew") + .directory(File(sdkRootDir)) + .start() +} From 5ac3db2bac728bc8b167ff2a9cf072c46f3c0bd6 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 19 Sep 2024 09:58:47 -0400 Subject: [PATCH 13/41] Use gradlew.bat --- tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index 53895c83b72..119af9cd40e 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -41,11 +41,11 @@ class SmokeTestE2ETest { private fun runSmokeTests(service: String, envVars: Map = emptyMap()): String { val sdkRootDir = System.getProperty("user.dir") + "/../../../" - setUpGradlew(sdkRootDir) +// setUpGradlew(sdkRootDir) val output = StringBuilder() val smokeTests = ProcessBuilder() - .command("./gradlew", ":tests:codegen:smoke-tests:services:$service:smokeTest") + .command("gradlew.bat", ":tests:codegen:smoke-tests:services:$service:smokeTest") .directory(File(sdkRootDir)) .redirectErrorStream(true) From ca3021173c99bb76c6a8970c1a4536a487298d3a Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 19 Sep 2024 15:43:37 -0400 Subject: [PATCH 14/41] ls sdk root dir --- .../smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index 119af9cd40e..759ce838b75 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -41,11 +41,9 @@ class SmokeTestE2ETest { private fun runSmokeTests(service: String, envVars: Map = emptyMap()): String { val sdkRootDir = System.getProperty("user.dir") + "/../../../" -// setUpGradlew(sdkRootDir) - val output = StringBuilder() val smokeTests = ProcessBuilder() - .command("gradlew.bat", ":tests:codegen:smoke-tests:services:$service:smokeTest") + .command("ls") .directory(File(sdkRootDir)) .redirectErrorStream(true) @@ -61,12 +59,6 @@ private fun runSmokeTests(service: String, envVars: Map = emptyM .bufferedReader() .forEachLine { output.append("$it\n") } + throw Exception(output.toString()) return output.toString() } - -private fun setUpGradlew(sdkRootDir: String) { - ProcessBuilder() - .command("chmod", "+x", "gradlew") - .directory(File(sdkRootDir)) - .start() -} From 08356db304464ae4be2fbaa13e35bda5b44af85a Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 20 Sep 2024 00:52:59 -0400 Subject: [PATCH 15/41] Use gradle connector instead of process builder --- .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 7 ++- tests/codegen/smoke-tests/build.gradle.kts | 10 +++- .../src/test/kotlin/SmokeTestE2ETest.kt | 46 +++++++++---------- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index 8d6d75b6bef..f4c837cd188 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -121,9 +121,12 @@ class GradleGenerator : KotlinIntegration { private fun generateSmokeTestTask(writer: GradleWriter, ctx: CodegenContext) { val hasSuccessResponseTrait = ctx.model.expectShape(ctx.settings.service).hasTrait(SuccessResponseTrait.ID) val hasFailedResponseTrait = ctx.model.expectShape(ctx.settings.service).hasTrait(FailedResponseTrait.ID) - - // E2E tests don't have sdkVersion in jar names val inTestingEnvironment = hasFailedResponseTrait || hasSuccessResponseTrait + + /** + * E2E tests don't have sdkVersion in jar names. They're added later for publishing. + * @see SmokeTestE2ETest + */ val jarName = if (inTestingEnvironment) "\${project.name}-smoketests.jar" else "\${project.name}-smoketests-\$sdkVersion.jar" writer.withBlock("tasks.register(#S) {", "}", "smokeTest") { diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index 891a16b5ecd..51f7afffbbe 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -27,10 +27,12 @@ fun configureProject() { dependencies { codegen(project(":codegen:aws-sdk-codegen")) - implementation(libs.smithy.kotlin.codegen) codegen(libs.smithy.cli) codegen(libs.smithy.model) + implementation(libs.smithy.kotlin.codegen) + implementation("org.gradle:gradle-tooling-api:+") + testImplementation(libs.kotlin.test) } } @@ -93,6 +95,12 @@ fun configureTasks() { tasks.build { dependsOn(tasks.getByName("stageServices")) } + + tasks.clean { + this@Build_gradle.projections.forEach { projection -> + delete("services/${projection.name}") + } + } } /** diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index 759ce838b75..f57c68b3a89 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -1,12 +1,14 @@ +import org.gradle.tooling.GradleConnector import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SERVICE_FILTER import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SKIP_TAGS +import java.io.ByteArrayOutputStream import java.io.File import kotlin.test.* class SmokeTestE2ETest { @Test fun successService() { - val smokeTestRunnerOutput = runSmokeTests("successService") + val smokeTestRunnerOutput = runSmokeTests() assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service") assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTestWithTags - no error expected from service") @@ -14,7 +16,7 @@ class SmokeTestE2ETest { @Test fun failureService() { - val smokeTestRunnerOutput = runSmokeTests("failureService") + val smokeTestRunnerOutput = runSmokeTests() assertContains(smokeTestRunnerOutput, "ok FailureService FailuresTest - error expected from service") } @@ -22,7 +24,7 @@ class SmokeTestE2ETest { @Test fun successServiceSkipTags() { val envVars = mapOf(SKIP_TAGS to "success") - val smokeTestRunnerOutput = runSmokeTests("successService", envVars) + val smokeTestRunnerOutput = runSmokeTests(envVars) assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service") assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTestWithTags - no error expected from service # skip") @@ -31,34 +33,28 @@ class SmokeTestE2ETest { @Test fun successServiceServiceFilter() { val envVars = mapOf(SERVICE_FILTER to "Failure") // Only run tests for services with this SDK ID - val smokeTestRunnerOutput = runSmokeTests("successService", envVars) + val smokeTestRunnerOutput = runSmokeTests(envVars) assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service # skip") assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTestWithTags - no error expected from service # skip") } } -private fun runSmokeTests(service: String, envVars: Map = emptyMap()): String { - val sdkRootDir = System.getProperty("user.dir") + "/../../../" - - val output = StringBuilder() - val smokeTests = ProcessBuilder() - .command("ls") - .directory(File(sdkRootDir)) - .redirectErrorStream(true) - - envVars.forEach { (key, value) -> - smokeTests - .environment() - .put(key, value) +private fun runSmokeTests(envVars: Map = emptyMap()): String { + val currentDir = System.getProperty("user.dir") + val outputStream = ByteArrayOutputStream() + val connector = GradleConnector.newConnector() + .forProjectDirectory(File(currentDir)) + .connect() + + connector.use { + it.newBuild() + .forTasks("smokeTest") + .setStandardOutput(outputStream) + .setStandardError(outputStream) + .setEnvironmentVariables(envVars) + .run() } - smokeTests - .start() - .inputStream - .bufferedReader() - .forEachLine { output.append("$it\n") } - - throw Exception(output.toString()) - return output.toString() + return outputStream.toString() } From e7fdeffb24e6a4c8163a481e86e696f858e31769 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 20 Sep 2024 09:49:19 -0400 Subject: [PATCH 16/41] build before testing --- .github/workflows/continuous-integration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b8cb2e12035..564b96d2238 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -70,6 +70,7 @@ jobs: ./gradlew :build-support:test ./gradlew publishToMavenLocal ./gradlew apiCheck + ./gradlew build ./gradlew test jvmTest ./gradlew testAllProtocols - name: Save Test Reports From 8f0dec113a6cb3ac086015c29dc216f54a8f1a79 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 20 Sep 2024 13:47:46 -0400 Subject: [PATCH 17/41] increase gradle connection timeout --- gradle.properties | 4 ++++ tests/codegen/smoke-tests/build.gradle.kts | 11 ++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4fc4817495e..11b3a9a22d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,6 +4,10 @@ kotlin.native.ignoreDisabledTargets=true # gradle org.gradle.jvmargs=-Xmx6g -XX:MaxMetaspaceSize=2G +org.gradle.internal.http.connectionTimeout=120_000 +org.gradle.internal.http.socketTimeout=120_000 +org.gradle.internal.https.connectionTimeout=120_000 +org.gradle.internal.https.socketTimeout=120_000 # sdk sdkVersion=1.3.18-SNAPSHOT diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index 51f7afffbbe..79490743aec 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -8,18 +8,19 @@ import aws.sdk.kotlin.gradle.codegen.dsl.smithyKotlinPlugin import aws.sdk.kotlin.gradle.codegen.smithyKotlinProjectionPath description = "Tests for smoke tests runners" + plugins { alias(libs.plugins.aws.kotlin.repo.tools.smithybuild) alias(libs.plugins.kotlin.jvm) } val projections = listOf( - ProjectionMetadata("successService", "smoke-tests-success.smithy", "smithy.kotlin.traits#SuccessService"), - ProjectionMetadata("failureService", "smoke-tests-failure.smithy", "smithy.kotlin.traits#FailureService"), + Projection("successService", "smoke-tests-success.smithy", "smithy.kotlin.traits#SuccessService"), + Projection("failureService", "smoke-tests-failure.smithy", "smithy.kotlin.traits#FailureService"), ) configureProject() -configureSmithyProjections() +configureProjections() configureTasks() fun configureProject() { @@ -37,7 +38,7 @@ fun configureProject() { } } -fun configureSmithyProjections() { +fun configureProjections() { smithyBuild { val pathToSmithyModels = "src/test/resources/" @@ -106,7 +107,7 @@ fun configureTasks() { /** * Holds metadata about a smithy projection */ -data class ProjectionMetadata( +data class Projection( val name: String, val modelFile: String, val serviceShapeId: String, From 431e63efb744f1b5a537c85f897a42b3f28e19f9 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 20 Sep 2024 14:52:07 -0400 Subject: [PATCH 18/41] run from sdk root dir, better logging, use explicit gradle distribution URI --- .../src/test/kotlin/SmokeTestE2ETest.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index f57c68b3a89..7fa2437638e 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -3,6 +3,7 @@ import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SERVICE_FILTER import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SKIP_TAGS import java.io.ByteArrayOutputStream import java.io.File +import java.net.URI import kotlin.test.* class SmokeTestE2ETest { @@ -41,19 +42,24 @@ class SmokeTestE2ETest { } private fun runSmokeTests(envVars: Map = emptyMap()): String { - val currentDir = System.getProperty("user.dir") + val sdkRootDir = System.getProperty("user.dir") + "/../../../" val outputStream = ByteArrayOutputStream() val connector = GradleConnector.newConnector() - .forProjectDirectory(File(currentDir)) + .forProjectDirectory(File(sdkRootDir)) + .useDistribution(URI("https://services.gradle.org/distributions/gradle-8.5-bin.zip")) .connect() - connector.use { - it.newBuild() - .forTasks("smokeTest") - .setStandardOutput(outputStream) - .setStandardError(outputStream) - .setEnvironmentVariables(envVars) - .run() + try { + connector.use { + it.newBuild() + .forTasks("smokeTest") + .setStandardOutput(outputStream) + .setStandardError(outputStream) + .setEnvironmentVariables(envVars) + .run() + } + } catch (e: Exception) { + throw Exception(e.message + "\n\n\n\n\n" + outputStream.toString(), e) } return outputStream.toString() From 1706764444a90903764d4dc8e723f98d432f7205 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 20 Sep 2024 20:54:01 -0400 Subject: [PATCH 19/41] Enable gradle daemon with an idle timeout, increment internal timeout --- .github/workflows/continuous-integration.yml | 2 +- gradle.properties | 3 +++ tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt | 2 -- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 564b96d2238..5ce3696576d 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -11,7 +11,7 @@ concurrency: env: RUN: ${{ github.run_id }}-${{ github.run_number }} - GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dkotlin.incremental=false" + GRADLE_OPTS: "-Dorg.gradle.daemon.idletimeout=60000 -Dkotlin.incremental=false" jobs: jvm: diff --git a/gradle.properties b/gradle.properties index 11b3a9a22d9..3c8d6b2cea5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,10 +4,13 @@ kotlin.native.ignoreDisabledTargets=true # gradle org.gradle.jvmargs=-Xmx6g -XX:MaxMetaspaceSize=2G + +# temp debugging properties org.gradle.internal.http.connectionTimeout=120_000 org.gradle.internal.http.socketTimeout=120_000 org.gradle.internal.https.connectionTimeout=120_000 org.gradle.internal.https.socketTimeout=120_000 +org.gradle.internal.timeout=120_000 # sdk sdkVersion=1.3.18-SNAPSHOT diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index 7fa2437638e..2c409c01184 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -3,7 +3,6 @@ import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SERVICE_FILTER import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SKIP_TAGS import java.io.ByteArrayOutputStream import java.io.File -import java.net.URI import kotlin.test.* class SmokeTestE2ETest { @@ -46,7 +45,6 @@ private fun runSmokeTests(envVars: Map = emptyMap()): String { val outputStream = ByteArrayOutputStream() val connector = GradleConnector.newConnector() .forProjectDirectory(File(sdkRootDir)) - .useDistribution(URI("https://services.gradle.org/distributions/gradle-8.5-bin.zip")) .connect() try { From bb53c3d10a5985e8dc676302c2736bc8752f22c5 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Sun, 22 Sep 2024 11:50:34 -0400 Subject: [PATCH 20/41] use gradle runner instead of connector --- .github/workflows/continuous-integration.yml | 2 +- gradle.properties | 7 ----- tests/codegen/smoke-tests/build.gradle.kts | 2 +- .../src/test/kotlin/SmokeTestE2ETest.kt | 27 +++++-------------- 4 files changed, 9 insertions(+), 29 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 5ce3696576d..564b96d2238 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -11,7 +11,7 @@ concurrency: env: RUN: ${{ github.run_id }}-${{ github.run_number }} - GRADLE_OPTS: "-Dorg.gradle.daemon.idletimeout=60000 -Dkotlin.incremental=false" + GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dkotlin.incremental=false" jobs: jvm: diff --git a/gradle.properties b/gradle.properties index 3c8d6b2cea5..4fc4817495e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,13 +5,6 @@ kotlin.native.ignoreDisabledTargets=true # gradle org.gradle.jvmargs=-Xmx6g -XX:MaxMetaspaceSize=2G -# temp debugging properties -org.gradle.internal.http.connectionTimeout=120_000 -org.gradle.internal.http.socketTimeout=120_000 -org.gradle.internal.https.connectionTimeout=120_000 -org.gradle.internal.https.socketTimeout=120_000 -org.gradle.internal.timeout=120_000 - # sdk sdkVersion=1.3.18-SNAPSHOT diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index 79490743aec..047ea1af71c 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -32,9 +32,9 @@ fun configureProject() { codegen(libs.smithy.model) implementation(libs.smithy.kotlin.codegen) - implementation("org.gradle:gradle-tooling-api:+") testImplementation(libs.kotlin.test) + testImplementation(gradleTestKit()) } } diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index 2c409c01184..50ff7b2c391 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -1,7 +1,6 @@ -import org.gradle.tooling.GradleConnector +import org.gradle.testkit.runner.GradleRunner import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SERVICE_FILTER import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SKIP_TAGS -import java.io.ByteArrayOutputStream import java.io.File import kotlin.test.* @@ -42,23 +41,11 @@ class SmokeTestE2ETest { private fun runSmokeTests(envVars: Map = emptyMap()): String { val sdkRootDir = System.getProperty("user.dir") + "/../../../" - val outputStream = ByteArrayOutputStream() - val connector = GradleConnector.newConnector() - .forProjectDirectory(File(sdkRootDir)) - .connect() + val runner = GradleRunner.create() + .withProjectDir(File(sdkRootDir)) + .withArguments("smokeTest") + .withEnvironment(envVars) + .build() - try { - connector.use { - it.newBuild() - .forTasks("smokeTest") - .setStandardOutput(outputStream) - .setStandardError(outputStream) - .setEnvironmentVariables(envVars) - .run() - } - } catch (e: Exception) { - throw Exception(e.message + "\n\n\n\n\n" + outputStream.toString(), e) - } - - return outputStream.toString() + return runner.output } From e13e9fcd0a2e53cb24b3bb399eca1108aec7da0a Mon Sep 17 00:00:00 2001 From: 0marperez Date: Sun, 22 Sep 2024 12:38:04 -0400 Subject: [PATCH 21/41] Specify smokeTests to run & better test failure logging --- tests/codegen/smoke-tests/build.gradle.kts | 10 ++++++++++ .../smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index 047ea1af71c..a65f1419087 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -102,6 +102,16 @@ fun configureTasks() { delete("services/${projection.name}") } } + + tasks.withType { + testLogging { + events("passed", "skipped", "failed") + exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL + showExceptions = true + showCauses = true + showStackTraces = true + } + } } /** diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index 50ff7b2c391..d27eef61583 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -7,7 +7,7 @@ import kotlin.test.* class SmokeTestE2ETest { @Test fun successService() { - val smokeTestRunnerOutput = runSmokeTests() + val smokeTestRunnerOutput = runSmokeTests("successService") assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service") assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTestWithTags - no error expected from service") @@ -15,7 +15,7 @@ class SmokeTestE2ETest { @Test fun failureService() { - val smokeTestRunnerOutput = runSmokeTests() + val smokeTestRunnerOutput = runSmokeTests("failureService") assertContains(smokeTestRunnerOutput, "ok FailureService FailuresTest - error expected from service") } @@ -23,7 +23,7 @@ class SmokeTestE2ETest { @Test fun successServiceSkipTags() { val envVars = mapOf(SKIP_TAGS to "success") - val smokeTestRunnerOutput = runSmokeTests(envVars) + val smokeTestRunnerOutput = runSmokeTests("successService", envVars) assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service") assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTestWithTags - no error expected from service # skip") @@ -32,18 +32,18 @@ class SmokeTestE2ETest { @Test fun successServiceServiceFilter() { val envVars = mapOf(SERVICE_FILTER to "Failure") // Only run tests for services with this SDK ID - val smokeTestRunnerOutput = runSmokeTests(envVars) + val smokeTestRunnerOutput = runSmokeTests("successService", envVars) assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service # skip") assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTestWithTags - no error expected from service # skip") } } -private fun runSmokeTests(envVars: Map = emptyMap()): String { +private fun runSmokeTests(service: String, envVars: Map = emptyMap()): String { val sdkRootDir = System.getProperty("user.dir") + "/../../../" val runner = GradleRunner.create() .withProjectDir(File(sdkRootDir)) - .withArguments("smokeTest") + .withArguments(":tests:codegen:smoke-tests:services:$service:smokeTest") .withEnvironment(envVars) .build() From afc5168e5b72f6cf16eb55af31dc433c08192ea9 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Sun, 22 Sep 2024 13:36:27 -0400 Subject: [PATCH 22/41] fix parallel task execution issues --- .../src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt | 2 ++ tests/codegen/smoke-tests/build.gradle.kts | 1 + 2 files changed, 3 insertions(+) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index f4c837cd188..8a91aff9d65 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -102,6 +102,7 @@ class GradleGenerator : KotlinIntegration { write("description = #S", "Creates smoke tests jar") write("group = #S", "application") write("dependsOn(build)") + write("mustRunAfter(build)") withBlock("manifest {", "}") { write("attributes[#S] = #S", "Main-Class", "${ctx.settings.pkg.name}.smoketests.SmokeTestsKt") } @@ -133,6 +134,7 @@ class GradleGenerator : KotlinIntegration { write("description = #S", "Runs smoke tests jar") write("group = #S", "verification") write("dependsOn(tasks.getByName(#S))", "smokeTestJar") + write("mustRunAfter(tasks.getByName(#S))", "smokeTestJar") emptyLine() write("val sdkVersion: String by project") write("val jarFile = file(#S)", "build/libs/$jarName") diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index a65f1419087..ce08784e545 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -111,6 +111,7 @@ fun configureTasks() { showCauses = true showStackTraces = true } + mustRunAfter(tasks.getByName("stageServices")) } } From c39f3feff36a2e6fd9cdd9090cdb9202713eb93e Mon Sep 17 00:00:00 2001 From: 0marperez Date: Mon, 23 Sep 2024 10:33:16 -0400 Subject: [PATCH 23/41] move task dependency from ci tests to code --- .github/workflows/continuous-integration.yml | 1 - tests/codegen/smoke-tests/build.gradle.kts | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 564b96d2238..b8cb2e12035 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -70,7 +70,6 @@ jobs: ./gradlew :build-support:test ./gradlew publishToMavenLocal ./gradlew apiCheck - ./gradlew build ./gradlew test jvmTest ./gradlew testAllProtocols - name: Save Test Reports diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index ce08784e545..e0c59402473 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -95,6 +95,7 @@ fun configureTasks() { tasks.build { dependsOn(tasks.getByName("stageServices")) + mustRunAfter(tasks.getByName("stageServices")) } tasks.clean { @@ -104,6 +105,9 @@ fun configureTasks() { } tasks.withType { + dependsOn(tasks.getByName("stageServices")) + mustRunAfter(tasks.getByName("stageServices")) + testLogging { events("passed", "skipped", "failed") exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL @@ -111,7 +115,6 @@ fun configureTasks() { showCauses = true showStackTraces = true } - mustRunAfter(tasks.getByName("stageServices")) } } From 5dfd004135db1d5ed70107ef7b3b449bca0a6e92 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Mon, 23 Sep 2024 17:36:55 -0400 Subject: [PATCH 24/41] easy to fix PR feedback and decoupling SmokeTestRunnerGenerator from SDK --- .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 21 ++++---- .../SmokeTestFailHttpEngineIntegration.kt | 49 +++++++++++++++++++ .../SmokeTestSuccessHttpEngineIntegration.kt | 40 +++++++++++++++ .../SmokeTestsCodegenRegionIntegration.kt | 40 +++++++++++++++ .../SmokeTestsDenyListIntegration.kt | 6 +-- ...tlin.codegen.integration.KotlinIntegration | 5 +- 6 files changed, 146 insertions(+), 15 deletions(-) create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt rename codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/{ => smoketests}/SmokeTestsDenyListIntegration.kt (84%) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index 8a91aff9d65..4098d0e6ef3 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -4,6 +4,7 @@ */ package aws.sdk.kotlin.codegen +import aws.sdk.kotlin.codegen.smoketests.smokeTestDenyList import software.amazon.smithy.kotlin.codegen.core.* import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.model.expectShape @@ -11,7 +12,7 @@ import software.amazon.smithy.kotlin.codegen.model.hasTrait import software.amazon.smithy.kotlin.codegen.model.traits.FailedResponseTrait import software.amazon.smithy.kotlin.codegen.model.traits.SuccessResponseTrait import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter -import software.amazon.smithy.kotlin.codegen.utils.operations +import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.smoketests.traits.SmokeTestsTrait @@ -71,9 +72,9 @@ class GradleGenerator : KotlinIntegration { } } } - if (ctx.model.operations(ctx.settings.service).any { it.hasTrait() }) { - emptyLine() - generateSmokeTestConfig(writer, ctx.settings.sdkId, ctx) + if (ctx.model.topDownOperations(ctx.settings.service).any { it.hasTrait() } && ctx.settings.sdkId !in smokeTestDenyList) { + write("") + generateSmokeTestConfig(writer, ctx) } } @@ -81,12 +82,10 @@ class GradleGenerator : KotlinIntegration { delegator.fileManifest.writeFile("build.gradle.kts", contents) } - private fun generateSmokeTestConfig(writer: GradleWriter, sdkId: String, ctx: CodegenContext) { - if (sdkId !in smokeTestDenyList) { - generateSmokeTestJarTask(writer, ctx) - writer.emptyLine() - generateSmokeTestTask(writer, ctx) - } + private fun generateSmokeTestConfig(writer: GradleWriter, ctx: CodegenContext) { + generateSmokeTestJarTask(writer, ctx) + writer.write("") + generateSmokeTestTask(writer, ctx) } /** @@ -135,7 +134,7 @@ class GradleGenerator : KotlinIntegration { write("group = #S", "verification") write("dependsOn(tasks.getByName(#S))", "smokeTestJar") write("mustRunAfter(tasks.getByName(#S))", "smokeTestJar") - emptyLine() + write("") write("val sdkVersion: String by project") write("val jarFile = file(#S)", "build/libs/$jarName") write("classpath = files(jarFile)") diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt new file mode 100644 index 00000000000..d76ef7087ab --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt @@ -0,0 +1,49 @@ +package aws.sdk.kotlin.codegen.smoketests + +import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes +import software.amazon.smithy.kotlin.codegen.core.withBlock +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionWriter +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding +import software.amazon.smithy.kotlin.codegen.model.expectShape +import software.amazon.smithy.kotlin.codegen.model.hasTrait +import software.amazon.smithy.kotlin.codegen.model.traits.FailedResponseTrait +import software.amazon.smithy.kotlin.codegen.model.traits.SuccessResponseTrait +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestHttpEngineOverride +import software.amazon.smithy.kotlin.codegen.utils.topDownOperations +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.ServiceShape +import software.amazon.smithy.smoketests.traits.SmokeTestsTrait + +/** + * Adds [FailedResponseTrait] support to smoke tests + */ +class SmokeTestFailHttpEngineIntegration : KotlinIntegration { + override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = + model.topDownOperations(settings.service).any { it.hasTrait() } && + settings.sdkId !in smokeTestDenyList && + !model.expectShape(settings.service).hasTrait(SuccessResponseTrait.ID) && + model.expectShape(settings.service).hasTrait(FailedResponseTrait.ID) + + override val sectionWriters: List + get() = listOf( + SectionWriterBinding(SmokeTestHttpEngineOverride, httpClientOverride), + ) + + private val httpClientOverride = SectionWriter { writer, _ -> + writer.withBlock("httpClient = #T(", ")", RuntimeTypes.HttpTest.TestEngine) { + withBlock("roundTripImpl = { _, request ->", "}") { + write( + "val resp = #T(#T.BadRequest, #T.Empty, #T.Empty)", + RuntimeTypes.Http.Response.HttpResponse, + RuntimeTypes.Http.StatusCode, + RuntimeTypes.Http.Headers, + RuntimeTypes.Http.HttpBody, + ) + write("val now = #T.now()", RuntimeTypes.Core.Instant) + write("#T(request, resp, now, now)", RuntimeTypes.Http.HttpCall) + } + } + } +} \ No newline at end of file diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt new file mode 100644 index 00000000000..b578b8dc552 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt @@ -0,0 +1,40 @@ +package aws.sdk.kotlin.codegen.smoketests + +import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes +import software.amazon.smithy.kotlin.codegen.core.withBlock +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionWriter +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding +import software.amazon.smithy.kotlin.codegen.model.expectShape +import software.amazon.smithy.kotlin.codegen.model.hasTrait +import software.amazon.smithy.kotlin.codegen.model.traits.FailedResponseTrait +import software.amazon.smithy.kotlin.codegen.model.traits.SuccessResponseTrait +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestAdditionalEnvVars +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestDefaultConfig +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestHttpEngineOverride +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestRegionDefault +import software.amazon.smithy.kotlin.codegen.utils.topDownOperations +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.ServiceShape +import software.amazon.smithy.smoketests.traits.SmokeTestsTrait + +/** + * Adds [SuccessResponseTrait] support to smoke tests + */ +class SmokeTestSuccessHttpEngineIntegration : KotlinIntegration { + override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = + model.topDownOperations(settings.service).any { it.hasTrait() } && + settings.sdkId !in smokeTestDenyList && + model.expectShape(settings.service).hasTrait(SuccessResponseTrait.ID) && + !model.expectShape(settings.service).hasTrait(FailedResponseTrait.ID) + + override val sectionWriters: List + get() = listOf( + SectionWriterBinding(SmokeTestHttpEngineOverride, httpClientOverride), + ) + + private val httpClientOverride = SectionWriter { writer, _ -> + writer.write("httpClient = #T()", RuntimeTypes.HttpTest.TestEngine) + } +} \ No newline at end of file diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt new file mode 100644 index 00000000000..4baecab9a63 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt @@ -0,0 +1,40 @@ +package aws.sdk.kotlin.codegen.smoketests + +import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionWriter +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding +import software.amazon.smithy.kotlin.codegen.model.hasTrait +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestDefaultConfig +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestAdditionalEnvVars +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestRegionDefault +import software.amazon.smithy.kotlin.codegen.utils.topDownOperations +import software.amazon.smithy.model.Model +import software.amazon.smithy.smoketests.traits.SmokeTestsTrait + +/** + * Adds AWS region support to smoke tests + */ +class SmokeTestsCodegenRegionIntegration : KotlinIntegration { + override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = + model.topDownOperations(settings.service).any { it.hasTrait() } && settings.sdkId !in smokeTestDenyList + + override val sectionWriters: List + get() = listOf( + SectionWriterBinding(SmokeTestAdditionalEnvVars, envVars), + SectionWriterBinding(SmokeTestDefaultConfig, region), + SectionWriterBinding(SmokeTestRegionDefault, regionDefault), + ) + + private val envVars = SectionWriter { writer, _ -> + writer.write("private val regionOverride = System.getenv(#S)", "AWS_SMOKE_TEST_REGION") + } + + private val region = SectionWriter { writer, _ -> + writer.write("region = regionOverride") + } + + private val regionDefault = SectionWriter { writer, _ -> + writer.write("regionOverride ?:") + } +} \ No newline at end of file diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt similarity index 84% rename from codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt index 09b057f7d3d..e7de6f0119f 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SmokeTestsDenyListIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt @@ -1,4 +1,4 @@ -package aws.sdk.kotlin.codegen +package aws.sdk.kotlin.codegen.smoketests import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -18,10 +18,10 @@ class SmokeTestsDenyListIntegration : KotlinIntegration { override val sectionWriters: List get() = listOf( - SectionWriterBinding(SmokeTestsRunner, endpointBusinessMetricsSectionWriter), + SectionWriterBinding(SmokeTestsRunner, smokeTestDenyListSectionWriter), ) - private val endpointBusinessMetricsSectionWriter = SectionWriter { writer, _ -> + private val smokeTestDenyListSectionWriter = SectionWriter { writer, _ -> writer.write("// Smoke tests for service deny listed until model is fixed") } } diff --git a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration index c66b5b097bc..83ca84b7f2f 100644 --- a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +++ b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -43,4 +43,7 @@ aws.sdk.kotlin.codegen.customization.s3.express.SigV4S3ExpressAuthSchemeIntegrat aws.sdk.kotlin.codegen.customization.s3.express.S3ExpressIntegration aws.sdk.kotlin.codegen.customization.s3.S3ExpiresIntegration aws.sdk.kotlin.codegen.BusinessMetricsIntegration -aws.sdk.kotlin.codegen.SmokeTestsDenyListIntegration +aws.sdk.kotlin.codegen.smoketests.SmokeTestsDenyListIntegration +aws.sdk.kotlin.codegen.smoketests.SmokeTestsCodegenRegionIntegration +aws.sdk.kotlin.codegen.smoketests.SmokeTestSuccessHttpEngineIntegration +aws.sdk.kotlin.codegen.smoketests.SmokeTestFailHttpEngineIntegration From c1e0edf76f344dfa6b5d0b71c1bd40df7ce6c1fe Mon Sep 17 00:00:00 2001 From: 0marperez Date: Mon, 23 Sep 2024 21:17:29 -0400 Subject: [PATCH 25/41] Remove accidental changes to AWS model --- .../smoketests/SmokeTestFailHttpEngineIntegration.kt | 8 ++++---- .../SmokeTestSuccessHttpEngineIntegration.kt | 12 ++++-------- .../smoketests/SmokeTestsCodegenRegionIntegration.kt | 4 ++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt index d76ef7087ab..24fa77300c2 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt @@ -22,9 +22,9 @@ import software.amazon.smithy.smoketests.traits.SmokeTestsTrait class SmokeTestFailHttpEngineIntegration : KotlinIntegration { override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = model.topDownOperations(settings.service).any { it.hasTrait() } && - settings.sdkId !in smokeTestDenyList && - !model.expectShape(settings.service).hasTrait(SuccessResponseTrait.ID) && - model.expectShape(settings.service).hasTrait(FailedResponseTrait.ID) + settings.sdkId !in smokeTestDenyList && + !model.expectShape(settings.service).hasTrait(SuccessResponseTrait.ID) && + model.expectShape(settings.service).hasTrait(FailedResponseTrait.ID) override val sectionWriters: List get() = listOf( @@ -46,4 +46,4 @@ class SmokeTestFailHttpEngineIntegration : KotlinIntegration { } } } -} \ No newline at end of file +} diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt index b578b8dc552..a1587f03e56 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt @@ -2,7 +2,6 @@ package aws.sdk.kotlin.codegen.smoketests import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes -import software.amazon.smithy.kotlin.codegen.core.withBlock import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding @@ -10,10 +9,7 @@ import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait import software.amazon.smithy.kotlin.codegen.model.traits.FailedResponseTrait import software.amazon.smithy.kotlin.codegen.model.traits.SuccessResponseTrait -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestAdditionalEnvVars -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestDefaultConfig import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestHttpEngineOverride -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestRegionDefault import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -25,9 +21,9 @@ import software.amazon.smithy.smoketests.traits.SmokeTestsTrait class SmokeTestSuccessHttpEngineIntegration : KotlinIntegration { override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = model.topDownOperations(settings.service).any { it.hasTrait() } && - settings.sdkId !in smokeTestDenyList && - model.expectShape(settings.service).hasTrait(SuccessResponseTrait.ID) && - !model.expectShape(settings.service).hasTrait(FailedResponseTrait.ID) + settings.sdkId !in smokeTestDenyList && + model.expectShape(settings.service).hasTrait(SuccessResponseTrait.ID) && + !model.expectShape(settings.service).hasTrait(FailedResponseTrait.ID) override val sectionWriters: List get() = listOf( @@ -37,4 +33,4 @@ class SmokeTestSuccessHttpEngineIntegration : KotlinIntegration { private val httpClientOverride = SectionWriter { writer, _ -> writer.write("httpClient = #T()", RuntimeTypes.HttpTest.TestEngine) } -} \ No newline at end of file +} diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt index 4baecab9a63..5404637c1f1 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt @@ -5,8 +5,8 @@ import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestDefaultConfig import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestAdditionalEnvVars +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestDefaultConfig import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestRegionDefault import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model @@ -37,4 +37,4 @@ class SmokeTestsCodegenRegionIntegration : KotlinIntegration { private val regionDefault = SectionWriter { writer, _ -> writer.write("regionOverride ?:") } -} \ No newline at end of file +} From dfcffbb3de638b95e69ca4dc295f1f9936120ecf Mon Sep 17 00:00:00 2001 From: 0marperez Date: Mon, 23 Sep 2024 22:31:33 -0400 Subject: [PATCH 26/41] Run smoke tests in common --- .gitignore | 2 -- .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 4 ++-- .../codegen/model/traits/SmokeTestTraits.kt | 23 +++++++++++++++++++ .../SmokeTestFailHttpEngineIntegration.kt | 4 ++-- .../SmokeTestSuccessHttpEngineIntegration.kt | 4 ++-- codegen/sdk/build.gradle.kts | 4 ---- services/build.gradle.kts | 4 ---- tests/codegen/smoke-tests/build.gradle.kts | 6 +---- .../smoke-tests/services/build.gradle.kts | 4 ++-- 9 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/SmokeTestTraits.kt diff --git a/.gitignore b/.gitignore index 865830349b3..45b192f3d25 100644 --- a/.gitignore +++ b/.gitignore @@ -17,8 +17,6 @@ local.properties # ignore generated files services/*/generated-src -services/*/generated-src-jvm services/*/build.gradle.kts tests/codegen/smoke-tests/services/*/generated-src -tests/codegen/smoke-tests/services/*/generated-src-jvm tests/codegen/smoke-tests/services/*/build.gradle.kts \ No newline at end of file diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index 4098d0e6ef3..32606ea2460 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -4,13 +4,13 @@ */ package aws.sdk.kotlin.codegen +import aws.sdk.kotlin.codegen.model.traits.FailedResponseTrait +import aws.sdk.kotlin.codegen.model.traits.SuccessResponseTrait import aws.sdk.kotlin.codegen.smoketests.smokeTestDenyList import software.amazon.smithy.kotlin.codegen.core.* import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.model.traits.FailedResponseTrait -import software.amazon.smithy.kotlin.codegen.model.traits.SuccessResponseTrait import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.shapes.ServiceShape diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/SmokeTestTraits.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/SmokeTestTraits.kt new file mode 100644 index 00000000000..9a115357629 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/SmokeTestTraits.kt @@ -0,0 +1,23 @@ +package aws.sdk.kotlin.codegen.model.traits + +import software.amazon.smithy.model.node.ObjectNode +import software.amazon.smithy.model.shapes.ShapeId +import software.amazon.smithy.model.traits.AnnotationTrait + +/** + * Indicates the annotated service should always return a failed response. + */ +class FailedResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) { + companion object { + val ID: ShapeId = ShapeId.from("smithy.kotlin.traits#failedResponseTrait") + } +} + +/** + * Indicates the annotated service should always return a success response. + */ +class SuccessResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) { + companion object { + val ID: ShapeId = ShapeId.from("smithy.kotlin.traits#successResponseTrait") + } +} diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt index 24fa77300c2..cc3a11bc18e 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt @@ -1,5 +1,7 @@ package aws.sdk.kotlin.codegen.smoketests +import aws.sdk.kotlin.codegen.model.traits.FailedResponseTrait +import aws.sdk.kotlin.codegen.model.traits.SuccessResponseTrait import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.core.withBlock @@ -8,8 +10,6 @@ import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.model.traits.FailedResponseTrait -import software.amazon.smithy.kotlin.codegen.model.traits.SuccessResponseTrait import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestHttpEngineOverride import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt index a1587f03e56..296fe4f4564 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt @@ -1,5 +1,7 @@ package aws.sdk.kotlin.codegen.smoketests +import aws.sdk.kotlin.codegen.model.traits.FailedResponseTrait +import aws.sdk.kotlin.codegen.model.traits.SuccessResponseTrait import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -7,8 +9,6 @@ import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.model.traits.FailedResponseTrait -import software.amazon.smithy.kotlin.codegen.model.traits.SuccessResponseTrait import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestHttpEngineOverride import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model diff --git a/codegen/sdk/build.gradle.kts b/codegen/sdk/build.gradle.kts index a25e87efbc6..2ef66603b3b 100644 --- a/codegen/sdk/build.gradle.kts +++ b/codegen/sdk/build.gradle.kts @@ -176,10 +176,6 @@ val stageSdks = tasks.register("stageSdks") { from("$projectionOutputDir/src") into("${it.destinationDir}/generated-src") } - copy { - from("$projectionOutputDir/jvm-src") - into("${it.destinationDir}/generated-src-jvm") - } copy { from("$projectionOutputDir/build.gradle.kts") into(it.destinationDir) diff --git a/services/build.gradle.kts b/services/build.gradle.kts index a13597aed2e..d6749594dc9 100644 --- a/services/build.gradle.kts +++ b/services/build.gradle.kts @@ -50,10 +50,6 @@ subprojects { kotlin.srcDir("generated-src/main/kotlin") } - getByName("jvmTest") { - kotlin.srcDir("generated-src-jvm/test/java") - } - getByName("commonTest") { kotlin.srcDir("generated-src/test") diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index e0c59402473..7d082ddb9b8 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -47,7 +47,7 @@ fun configureProjections() { imports = listOf(layout.projectDirectory.file(pathToSmithyModels + projection.modelFile).asFile.absolutePath) smithyKotlinPlugin { serviceShapeId = projection.serviceShapeId - packageName = "aws.sdk.kotlin.test.smoketests" + packageName = "aws.sdk.kotlin.test" packageVersion = "1.0" buildSettings { generateFullProject = false @@ -81,10 +81,6 @@ fun configureTasks() { from("$projectionPath/src") into("$destinationPath/generated-src") } - copy { - from("$projectionPath/jvm-src") - into("$destinationPath/generated-src-jvm") - } copy { from("$projectionPath/build.gradle.kts") into(destinationPath) diff --git a/tests/codegen/smoke-tests/services/build.gradle.kts b/tests/codegen/smoke-tests/services/build.gradle.kts index f4ec4cb784a..2238ac4b0d1 100644 --- a/tests/codegen/smoke-tests/services/build.gradle.kts +++ b/tests/codegen/smoke-tests/services/build.gradle.kts @@ -28,8 +28,8 @@ subprojects { kotlin.srcDir("generated-src/main/kotlin") } - jvmTest { - kotlin.srcDir("generated-src-jvm/test/java") + commonTest { + kotlin.srcDir("generated-src/test/kotlin") } } } From 25b8e8edbdf59046b01e524267284e9606c69ce3 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 24 Sep 2024 09:39:58 -0400 Subject: [PATCH 27/41] Self nits --- .gitignore | 4 ++-- settings.gradle.kts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 45b192f3d25..c6ae9dc5eb6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,11 +12,11 @@ build/ .idea/ __pycache__/ local.properties -.kotest/ -*.klib # ignore generated files services/*/generated-src services/*/build.gradle.kts +.kotest/ +*.klib tests/codegen/smoke-tests/services/*/generated-src tests/codegen/smoke-tests/services/*/build.gradle.kts \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 2098033de24..2d6c4831ac5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -59,7 +59,7 @@ file("services").listFiles().forEach { } } -// generated services by smoke tests - test suite +// generated services by smoke tests test suite file("tests/codegen/smoke-tests/services").listFiles().forEach { if (it.isServiceDir) { include(":tests:codegen:smoke-tests:services:${it.name}") From 8aae6e4094d39f7a1da5424f1b42ca12ab99eb0c Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 24 Sep 2024 10:12:54 -0400 Subject: [PATCH 28/41] Use new runtime function for env vars --- .../smoketests/SmokeTestsCodegenRegionIntegration.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt index 5404637c1f1..cc84a239e78 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt @@ -1,6 +1,7 @@ package aws.sdk.kotlin.codegen.smoketests import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding @@ -27,7 +28,11 @@ class SmokeTestsCodegenRegionIntegration : KotlinIntegration { ) private val envVars = SectionWriter { writer, _ -> - writer.write("private val regionOverride = System.getenv(#S)", "AWS_SMOKE_TEST_REGION") + writer.write( + "private val regionOverride = #T(#S)", + RuntimeTypes.Core.SmokeTests.getEnv, + "AWS_SMOKE_TEST_REGION", + ) } private val region = SectionWriter { writer, _ -> From 5687f7ed71ba7759f190a87c2947153c161df250 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 24 Sep 2024 23:57:52 -0400 Subject: [PATCH 29/41] Cleanup, Clarity changes to test code in src --- .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 8 ++++---- .../model/traits/{ => testing}/SmokeTestTraits.kt | 10 +++++++--- .../SmokeTestsCodegenRegionIntegration.kt | 6 +++--- .../SmokeTestFailHttpEngineIntegration.kt | 15 ++++++++------- .../SmokeTestSuccessHttpEngineIntegration.kt | 15 ++++++++------- ...y.kotlin.codegen.integration.KotlinIntegration | 4 ++-- 6 files changed, 32 insertions(+), 26 deletions(-) rename codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/{ => testing}/SmokeTestTraits.kt (52%) rename codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/{ => testing}/SmokeTestFailHttpEngineIntegration.kt (81%) rename codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/{ => testing}/SmokeTestSuccessHttpEngineIntegration.kt (75%) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index 32606ea2460..bdd10d2b459 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -4,8 +4,8 @@ */ package aws.sdk.kotlin.codegen -import aws.sdk.kotlin.codegen.model.traits.FailedResponseTrait -import aws.sdk.kotlin.codegen.model.traits.SuccessResponseTrait +import aws.sdk.kotlin.codegen.model.traits.testing.TestFailedResponseTrait +import aws.sdk.kotlin.codegen.model.traits.testing.TestSuccessResponseTrait import aws.sdk.kotlin.codegen.smoketests.smokeTestDenyList import software.amazon.smithy.kotlin.codegen.core.* import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -119,8 +119,8 @@ class GradleGenerator : KotlinIntegration { * Generates a gradle task to run smoke tests */ private fun generateSmokeTestTask(writer: GradleWriter, ctx: CodegenContext) { - val hasSuccessResponseTrait = ctx.model.expectShape(ctx.settings.service).hasTrait(SuccessResponseTrait.ID) - val hasFailedResponseTrait = ctx.model.expectShape(ctx.settings.service).hasTrait(FailedResponseTrait.ID) + val hasSuccessResponseTrait = ctx.model.expectShape(ctx.settings.service).hasTrait(TestSuccessResponseTrait.ID) + val hasFailedResponseTrait = ctx.model.expectShape(ctx.settings.service).hasTrait(TestFailedResponseTrait.ID) val inTestingEnvironment = hasFailedResponseTrait || hasSuccessResponseTrait /** diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/SmokeTestTraits.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/testing/SmokeTestTraits.kt similarity index 52% rename from codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/SmokeTestTraits.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/testing/SmokeTestTraits.kt index 9a115357629..6805c3bad1f 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/SmokeTestTraits.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/testing/SmokeTestTraits.kt @@ -1,4 +1,4 @@ -package aws.sdk.kotlin.codegen.model.traits +package aws.sdk.kotlin.codegen.model.traits.testing import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.shapes.ShapeId @@ -6,8 +6,10 @@ import software.amazon.smithy.model.traits.AnnotationTrait /** * Indicates the annotated service should always return a failed response. + * IMPORTANT: This trait is intended for use in integration or E2E tests only, not in real-life smoke tests that run + * against a service endpoint. */ -class FailedResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) { +class TestFailedResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) { companion object { val ID: ShapeId = ShapeId.from("smithy.kotlin.traits#failedResponseTrait") } @@ -15,8 +17,10 @@ class FailedResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) { /** * Indicates the annotated service should always return a success response. + * IMPORTANT: This trait is intended for use in integration or E2E tests only, not in real-life smoke tests that run + * against a service endpoint. */ -class SuccessResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) { +class TestSuccessResponseTrait(node: ObjectNode) : AnnotationTrait(ID, node) { companion object { val ID: ShapeId = ShapeId.from("smithy.kotlin.traits#successResponseTrait") } diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt index cc84a239e78..a974d3ea914 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt @@ -18,7 +18,7 @@ import software.amazon.smithy.smoketests.traits.SmokeTestsTrait */ class SmokeTestsCodegenRegionIntegration : KotlinIntegration { override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = - model.topDownOperations(settings.service).any { it.hasTrait() } && settings.sdkId !in smokeTestDenyList + model.topDownOperations(settings.service).any { it.hasTrait() } override val sectionWriters: List get() = listOf( @@ -29,8 +29,8 @@ class SmokeTestsCodegenRegionIntegration : KotlinIntegration { private val envVars = SectionWriter { writer, _ -> writer.write( - "private val regionOverride = #T(#S)", - RuntimeTypes.Core.SmokeTests.getEnv, + "private val regionOverride = #T.System.getenv(#S)", + RuntimeTypes.Core.Utils.PlatformProvider, "AWS_SMOKE_TEST_REGION", ) } diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt similarity index 81% rename from codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt index cc3a11bc18e..43e5087f6be 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestFailHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt @@ -1,7 +1,7 @@ -package aws.sdk.kotlin.codegen.smoketests +package aws.sdk.kotlin.codegen.smoketests.testing -import aws.sdk.kotlin.codegen.model.traits.FailedResponseTrait -import aws.sdk.kotlin.codegen.model.traits.SuccessResponseTrait +import aws.sdk.kotlin.codegen.model.traits.testing.TestFailedResponseTrait +import aws.sdk.kotlin.codegen.model.traits.testing.TestSuccessResponseTrait import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.core.withBlock @@ -17,14 +17,15 @@ import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.smoketests.traits.SmokeTestsTrait /** - * Adds [FailedResponseTrait] support to smoke tests + * Adds [TestFailedResponseTrait] support to smoke tests + * IMPORTANT: This integration is intended for use in integration or E2E tests only, not in real-life smoke tests that run + * against a service endpoint. */ class SmokeTestFailHttpEngineIntegration : KotlinIntegration { override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = model.topDownOperations(settings.service).any { it.hasTrait() } && - settings.sdkId !in smokeTestDenyList && - !model.expectShape(settings.service).hasTrait(SuccessResponseTrait.ID) && - model.expectShape(settings.service).hasTrait(FailedResponseTrait.ID) + !model.expectShape(settings.service).hasTrait(TestSuccessResponseTrait.ID) && + model.expectShape(settings.service).hasTrait(TestFailedResponseTrait.ID) override val sectionWriters: List get() = listOf( diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt similarity index 75% rename from codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt index 296fe4f4564..db7b52f013b 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestSuccessHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt @@ -1,7 +1,7 @@ -package aws.sdk.kotlin.codegen.smoketests +package aws.sdk.kotlin.codegen.smoketests.testing -import aws.sdk.kotlin.codegen.model.traits.FailedResponseTrait -import aws.sdk.kotlin.codegen.model.traits.SuccessResponseTrait +import aws.sdk.kotlin.codegen.model.traits.testing.TestFailedResponseTrait +import aws.sdk.kotlin.codegen.model.traits.testing.TestSuccessResponseTrait import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -16,14 +16,15 @@ import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.smoketests.traits.SmokeTestsTrait /** - * Adds [SuccessResponseTrait] support to smoke tests + * Adds [TestSuccessResponseTrait] support to smoke tests + * IMPORTANT: This integration is intended for use in integration or E2E tests only, not in real-life smoke tests that run + * against a service endpoint. */ class SmokeTestSuccessHttpEngineIntegration : KotlinIntegration { override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = model.topDownOperations(settings.service).any { it.hasTrait() } && - settings.sdkId !in smokeTestDenyList && - model.expectShape(settings.service).hasTrait(SuccessResponseTrait.ID) && - !model.expectShape(settings.service).hasTrait(FailedResponseTrait.ID) + model.expectShape(settings.service).hasTrait(TestSuccessResponseTrait.ID) && + !model.expectShape(settings.service).hasTrait(TestFailedResponseTrait.ID) override val sectionWriters: List get() = listOf( diff --git a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration index 83ca84b7f2f..ad056abf01d 100644 --- a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +++ b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -45,5 +45,5 @@ aws.sdk.kotlin.codegen.customization.s3.S3ExpiresIntegration aws.sdk.kotlin.codegen.BusinessMetricsIntegration aws.sdk.kotlin.codegen.smoketests.SmokeTestsDenyListIntegration aws.sdk.kotlin.codegen.smoketests.SmokeTestsCodegenRegionIntegration -aws.sdk.kotlin.codegen.smoketests.SmokeTestSuccessHttpEngineIntegration -aws.sdk.kotlin.codegen.smoketests.SmokeTestFailHttpEngineIntegration +aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestSuccessHttpEngineIntegration +aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestFailHttpEngineIntegration From d465c500df0c57c0effe6b03f77dc10ead7bef62 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 3 Oct 2024 09:51:38 -0400 Subject: [PATCH 30/41] Disable native for smoke test e2e tests --- tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index d27eef61583..b1804c25b88 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -43,7 +43,7 @@ private fun runSmokeTests(service: String, envVars: Map = emptyM val sdkRootDir = System.getProperty("user.dir") + "/../../../" val runner = GradleRunner.create() .withProjectDir(File(sdkRootDir)) - .withArguments(":tests:codegen:smoke-tests:services:$service:smokeTest") + .withArguments(listOf("-Paws.kotlin.native=false", ":tests:codegen:smoke-tests:services:$service:smokeTest")) .withEnvironment(envVars) .build() From 73f694a31b83acdf1e9f0ba2533b365bcf9529d7 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 4 Oct 2024 10:02:30 -0400 Subject: [PATCH 31/41] Use vararg instead of list & add FIXME to enable native builds later --- tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index b1804c25b88..df52b696150 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -43,7 +43,8 @@ private fun runSmokeTests(service: String, envVars: Map = emptyM val sdkRootDir = System.getProperty("user.dir") + "/../../../" val runner = GradleRunner.create() .withProjectDir(File(sdkRootDir)) - .withArguments(listOf("-Paws.kotlin.native=false", ":tests:codegen:smoke-tests:services:$service:smokeTest")) + // FIXME: Remove `-Paws.kotlin.native=false` when Kotlin Native is ready + .withArguments("-Paws.kotlin.native=false", ":tests:codegen:smoke-tests:services:$service:smokeTest") .withEnvironment(envVars) .build() From 578350bdeb2f8c58f202a49e259fd4d3ec83e85a Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 8 Oct 2024 10:02:40 -0400 Subject: [PATCH 32/41] Remove iot data plane from smoke test deny list --- .../kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt index 66d5196b2f3..e7de6f0119f 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt @@ -33,5 +33,4 @@ val smokeTestDenyList = setOf( "Application Auto Scaling", "SWF", "WAFV2", - "IoT Data Plane", ) From e2107d7316af8d31896d38eeddef75189fe2c5b7 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 8 Oct 2024 17:23:28 -0400 Subject: [PATCH 33/41] AWS & S3 vendor params support --- .../SmokeTestAwsVendorParamsIntegration.kt | 150 ++++++++++++++++++ .../SmokeTestsCodegenRegionIntegration.kt | 45 ------ .../SmokeTestsDenyListIntegration.kt | 2 +- ...tlin.codegen.integration.KotlinIntegration | 2 +- .../test/resources/smoke-tests-failure.smithy | 15 +- .../test/resources/smoke-tests-success.smithy | 18 ++- 6 files changed, 179 insertions(+), 53 deletions(-) create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt delete mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt new file mode 100644 index 00000000000..9f3e6a9f056 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt @@ -0,0 +1,150 @@ +package aws.sdk.kotlin.codegen.smoketests + +import aws.sdk.kotlin.codegen.AwsRuntimeTypes +import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes +import software.amazon.smithy.kotlin.codegen.core.getContextValue +import software.amazon.smithy.kotlin.codegen.core.withBlock +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding +import software.amazon.smithy.kotlin.codegen.model.hasTrait +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.* +import software.amazon.smithy.kotlin.codegen.utils.topDownOperations +import software.amazon.smithy.model.Model +import software.amazon.smithy.smoketests.traits.SmokeTestsTrait + +/** + * Adds support for AWS specific client config during smoke tests code generation. + */ +class SmokeTestAwsVendorParamsIntegration : KotlinIntegration { + override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = + model.topDownOperations(settings.service).any { it.hasTrait() } + + override val sectionWriters: List + get() = + dualStackSectionWriters + + sigv4aRegionSetSectionWriters + + uriSectionWriters + + accountIdEndpointSectionWriters + + regionSectionWriters + + useAccelerateSectionWriters + + useMultiRegionAccessPointsSectionWriters + + useGlobalEndpointSectionWriters +} + +/** + * Uses the AWS Kotlin SDK specific name for the dual stack config option i.e. `useDualstack` -> `useDualStack` + */ +private val dualStackSectionWriters = listOf( + SectionWriterBinding(SmokeTestUseDualStackKey) { writer, _ -> writer.writeInline("useDualStack") }, +) + +/** + * Uses the AWS Kotlin SDK specific name for the sigV4a signing region set option i.e. + * `sigv4aRegionSet` -> `sigV4aSigningRegionSet`. + * + * Converts the modeled sigV4a signing region set from a list to a set. + * + * Adds additional config needed for the SDK to make sigV4a calls + */ +private val sigv4aRegionSetSectionWriters = listOf( + SectionWriterBinding(SmokeTestSigv4aRegionSetKey) { writer, _ -> writer.writeInline("sigV4aSigningRegionSet") }, + SectionWriterBinding(SmokeTestSigv4aRegionSetValue) { writer, value -> + writer.write("#L.toSet()", value) + // TODO: Remove once sigV4a is supported for default signer. + writer.write( + "authSchemes = listOf(#T(#T))", + RuntimeTypes.Auth.HttpAuthAws.SigV4AsymmetricAuthScheme, + RuntimeTypes.Auth.AwsSigningCrt.CrtAwsSigner, + ) + }, +) + +/** + * Ensures we use the provided URI + */ +private val uriSectionWriters = listOf( + SectionWriterBinding(SmokeTestUriKey) { writer, _ -> writer.writeInline("endpointProvider") }, + SectionWriterBinding(SmokeTestUriValue) { writer, value -> + val endpointProvider = writer.getContextValue(SmokeTestUriValue.EndpointProvider) + val endpointParameters = writer.getContextValue(SmokeTestUriValue.EndpointParameters) + writer.withBlock("object : #T {", "}", endpointProvider) { + write( + "override suspend fun resolveEndpoint(params: #T): #T = #T(#L)", + endpointParameters, + RuntimeTypes.SmithyClient.Endpoints.Endpoint, + RuntimeTypes.SmithyClient.Endpoints.Endpoint, + value, + ) + } + }, +) + +/** + * Uses the AWS Kotlin SDK specific way of configuring `accountIdEndpointMode` + */ +private val accountIdEndpointSectionWriters = listOf( + SectionWriterBinding(SmokeTestAccountIdBasedRoutingKey) { writer, _ -> writer.writeInline("accountIdEndpointMode") }, + SectionWriterBinding(SmokeTestAccountIdBasedRoutingValue) { writer, value -> + when (value) { + "true" -> writer.write("#T.REQUIRED", AwsRuntimeTypes.Config.Endpoints.AccountIdEndpointMode) + "false" -> writer.write("#T.DISABLED", AwsRuntimeTypes.Config.Endpoints.AccountIdEndpointMode) + } + }, +) + +/** + * Gets region override environment variable. + * + * Sets region override as default. + * + * Sets region override as default client config if no other client config is modelled. + */ +private val regionSectionWriters = listOf( + SectionWriterBinding(SmokeTestAdditionalEnvVars) { writer, _ -> + writer.write( + "private val regionOverride = #T.System.getenv(#S)", + RuntimeTypes.Core.Utils.PlatformProvider, + "AWS_SMOKE_TEST_REGION", + ) + }, + SectionWriterBinding(SmokeTestRegionDefault) { writer, _ -> + writer.writeInline("regionOverride ?: ") + }, + SectionWriterBinding(SmokeTestDefaultConfig) { writer, _ -> writer.write("region = regionOverride") }, +) + +/** + * Uses the AWS Kotlin SDK specific name for the S3 accelerate config option i.e. `useAccelerate` -> `enableAccelerate` + */ +private val useAccelerateSectionWriters = listOf( + SectionWriterBinding(SmokeTestUseAccelerateKey) { writer, _ -> writer.writeInline("enableAccelerate") }, +) + +/** + * Uses the AWS Kotlin SDK specific name for the S3 multi region access points (MRAP) config option i.e. + * `useMultiRegionAccessPoints` -> `disableMrap`. + * + * Our config option is opt out while the modeled config is opt in so we invert the boolean values. + */ +private val useMultiRegionAccessPointsSectionWriters = listOf( + SectionWriterBinding(SmokeTestUseMultiRegionAccessPointsKey) { writer, _ -> writer.writeInline("disableMrap") }, + SectionWriterBinding(SmokeTestUseMultiRegionAccessPointsValue) { writer, value -> + when (value) { + "true" -> writer.write("false") + "false" -> writer.write("true") + } + }, +) + +/** + * Leaves a comment in the client config whenever the use of the `useGlobalEndpoint` S3 config option is modeled. + * + * The SDK does not support this config option. + * See `BindAwsEndpointBuiltins` & `S3_USE_GLOBAL_ENDPOINT` + */ +private val useGlobalEndpointSectionWriters = listOf( + SectionWriterBinding(SmokeTestUseGlobalEndpoint) { writer, _ -> + writer.write("// Smoke tests modeled the use of `useGlobalEndpoint` config, but it's not supported by the SDK") + }, +) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt deleted file mode 100644 index a974d3ea914..00000000000 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsCodegenRegionIntegration.kt +++ /dev/null @@ -1,45 +0,0 @@ -package aws.sdk.kotlin.codegen.smoketests - -import software.amazon.smithy.kotlin.codegen.KotlinSettings -import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes -import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration -import software.amazon.smithy.kotlin.codegen.integration.SectionWriter -import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding -import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestAdditionalEnvVars -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestDefaultConfig -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestRegionDefault -import software.amazon.smithy.kotlin.codegen.utils.topDownOperations -import software.amazon.smithy.model.Model -import software.amazon.smithy.smoketests.traits.SmokeTestsTrait - -/** - * Adds AWS region support to smoke tests - */ -class SmokeTestsCodegenRegionIntegration : KotlinIntegration { - override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = - model.topDownOperations(settings.service).any { it.hasTrait() } - - override val sectionWriters: List - get() = listOf( - SectionWriterBinding(SmokeTestAdditionalEnvVars, envVars), - SectionWriterBinding(SmokeTestDefaultConfig, region), - SectionWriterBinding(SmokeTestRegionDefault, regionDefault), - ) - - private val envVars = SectionWriter { writer, _ -> - writer.write( - "private val regionOverride = #T.System.getenv(#S)", - RuntimeTypes.Core.Utils.PlatformProvider, - "AWS_SMOKE_TEST_REGION", - ) - } - - private val region = SectionWriter { writer, _ -> - writer.write("region = regionOverride") - } - - private val regionDefault = SectionWriter { writer, _ -> - writer.write("regionOverride ?:") - } -} diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt index e7de6f0119f..620b096b111 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt @@ -22,7 +22,7 @@ class SmokeTestsDenyListIntegration : KotlinIntegration { ) private val smokeTestDenyListSectionWriter = SectionWriter { writer, _ -> - writer.write("// Smoke tests for service deny listed until model is fixed") + writer.write("// Smoke tests for service deny listed") } } diff --git a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration index ad056abf01d..26302b6d691 100644 --- a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +++ b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -44,6 +44,6 @@ aws.sdk.kotlin.codegen.customization.s3.express.S3ExpressIntegration aws.sdk.kotlin.codegen.customization.s3.S3ExpiresIntegration aws.sdk.kotlin.codegen.BusinessMetricsIntegration aws.sdk.kotlin.codegen.smoketests.SmokeTestsDenyListIntegration -aws.sdk.kotlin.codegen.smoketests.SmokeTestsCodegenRegionIntegration +aws.sdk.kotlin.codegen.smoketests.SmokeTestAwsVendorParamsIntegration aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestSuccessHttpEngineIntegration aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestFailHttpEngineIntegration diff --git a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy index 0a903a77303..05f1b8563dc 100644 --- a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy +++ b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-failure.smithy @@ -41,6 +41,9 @@ service FailureService { vendorParamsShape: AwsVendorParams, vendorParams: { region: "eu-central-1" + uri: "https://failure.amazonaws.com" + useFips: false + useDualstack: false } } ] @@ -57,6 +60,12 @@ operation TestOperation { @error("client") structure InvalidMessageError {} -structure AwsVendorParams { - region: String -} \ No newline at end of file +@mixin +structure BaseAwsVendorParams { + region: String = "us-west-2" + uri: String + useFips: Boolean = false + useDualstack: Boolean = false +} + +structure AwsVendorParams with [BaseAwsVendorParams] {} \ No newline at end of file diff --git a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy index 45a8f425881..4f27498fc2e 100644 --- a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy +++ b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-success.smithy @@ -41,6 +41,9 @@ service SuccessService { vendorParamsShape: AwsVendorParams, vendorParams: { region: "eu-central-1" + uri: "https://success.amazonaws.com" + useFips: false + useDualstack: false } }, { @@ -55,6 +58,9 @@ service SuccessService { vendorParamsShape: AwsVendorParams, vendorParams: { region: "eu-central-1" + uri: "https://success.amazonaws.com" + useFips: false + useDualstack: false } } ] @@ -71,6 +77,12 @@ operation TestOperation { @error("client") structure InvalidMessageError {} -structure AwsVendorParams { - region: String -} \ No newline at end of file +@mixin +structure BaseAwsVendorParams { + region: String = "us-west-2" + uri: String + useFips: Boolean = false + useDualstack: Boolean = false +} + +structure AwsVendorParams with [BaseAwsVendorParams] {} From 408b3cfc998bc008f17fa7f92401b720f540c738 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 9 Oct 2024 11:04:22 -0400 Subject: [PATCH 34/41] Add test for exception logging --- tests/codegen/smoke-tests/build.gradle.kts | 1 + .../src/test/kotlin/SmokeTestE2ETest.kt | 24 +++++++-- .../resources/smoke-tests-exception.smithy | 53 +++++++++++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 tests/codegen/smoke-tests/src/test/resources/smoke-tests-exception.smithy diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index 7d082ddb9b8..1774e5dd8f4 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -17,6 +17,7 @@ plugins { val projections = listOf( Projection("successService", "smoke-tests-success.smithy", "smithy.kotlin.traits#SuccessService"), Projection("failureService", "smoke-tests-failure.smithy", "smithy.kotlin.traits#FailureService"), + Projection("exceptionService", "smoke-tests-exception.smithy", "smithy.kotlin.traits#ExceptionService"), ) configureProject() diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index df52b696150..c4ff97f4229 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -20,6 +20,16 @@ class SmokeTestE2ETest { assertContains(smokeTestRunnerOutput, "ok FailureService FailuresTest - error expected from service") } + @Test + fun exceptionService() { + val smokeTestRunnerOutput = runSmokeTests("exceptionService", expectingFailure = true) + + assertContains(smokeTestRunnerOutput, "not ok ExceptionService ExceptionTest - no error expected from service") + assertContains(smokeTestRunnerOutput, "#aws.smithy.kotlin.runtime.http.interceptors.SmokeTestsFailureException: Smoke test failed with HTTP status code: 400") + assertContains(smokeTestRunnerOutput, "#\tat aws.smithy.kotlin.runtime.http.interceptors.SmokeTestsInterceptor.readBeforeDeserialization(SmokeTestsInterceptor.kt:19)") + assertContains(smokeTestRunnerOutput, "#\tat aws.smithy.kotlin.runtime.http.interceptors.InterceptorExecutor.readBeforeDeserialization(InterceptorExecutor.kt:252)") + } + @Test fun successServiceSkipTags() { val envVars = mapOf(SKIP_TAGS to "success") @@ -39,14 +49,20 @@ class SmokeTestE2ETest { } } -private fun runSmokeTests(service: String, envVars: Map = emptyMap()): String { +private fun runSmokeTests( + service: String, + envVars: Map = emptyMap(), + expectingFailure: Boolean = false, +): String { val sdkRootDir = System.getProperty("user.dir") + "/../../../" - val runner = GradleRunner.create() + + val task = GradleRunner.create() .withProjectDir(File(sdkRootDir)) // FIXME: Remove `-Paws.kotlin.native=false` when Kotlin Native is ready .withArguments("-Paws.kotlin.native=false", ":tests:codegen:smoke-tests:services:$service:smokeTest") .withEnvironment(envVars) - .build() - return runner.output + val buildResult = if (expectingFailure) task.buildAndFail() else task.build() + + return buildResult.output } diff --git a/tests/codegen/smoke-tests/src/test/resources/smoke-tests-exception.smithy b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-exception.smithy new file mode 100644 index 00000000000..24bc4f7183b --- /dev/null +++ b/tests/codegen/smoke-tests/src/test/resources/smoke-tests-exception.smithy @@ -0,0 +1,53 @@ +$version: "2" +namespace smithy.kotlin.traits + +use aws.protocols#awsJson1_0 +use aws.api#service +use smithy.test#smokeTests +use smithy.rules#endpointRuleSet + +@trait(selector: "service") +structure failedResponseTrait { } + +@failedResponseTrait +@awsJson1_0 +@service(sdkId: "Exception") +@endpointRuleSet( + version: "1.0", + parameters: {}, + rules: [ + { + "type": "endpoint", + "conditions": [], + "endpoint": { + "url": "https://static.endpoint" + } + } + ] +) +service ExceptionService { + version: "1.0.0", + operations: [ TestOperation ], +} + +@smokeTests( + [ + { + id: "ExceptionTest" + expect: { + success: {} + } + } + ] +) +operation TestOperation { + input := { + bar: String + } + errors: [ + InvalidMessageError + ] +} + +@error("client") +structure InvalidMessageError {} From ca2fa0252c154745e8dbf5017e42e33a9eed2a7a Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 30 Oct 2024 11:07:40 -0400 Subject: [PATCH 35/41] Checkpoint for smoke tests code generation bug fixes --- .../SmokeTestAwsVendorParamsIntegration.kt | 82 ++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt index 9f3e6a9f056..3613215e6ab 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt @@ -9,12 +9,19 @@ import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.hasTrait import software.amazon.smithy.kotlin.codegen.rendering.smoketests.* +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.Param.ParamName +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.Param.ParamShape +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.Param.Parameter +import software.amazon.smithy.kotlin.codegen.rendering.util.format +import software.amazon.smithy.kotlin.codegen.utils.dq import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model +import software.amazon.smithy.model.node.* +import software.amazon.smithy.model.shapes.* import software.amazon.smithy.smoketests.traits.SmokeTestsTrait /** - * Adds support for AWS specific client config during smoke tests code generation. + * Adds support for AWS specific client config and custom code generation to smoke tests. */ class SmokeTestAwsVendorParamsIntegration : KotlinIntegration { override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = @@ -29,9 +36,80 @@ class SmokeTestAwsVendorParamsIntegration : KotlinIntegration { regionSectionWriters + useAccelerateSectionWriters + useMultiRegionAccessPointsSectionWriters + - useGlobalEndpointSectionWriters + useGlobalEndpointSectionWriters + + listOf(parameterGenerator) // TODO: Convert this so that all can be placed here in this list } +/** + * TODO: Write + */ +private val parameterGenerator = + SectionWriterBinding(Param) { writer, _ -> + val paramName = writer.getContextValue(ParamName) + val parameter = writer.getContextValue(Parameter) + val shape = writer.getContextValue(ParamShape) + + writer.write("#L", coerceParameterToModeledShape(parameter, shape, paramName)) + } + +fun coerceParameterToModeledShape(param: Node, customShape: Shape?, name: String): String { + if (customShape == null) return param.format() + + // TODO: Fill this out + + // TODO: Which ones need customization and which ones can I delegate down to `format` ? + when (customShape) { + is BigDecimalShape -> { + if (param !is NumberNode) + } + is BigIntegerShape -> {} + is BlobShape -> {} + is BooleanShape -> {} + is ByteShape -> {} + is ListShape -> {} + is CollectionShape -> {} + is DocumentShape -> {} + is DoubleShape -> {} + is EntityShape -> {} // ?? + is EnumShape -> {} + is FloatShape -> {} + is IntEnumShape -> {} + is IntegerShape -> {} + is LongShape -> {} + is MapShape -> {} + is MemberShape -> {} + is NumberShape -> {} + is SetShape -> {} + is ShortShape -> {} + is StringShape -> {} + is TimestampShape -> {} + is UnionShape -> {} + else -> throw Exception("Code generation unsupported for smoke test operation parameter '$name' of type '$customShape'.") + } + + // TODO: Remove. This is here for reference only. + when (param) { + is NullNode -> "null" + is StringNode -> value.dq() + is BooleanNode -> value.toString() + is NumberNode -> value.toString() + is ArrayNode -> elements.joinToString(",", "listOf(", ")") { element -> + element.format() + } + is ObjectNode -> stringMap.entries.joinToString(", ", "mapOf(", ")") { (key, value) -> + "${key.dq()} to ${value.format()}" + } + else -> throw Exception("Unexpected node type: $this") + } + + return "" +} + + + + + + /** * Uses the AWS Kotlin SDK specific name for the dual stack config option i.e. `useDualstack` -> `useDualStack` */ From ea40b9b1a0e27a88f31b6ff884d4f3b43cd9a75c Mon Sep 17 00:00:00 2001 From: 0marperez Date: Fri, 1 Nov 2024 10:37:51 -0400 Subject: [PATCH 36/41] Checkpoint --- .../smoketests/SmokeTestAwsVendorParamsIntegration.kt | 6 ++++-- settings.gradle.kts | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt index b2b94b353d8..e1dc7709a19 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt @@ -69,9 +69,11 @@ fun coerceParameterToModeledShape( symbolProvider: SymbolProvider ) { if (customShape == null || customShape.isCompatibleWithNodeTypes) { - writer.write("#L", param.format()) + writer.writeInline("#L", param.format()) } + if (customShape != null) writer.write("// ${customShape::class.simpleName}") + when (customShape) { is DocumentShape -> {} // TODO: Unknown ! is BlobShape -> {} // TODO: Unknown ! @@ -84,7 +86,7 @@ fun coerceParameterToModeledShape( is MemberShape -> {} // TODO: Important ! is TimestampShape -> {} // TODO: Unknown ! is UnionShape -> {} // TODO: Important ! - else -> throw Exception("Code generation unsupported for smoke test operation parameter '$name' of type '$customShape'.") +// else -> throw Exception("Code generation unsupported for smoke test operation parameter '$name' of type '$customShape'.") } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 7ce2c75cdd8..fa43e4d2789 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -75,6 +75,7 @@ file("tests/codegen/smoke-tests/services").listFiles().forEach { if (it.isServiceDir) { include(":tests:codegen:smoke-tests:services:${it.name}") } +} if ("dynamodb".isBootstrappedService) { include(":hll:dynamodb-mapper") From c9d266f7b5ddd571db6ec9e41d16fecb7fe86298 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 5 Nov 2024 00:45:54 -0500 Subject: [PATCH 37/41] PR feedback --- .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 3 +- .../SmokeTestAwsVendorParamsIntegration.kt | 316 +++++++----------- .../SmokeTestsDenyListIntegration.kt | 36 -- .../SmokeTestFailHttpEngineIntegration.kt | 4 +- .../SmokeTestSuccessHttpEngineIntegration.kt | 4 +- ...tlin.codegen.integration.KotlinIntegration | 1 - tests/codegen/smoke-tests/build.gradle.kts | 1 + .../src/test/kotlin/SmokeTestE2ETest.kt | 8 +- 8 files changed, 132 insertions(+), 241 deletions(-) delete mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt index bdd10d2b459..f590cf1a790 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt @@ -6,7 +6,6 @@ package aws.sdk.kotlin.codegen import aws.sdk.kotlin.codegen.model.traits.testing.TestFailedResponseTrait import aws.sdk.kotlin.codegen.model.traits.testing.TestSuccessResponseTrait -import aws.sdk.kotlin.codegen.smoketests.smokeTestDenyList import software.amazon.smithy.kotlin.codegen.core.* import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.model.expectShape @@ -72,7 +71,7 @@ class GradleGenerator : KotlinIntegration { } } } - if (ctx.model.topDownOperations(ctx.settings.service).any { it.hasTrait() } && ctx.settings.sdkId !in smokeTestDenyList) { + if (ctx.model.topDownOperations(ctx.settings.service).any { it.hasTrait() }) { write("") generateSmokeTestConfig(writer, ctx) } diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt index e1dc7709a19..3419cdc00a7 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt @@ -1,232 +1,160 @@ package aws.sdk.kotlin.codegen.smoketests import aws.sdk.kotlin.codegen.AwsRuntimeTypes -import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.kotlin.codegen.KotlinSettings -import software.amazon.smithy.kotlin.codegen.core.* +import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes +import software.amazon.smithy.kotlin.codegen.core.getContextValue +import software.amazon.smithy.kotlin.codegen.core.withBlock import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration -import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.hasTrait import software.amazon.smithy.kotlin.codegen.rendering.smoketests.* -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.Param.ParamName -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.Param.ParamShape -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.Param.Parameter -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.Param.SymbolProvider -import software.amazon.smithy.kotlin.codegen.rendering.util.format -import software.amazon.smithy.kotlin.codegen.utils.dq import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model -import software.amazon.smithy.model.node.* -import software.amazon.smithy.model.shapes.* import software.amazon.smithy.smoketests.traits.SmokeTestsTrait /** - * Code generates AWS specific code for smoke test runners + * Generates AWS specific code for smoke test runners */ class AwsSmokeTestsRunnerGeneratorIntegration : KotlinIntegration { override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = model.topDownOperations(settings.service).any { it.hasTrait() } override val sectionWriters: List - get() = - dualStackSectionWriters + - sigv4aRegionSetSectionWriters + - uriSectionWriters + - accountIdEndpointSectionWriters + - regionSectionWriters + - useAccelerateSectionWriters + - useMultiRegionAccessPointsSectionWriters + - useGlobalEndpointSectionWriters + - listOf(parameterGenerator) // TODO: Convert this so that all can be placed here in this list -} - -/** - * TODO: Write - */ -private val parameterGenerator = - SectionWriterBinding(Param) { writer, _ -> - val paramName = writer.getContextValue(ParamName) - val parameter = writer.getContextValue(Parameter) - val shape = writer.getContextValue(ParamShape) - - val symbolProvider = writer.getContextValue(SymbolProvider) - - coerceParameterToModeledShape( - parameter, - shape, - paramName, - writer, - symbolProvider, + get() = listOf( + AwsSmokeTestsRunnerGenerator.regionEnvironmentVariable, + AwsSmokeTestsRunnerGenerator.clientConfig, + AwsSmokeTestsRunnerGenerator.defaultClientConfig, + AwsSmokeTestsRunnerGenerator.skipTagsEnvironmentVariable, + AwsSmokeTestsRunnerGenerator.serviceFilterEnvironmentVariable, ) - } - -fun coerceParameterToModeledShape( - param: Node, - customShape: Shape?, - name: String, - writer: KotlinWriter, - symbolProvider: SymbolProvider -) { - if (customShape == null || customShape.isCompatibleWithNodeTypes) { - writer.writeInline("#L", param.format()) - } - - if (customShape != null) writer.write("// ${customShape::class.simpleName}") - - when (customShape) { - is DocumentShape -> {} // TODO: Unknown ! - is BlobShape -> {} // TODO: Unknown ! - is EnumShape -> { - val enumSymbol = symbolProvider.toSymbol(customShape) - val enumValue = param.asStringNode().get().value - - writer.write("#T.#L", enumSymbol, enumValue) - } - is MemberShape -> {} // TODO: Important ! - is TimestampShape -> {} // TODO: Unknown ! - is UnionShape -> {} // TODO: Important ! -// else -> throw Exception("Code generation unsupported for smoke test operation parameter '$name' of type '$customShape'.") - } } -private val Shape.isCompatibleWithNodeTypes: Boolean - get() = when (this) { - is NumberShape, // TODO: Maybe not all numbers are okay? - is MapShape, - is StringShape, - is BooleanShape, // TODO: One of these can actually be an enum..... - is CollectionShape -> true - - else -> false - } - - - - - - - - - - - - - - /** - * Uses the AWS Kotlin SDK specific name for the dual stack config option i.e. `useDualstack` -> `useDualStack` + * The section writer bindings used by [AwsSmokeTestsRunnerGeneratorIntegration] */ -private val dualStackSectionWriters = listOf( - SectionWriterBinding(SmokeTestUseDualStackKey) { writer, _ -> writer.writeInline("useDualStack") }, -) - -/** - * Uses the AWS Kotlin SDK specific name for the sigV4a signing region set option i.e. - * `sigv4aRegionSet` -> `sigV4aSigningRegionSet`. - * - * Converts the modeled sigV4a signing region set from a list to a set. - * - * Adds additional config needed for the SDK to make sigV4a calls - */ -private val sigv4aRegionSetSectionWriters = listOf( - SectionWriterBinding(SmokeTestSigv4aRegionSetKey) { writer, _ -> writer.writeInline("sigV4aSigningRegionSet") }, - SectionWriterBinding(SmokeTestSigv4aRegionSetValue) { writer, value -> - writer.write("#L.toSet()", value) - // TODO: Remove once sigV4a is supported for default signer. - writer.write( - "authSchemes = listOf(#T(#T))", - RuntimeTypes.Auth.HttpAuthAws.SigV4AsymmetricAuthScheme, - RuntimeTypes.Auth.AwsSigningCrt.CrtAwsSigner, - ) - }, -) - -/** - * Ensures we use the provided URI - */ -private val uriSectionWriters = listOf( - SectionWriterBinding(SmokeTestUriKey) { writer, _ -> writer.writeInline("endpointProvider") }, - SectionWriterBinding(SmokeTestUriValue) { writer, value -> - val endpointProvider = writer.getContextValue(SmokeTestUriValue.EndpointProvider) - val endpointParameters = writer.getContextValue(SmokeTestUriValue.EndpointParameters) - writer.withBlock("object : #T {", "}", endpointProvider) { - write( - "override suspend fun resolveEndpoint(params: #T): #T = #T(#L)", - endpointParameters, - RuntimeTypes.SmithyClient.Endpoints.Endpoint, - RuntimeTypes.SmithyClient.Endpoints.Endpoint, - value, +private object AwsSmokeTestsRunnerGenerator { + /** + * Adds region environment variable support to AWS smoke test runners. + * Preserves other environment variables added via section writer binding, if any. + */ + val regionEnvironmentVariable = + SectionWriterBinding(SmokeTestsRunnerGenerator.AdditionalEnvironmentVariables) { writer, previous -> + writer.write("#L", previous) + writer.write( + "private val regionOverride = #T.System.getenv(#S)", + RuntimeTypes.Core.Utils.PlatformProvider, + AWS_REGION, ) } - }, -) -/** - * Uses the AWS Kotlin SDK specific way of configuring `accountIdEndpointMode` - */ -private val accountIdEndpointSectionWriters = listOf( - SectionWriterBinding(SmokeTestAccountIdBasedRoutingKey) { writer, _ -> writer.writeInline("accountIdEndpointMode") }, - SectionWriterBinding(SmokeTestAccountIdBasedRoutingValue) { writer, value -> - when (value) { - "true" -> writer.write("#T.REQUIRED", AwsRuntimeTypes.Config.Endpoints.AccountIdEndpointMode) - "false" -> writer.write("#T.DISABLED", AwsRuntimeTypes.Config.Endpoints.AccountIdEndpointMode) + /** + * Add AWS specific client config support to AWS smoke test runners + */ + val clientConfig = + SectionWriterBinding(SmokeTestsRunnerGenerator.ClientConfig) { writer, _ -> + val name = writer.getContextValue(SmokeTestsRunnerGenerator.ClientConfig.Name) + val value = writer.getContextValue(SmokeTestsRunnerGenerator.ClientConfig.Value) + + // Normalize client config names + val newName = when (name) { + "uri" -> "endpointProvider" + "useDualstack" -> "useDualStack" + "sigv4aRegionSet" -> "sigV4aSigningRegionSet" + "useAccountIdRouting" -> "accountIdEndpointMode" + "useAccelerate" -> "enableAccelerate" + "useMultiRegionAccessPoints" -> "disableMrap" + "useGlobalEndpoint" -> { + writer.write("throw Exception(#S)", "'useGlobalEndpoint' is not supported by the SDK") + return@SectionWriterBinding + } + else -> name + } + writer.writeInline("#L = ", newName) + + // Normalize client values + when (newName) { + "endpointProvider" -> { + val endpointProvider = writer.getContextValue(SmokeTestsRunnerGenerator.ClientConfig.EndpointProvider) + val endpointParameters = writer.getContextValue(SmokeTestsRunnerGenerator.ClientConfig.EndpointParams) + + writer.withBlock("object : #T {", "}", endpointProvider) { + write( + "override suspend fun resolveEndpoint(params: #1T): #2T = #2T(#3L)", + endpointParameters, + RuntimeTypes.SmithyClient.Endpoints.Endpoint, + value, + ) + } + } + "sigV4aSigningRegionSet" -> { + // Render new value + writer.write("#L.toSet()", value) + // Also configure sigV4a - TODO: Remove once sigV4a is supported for default signer. + writer.write( + "authSchemes = listOf(#T(#T))", + RuntimeTypes.Auth.HttpAuthAws.SigV4AsymmetricAuthScheme, + RuntimeTypes.Auth.AwsSigningCrt.CrtAwsSigner, + ) + } + "accountIdEndpointMode" -> { + when (value) { + "true" -> writer.write("#T.REQUIRED", AwsRuntimeTypes.Config.Endpoints.AccountIdEndpointMode) + "false" -> writer.write("#T.DISABLED", AwsRuntimeTypes.Config.Endpoints.AccountIdEndpointMode) + } + } + "disableMrap" -> { + when (value) { + "true" -> writer.write("false") + "false" -> writer.write("true") + } + } + "region" -> { + writer.write("regionOverride ?: #L", value) + } + else -> writer.write("#L", value) + } } - }, -) -/** - * Gets region override environment variable. - * - * Sets region override as default. - * - * Sets region override as default client config if no other client config is modelled. - */ -private val regionSectionWriters = listOf( - SectionWriterBinding(SmokeTestAdditionalEnvVars) { writer, _ -> - writer.write( - "private val regionOverride = #T.System.getenv(#S)", - RuntimeTypes.Core.Utils.PlatformProvider, - "AWS_SMOKE_TEST_REGION", - ) - }, - SectionWriterBinding(SmokeTestRegionDefault) { writer, _ -> - writer.writeInline("regionOverride ?: ") - }, - SectionWriterBinding(SmokeTestDefaultConfig) { writer, _ -> writer.write("region = regionOverride") }, -) + /** + * Add default client config to AWS smoke test runners. + * Preserves previous default config if any. + */ + val defaultClientConfig = + SectionWriterBinding(SmokeTestsRunnerGenerator.DefaultClientConfig) { writer, previous -> + writer.write("#L", previous) + writer.write("region = regionOverride") + } + + /** + * Replaces environment variable with one specific to AWS smoke test runners + */ + val skipTagsEnvironmentVariable = + SectionWriterBinding(SmokeTestsRunnerGenerator.SkipTags) { writer, _ -> writer.writeInline("#S", AWS_SKIP_TAGS) } + + /** + * Replaces environment variable with one specific to AWS smoke test runners + */ + val serviceFilterEnvironmentVariable = + SectionWriterBinding(SmokeTestsRunnerGenerator.ServiceFilter) { writer, _ -> writer.writeInline("#S", AWS_SERVICE_FILTER) } +} /** - * Uses the AWS Kotlin SDK specific name for the S3 accelerate config option i.e. `useAccelerate` -> `enableAccelerate` + * Env var for AWS smoke test runners. + * Should be a string that corresponds to an AWS region. + * The region to use when executing smoke tests. This value MUST override any value supplied in the smoke tests themselves. */ -private val useAccelerateSectionWriters = listOf( - SectionWriterBinding(SmokeTestUseAccelerateKey) { writer, _ -> writer.writeInline("enableAccelerate") }, -) +private const val AWS_REGION = "AWS_SMOKE_TEST_REGION" /** - * Uses the AWS Kotlin SDK specific name for the S3 multi region access points (MRAP) config option i.e. - * `useMultiRegionAccessPoints` -> `disableMrap`. - * - * Our config option is opt out while the modeled config is opt in so we invert the boolean values. + * Env var for AWS smoke test runners. + * Should be a comma-delimited list of strings that correspond to tags on the test cases. + * If a test case is tagged with one of the tags indicated by AWS_SMOKE_TEST_SKIP_TAGS, it MUST be skipped by the smoke test runner. */ -private val useMultiRegionAccessPointsSectionWriters = listOf( - SectionWriterBinding(SmokeTestUseMultiRegionAccessPointsKey) { writer, _ -> writer.writeInline("disableMrap") }, - SectionWriterBinding(SmokeTestUseMultiRegionAccessPointsValue) { writer, value -> - when (value) { - "true" -> writer.write("false") - "false" -> writer.write("true") - } - }, -) +const val AWS_SKIP_TAGS = "AWS_SMOKE_TEST_SKIP_TAGS" /** - * Leaves a comment in the client config whenever the use of the `useGlobalEndpoint` S3 config option is modeled. - * - * The SDK does not support this config option. - * See `BindAwsEndpointBuiltins` & `S3_USE_GLOBAL_ENDPOINT` + * Env var for AWS smoke test runners. + * Should be a comma-separated list of service identifiers to test. */ -private val useGlobalEndpointSectionWriters = listOf( - SectionWriterBinding(SmokeTestUseGlobalEndpoint) { writer, _ -> - writer.write("// Smoke tests modeled the use of `useGlobalEndpoint` config, but it's not supported by the SDK") - }, -) +const val AWS_SERVICE_FILTER = "AWS_SMOKE_TEST_SERVICE_IDS" diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt deleted file mode 100644 index 620b096b111..00000000000 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestsDenyListIntegration.kt +++ /dev/null @@ -1,36 +0,0 @@ -package aws.sdk.kotlin.codegen.smoketests - -import software.amazon.smithy.kotlin.codegen.KotlinSettings -import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration -import software.amazon.smithy.kotlin.codegen.integration.SectionWriter -import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunner -import software.amazon.smithy.model.Model - -/** - * Will wipe the smoke test runner file for services that are deny listed. - * - * Some services model smoke tests incorrectly and the code generated file will not compile. - */ -class SmokeTestsDenyListIntegration : KotlinIntegration { - override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = - settings.sdkId in smokeTestDenyList - - override val sectionWriters: List - get() = listOf( - SectionWriterBinding(SmokeTestsRunner, smokeTestDenyListSectionWriter), - ) - - private val smokeTestDenyListSectionWriter = SectionWriter { writer, _ -> - writer.write("// Smoke tests for service deny listed") - } -} - -/** - * SDK ID's of services that model smoke tests incorrectly - */ -val smokeTestDenyList = setOf( - "Application Auto Scaling", - "SWF", - "WAFV2", -) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt index 43e5087f6be..e8a83fdc851 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt @@ -10,7 +10,7 @@ import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestHttpEngineOverride +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunnerGenerator.HttpEngineOverride import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -29,7 +29,7 @@ class SmokeTestFailHttpEngineIntegration : KotlinIntegration { override val sectionWriters: List get() = listOf( - SectionWriterBinding(SmokeTestHttpEngineOverride, httpClientOverride), + SectionWriterBinding(HttpEngineOverride, httpClientOverride), ) private val httpClientOverride = SectionWriter { writer, _ -> diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt index db7b52f013b..265f7c1c65a 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt @@ -9,7 +9,7 @@ import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestHttpEngineOverride +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunnerGenerator.HttpEngineOverride import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -28,7 +28,7 @@ class SmokeTestSuccessHttpEngineIntegration : KotlinIntegration { override val sectionWriters: List get() = listOf( - SectionWriterBinding(SmokeTestHttpEngineOverride, httpClientOverride), + SectionWriterBinding(HttpEngineOverride, httpClientOverride), ) private val httpClientOverride = SectionWriter { writer, _ -> diff --git a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration index 6c2ceffeb72..de1ab6cd4ac 100644 --- a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +++ b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -42,7 +42,6 @@ aws.sdk.kotlin.codegen.customization.s3.express.SigV4S3ExpressAuthSchemeIntegrat aws.sdk.kotlin.codegen.customization.s3.express.S3ExpressIntegration aws.sdk.kotlin.codegen.customization.s3.S3ExpiresIntegration aws.sdk.kotlin.codegen.BusinessMetricsIntegration -aws.sdk.kotlin.codegen.smoketests.SmokeTestsDenyListIntegration aws.sdk.kotlin.codegen.smoketests.AwsSmokeTestsRunnerGeneratorIntegration aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestSuccessHttpEngineIntegration aws.sdk.kotlin.codegen.smoketests.testing.SmokeTestFailHttpEngineIntegration diff --git a/tests/codegen/smoke-tests/build.gradle.kts b/tests/codegen/smoke-tests/build.gradle.kts index 1774e5dd8f4..77a74afceba 100644 --- a/tests/codegen/smoke-tests/build.gradle.kts +++ b/tests/codegen/smoke-tests/build.gradle.kts @@ -32,6 +32,7 @@ fun configureProject() { codegen(libs.smithy.cli) codegen(libs.smithy.model) + implementation(project(":codegen:aws-sdk-codegen")) implementation(libs.smithy.kotlin.codegen) testImplementation(libs.kotlin.test) diff --git a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt index c4ff97f4229..61f38fe62c1 100644 --- a/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt +++ b/tests/codegen/smoke-tests/src/test/kotlin/SmokeTestE2ETest.kt @@ -1,6 +1,6 @@ +import aws.sdk.kotlin.codegen.smoketests.AWS_SERVICE_FILTER +import aws.sdk.kotlin.codegen.smoketests.AWS_SKIP_TAGS import org.gradle.testkit.runner.GradleRunner -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SERVICE_FILTER -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SKIP_TAGS import java.io.File import kotlin.test.* @@ -32,7 +32,7 @@ class SmokeTestE2ETest { @Test fun successServiceSkipTags() { - val envVars = mapOf(SKIP_TAGS to "success") + val envVars = mapOf(AWS_SKIP_TAGS to "success") val smokeTestRunnerOutput = runSmokeTests("successService", envVars) assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service") @@ -41,7 +41,7 @@ class SmokeTestE2ETest { @Test fun successServiceServiceFilter() { - val envVars = mapOf(SERVICE_FILTER to "Failure") // Only run tests for services with this SDK ID + val envVars = mapOf(AWS_SERVICE_FILTER to "Failure") // Only run tests for services with this SDK ID val smokeTestRunnerOutput = runSmokeTests("successService", envVars) assertContains(smokeTestRunnerOutput, "ok SuccessService SuccessTest - no error expected from service # skip") From dc5c1144e7bc0f305ce67afc8500fdb3d1fa72bb Mon Sep 17 00:00:00 2001 From: 0marperez Date: Tue, 5 Nov 2024 12:37:28 -0500 Subject: [PATCH 38/41] File rename --- ...sIntegration.kt => AwsSmokeTestsRunnerGeneratorIntegration.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/{SmokeTestAwsVendorParamsIntegration.kt => AwsSmokeTestsRunnerGeneratorIntegration.kt} (100%) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt similarity index 100% rename from codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/SmokeTestAwsVendorParamsIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt From c6ab6293fa226e9e9ef9efcf8406ef06beff1253 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 6 Nov 2024 10:15:18 -0500 Subject: [PATCH 39/41] Track upstream PR feedback --- .../AwsSmokeTestsRunnerGeneratorIntegration.kt | 18 +++++++++--------- .../SmokeTestFailHttpEngineIntegration.kt | 2 +- .../SmokeTestSuccessHttpEngineIntegration.kt | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt index 3419cdc00a7..8e6ec43708a 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt @@ -39,7 +39,7 @@ private object AwsSmokeTestsRunnerGenerator { * Preserves other environment variables added via section writer binding, if any. */ val regionEnvironmentVariable = - SectionWriterBinding(SmokeTestsRunnerGenerator.AdditionalEnvironmentVariables) { writer, previous -> + SectionWriterBinding(AdditionalEnvironmentVariables) { writer, previous -> writer.write("#L", previous) writer.write( "private val regionOverride = #T.System.getenv(#S)", @@ -52,9 +52,9 @@ private object AwsSmokeTestsRunnerGenerator { * Add AWS specific client config support to AWS smoke test runners */ val clientConfig = - SectionWriterBinding(SmokeTestsRunnerGenerator.ClientConfig) { writer, _ -> - val name = writer.getContextValue(SmokeTestsRunnerGenerator.ClientConfig.Name) - val value = writer.getContextValue(SmokeTestsRunnerGenerator.ClientConfig.Value) + SectionWriterBinding(ClientConfig) { writer, _ -> + val name = writer.getContextValue(ClientConfig.Name) + val value = writer.getContextValue(ClientConfig.Value) // Normalize client config names val newName = when (name) { @@ -75,8 +75,8 @@ private object AwsSmokeTestsRunnerGenerator { // Normalize client values when (newName) { "endpointProvider" -> { - val endpointProvider = writer.getContextValue(SmokeTestsRunnerGenerator.ClientConfig.EndpointProvider) - val endpointParameters = writer.getContextValue(SmokeTestsRunnerGenerator.ClientConfig.EndpointParams) + val endpointProvider = writer.getContextValue(ClientConfig.EndpointProvider) + val endpointParameters = writer.getContextValue(ClientConfig.EndpointParams) writer.withBlock("object : #T {", "}", endpointProvider) { write( @@ -121,7 +121,7 @@ private object AwsSmokeTestsRunnerGenerator { * Preserves previous default config if any. */ val defaultClientConfig = - SectionWriterBinding(SmokeTestsRunnerGenerator.DefaultClientConfig) { writer, previous -> + SectionWriterBinding(DefaultClientConfig) { writer, previous -> writer.write("#L", previous) writer.write("region = regionOverride") } @@ -130,13 +130,13 @@ private object AwsSmokeTestsRunnerGenerator { * Replaces environment variable with one specific to AWS smoke test runners */ val skipTagsEnvironmentVariable = - SectionWriterBinding(SmokeTestsRunnerGenerator.SkipTags) { writer, _ -> writer.writeInline("#S", AWS_SKIP_TAGS) } + SectionWriterBinding(SkipTags) { writer, _ -> writer.writeInline("#S", AWS_SKIP_TAGS) } /** * Replaces environment variable with one specific to AWS smoke test runners */ val serviceFilterEnvironmentVariable = - SectionWriterBinding(SmokeTestsRunnerGenerator.ServiceFilter) { writer, _ -> writer.writeInline("#S", AWS_SERVICE_FILTER) } + SectionWriterBinding(ServiceFilter) { writer, _ -> writer.writeInline("#S", AWS_SERVICE_FILTER) } } /** diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt index e8a83fdc851..ee25447aa84 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt @@ -10,7 +10,7 @@ import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunnerGenerator.HttpEngineOverride +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.HttpEngineOverride import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt index 265f7c1c65a..e1b12dcf60b 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt @@ -9,7 +9,7 @@ import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestsRunnerGenerator.HttpEngineOverride +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.HttpEngineOverride import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape From 93c850b2ddb0278ece6d1ecfc8cae7c1865920c1 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 6 Nov 2024 11:13:30 -0500 Subject: [PATCH 40/41] PR feedback --- ...AwsSmokeTestsRunnerGeneratorIntegration.kt | 20 +++++++++---------- .../SmokeTestFailHttpEngineIntegration.kt | 4 ++-- .../SmokeTestSuccessHttpEngineIntegration.kt | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt index 8e6ec43708a..1e694ae4bbc 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/AwsSmokeTestsRunnerGeneratorIntegration.kt @@ -39,7 +39,7 @@ private object AwsSmokeTestsRunnerGenerator { * Preserves other environment variables added via section writer binding, if any. */ val regionEnvironmentVariable = - SectionWriterBinding(AdditionalEnvironmentVariables) { writer, previous -> + SectionWriterBinding(SmokeTestSectionIds.AdditionalEnvironmentVariables) { writer, previous -> writer.write("#L", previous) writer.write( "private val regionOverride = #T.System.getenv(#S)", @@ -52,9 +52,9 @@ private object AwsSmokeTestsRunnerGenerator { * Add AWS specific client config support to AWS smoke test runners */ val clientConfig = - SectionWriterBinding(ClientConfig) { writer, _ -> - val name = writer.getContextValue(ClientConfig.Name) - val value = writer.getContextValue(ClientConfig.Value) + SectionWriterBinding(SmokeTestSectionIds.ClientConfig) { writer, _ -> + val name = writer.getContextValue(SmokeTestSectionIds.ClientConfig.Name) + val value = writer.getContextValue(SmokeTestSectionIds.ClientConfig.Value) // Normalize client config names val newName = when (name) { @@ -65,7 +65,7 @@ private object AwsSmokeTestsRunnerGenerator { "useAccelerate" -> "enableAccelerate" "useMultiRegionAccessPoints" -> "disableMrap" "useGlobalEndpoint" -> { - writer.write("throw Exception(#S)", "'useGlobalEndpoint' is not supported by the SDK") + writer.write("throw #T(#S)", RuntimeTypes.Core.SmokeTests.SmokeTestsException, "'useGlobalEndpoint' is not supported by the SDK") return@SectionWriterBinding } else -> name @@ -75,8 +75,8 @@ private object AwsSmokeTestsRunnerGenerator { // Normalize client values when (newName) { "endpointProvider" -> { - val endpointProvider = writer.getContextValue(ClientConfig.EndpointProvider) - val endpointParameters = writer.getContextValue(ClientConfig.EndpointParams) + val endpointProvider = writer.getContextValue(SmokeTestSectionIds.ClientConfig.EndpointProvider) + val endpointParameters = writer.getContextValue(SmokeTestSectionIds.ClientConfig.EndpointParams) writer.withBlock("object : #T {", "}", endpointProvider) { write( @@ -121,7 +121,7 @@ private object AwsSmokeTestsRunnerGenerator { * Preserves previous default config if any. */ val defaultClientConfig = - SectionWriterBinding(DefaultClientConfig) { writer, previous -> + SectionWriterBinding(SmokeTestSectionIds.DefaultClientConfig) { writer, previous -> writer.write("#L", previous) writer.write("region = regionOverride") } @@ -130,13 +130,13 @@ private object AwsSmokeTestsRunnerGenerator { * Replaces environment variable with one specific to AWS smoke test runners */ val skipTagsEnvironmentVariable = - SectionWriterBinding(SkipTags) { writer, _ -> writer.writeInline("#S", AWS_SKIP_TAGS) } + SectionWriterBinding(SmokeTestSectionIds.SkipTags) { writer, _ -> writer.writeInline("#S", AWS_SKIP_TAGS) } /** * Replaces environment variable with one specific to AWS smoke test runners */ val serviceFilterEnvironmentVariable = - SectionWriterBinding(ServiceFilter) { writer, _ -> writer.writeInline("#S", AWS_SERVICE_FILTER) } + SectionWriterBinding(SmokeTestSectionIds.ServiceFilter) { writer, _ -> writer.writeInline("#S", AWS_SERVICE_FILTER) } } /** diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt index ee25447aa84..ad6bd0ee95e 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestFailHttpEngineIntegration.kt @@ -10,7 +10,7 @@ import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.HttpEngineOverride +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestSectionIds import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -29,7 +29,7 @@ class SmokeTestFailHttpEngineIntegration : KotlinIntegration { override val sectionWriters: List get() = listOf( - SectionWriterBinding(HttpEngineOverride, httpClientOverride), + SectionWriterBinding(SmokeTestSectionIds.HttpEngineOverride, httpClientOverride), ) private val httpClientOverride = SectionWriter { writer, _ -> diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt index e1b12dcf60b..03077a4cd5a 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/smoketests/testing/SmokeTestSuccessHttpEngineIntegration.kt @@ -9,7 +9,7 @@ import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.rendering.smoketests.HttpEngineOverride +import software.amazon.smithy.kotlin.codegen.rendering.smoketests.SmokeTestSectionIds import software.amazon.smithy.kotlin.codegen.utils.topDownOperations import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -28,7 +28,7 @@ class SmokeTestSuccessHttpEngineIntegration : KotlinIntegration { override val sectionWriters: List get() = listOf( - SectionWriterBinding(HttpEngineOverride, httpClientOverride), + SectionWriterBinding(SmokeTestSectionIds.HttpEngineOverride, httpClientOverride), ) private val httpClientOverride = SectionWriter { writer, _ -> From e7843438d9d65bad36777d092b7faf39b3b4b15b Mon Sep 17 00:00:00 2001 From: 0marperez <60363173+0marperez@users.noreply.github.com> Date: Thu, 7 Nov 2024 12:34:59 -0500 Subject: [PATCH 41/41] bump smithy kotlin versions --- gradle/libs.versions.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d86529cab72..d003593d62b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,8 +11,8 @@ coroutines-version = "1.9.0" atomicfu-version = "0.25.0" # smithy-kotlin codegen and runtime are versioned separately -smithy-kotlin-runtime-version = "1.3.19" -smithy-kotlin-codegen-version = "0.33.19" +smithy-kotlin-runtime-version = "1.3.20" +smithy-kotlin-codegen-version = "0.33.20" # codegen smithy-version = "1.51.0"