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() }