Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

package aws.sdk.kotlin.tests.codegen.smoketests
package aws.sdk.kotlin.test.codegen.smoketest

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 aws.smithy.kotlin.runtime.util.OsFamily
import aws.smithy.kotlin.runtime.util.PlatformProvider
import java.io.File
import kotlin.test.Test
import kotlin.test.assertContains
Expand All @@ -30,7 +31,7 @@ class SmokeTestE2ETest {

@Test
fun exceptionService() {
val smokeTestRunnerOutput = runSmokeTests("exceptionService", expectingFailure = true)
val smokeTestRunnerOutput = runSmokeTests("exceptionService")

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")
Expand Down Expand Up @@ -58,21 +59,34 @@ class SmokeTestE2ETest {
private fun runSmokeTests(
service: String,
envVars: Map<String, String> = emptyMap(),
expectingFailure: Boolean = false,
): String {
val sdkRootDir = System.getProperty("user.dir") + "/../../../"

val task = GradleRunner.create()
.withProjectDir(File(sdkRootDir))
.withArguments(
"--stacktrace", // Make sure unexpected errors are debuggable
"-Paws.kotlin.native=false", // FIXME: Remove `-Paws.kotlin.native=false` when Kotlin Native is ready
val processBuilder =
ProcessBuilder(
*gradleWrapperCommand(),
":tests:codegen:smoke-tests:services:$service:smokeTest",
// Make sure unexpected errors are debuggable
"--stacktrace",
// FIXME: Remove `-Paws.kotlin.native=false` when Kotlin Native is ready
"-Paws.kotlin.native=false",
)
.withEnvironment(envVars)
.forwardOutput()
.directory(File(sdkRootDir))
.redirectErrorStream(true)

processBuilder.environment().putAll(envVars)

val buildResult = if (expectingFailure) task.buildAndFail() else task.build()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we no longer asserting that the Gradle task fails? ProcessBuilder should have an option to get the exit error code which could be processed in a similar way to buildAndFail()

val process = processBuilder.start()
val output = process.inputStream.bufferedReader().use { it.readText() }

return buildResult.output
return output
}

/**
* Determines the appropriate Gradle wrapper command based on the operating system.
*/
private fun gradleWrapperCommand() =
if (PlatformProvider.System.osInfo().family == OsFamily.Windows) {
arrayOf("cmd.exe", "/c", "gradlew.bat")
} else {
arrayOf("./gradlew")
}
Loading