Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor smoke test tests to use already running gradle instance #1542

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
* 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 java.io.File
import kotlin.test.Test
import kotlin.test.assertContains
Expand All @@ -30,7 +29,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 +57,24 @@ 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(
if (System.getProperty("os.name").contains("Windows", ignoreCase = true)) ".\\gradlew.bat" else "./gradlew",
Copy link
Member

Choose a reason for hiding this comment

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

You should re-use PlatformProvider.System which already offers utilities for this

":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()
val process = processBuilder.start()
val output = process.inputStream.bufferedReader().use { it.readText() }

return buildResult.output
return output
}
Loading