From 489ba8a0fb50be5e517e6d692e0c860c03c21f8d Mon Sep 17 00:00:00 2001 From: Pawel Pasterz Date: Fri, 13 Aug 2021 07:05:44 +0200 Subject: [PATCH] Review changes --- test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt | 11 +++++++++++ .../src/main/kotlin/ftl/args/CreateAndroidArgs.kt | 1 - test_runner/src/main/kotlin/ftl/args/CreateIosArgs.kt | 1 - test_runner/src/main/kotlin/ftl/util/Utils.kt | 11 ----------- .../src/test/kotlin/ftl/args/AndroidArgsFileTest.kt | 3 +-- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt b/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt index 3dc7c280cf..16334b62f2 100644 --- a/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt +++ b/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt @@ -291,3 +291,14 @@ fun String.normalizeFilePath(): String = fun List.normalizeToTestTargets(): ShardChunks = if (isEmpty()) emptyList() else map { it.split(',', ';') } + +fun getEnv(name: String): String? = System.getenv(name) + +fun List.parseEnvsIfNeeded() = this + .partition { it.startsWith("$") } + .let { (envs, commonTestTargets) -> + commonTestTargets + envs + .mapNotNull { getEnv(it.drop(1)) } + .flatMap { it.split(",") } + .map { it.trim() } + } diff --git a/test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt b/test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt index 3c01444a92..2cbdc5e26b 100644 --- a/test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt @@ -5,7 +5,6 @@ import ftl.config.android.AndroidFlankConfig import ftl.config.android.AndroidGcloudConfig import ftl.run.common.fromJson import ftl.run.model.AndroidTestShards -import ftl.util.parseEnvsIfNeeded import ftl.util.require import java.nio.file.Paths diff --git a/test_runner/src/main/kotlin/ftl/args/CreateIosArgs.kt b/test_runner/src/main/kotlin/ftl/args/CreateIosArgs.kt index 25321784b8..bad139f68c 100644 --- a/test_runner/src/main/kotlin/ftl/args/CreateIosArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/CreateIosArgs.kt @@ -4,7 +4,6 @@ import ftl.args.yml.Type import ftl.config.IosConfig import ftl.config.ios.IosFlankConfig import ftl.config.ios.IosGcloudConfig -import ftl.util.parseEnvsIfNeeded import ftl.util.require fun createIosArgs( diff --git a/test_runner/src/main/kotlin/ftl/util/Utils.kt b/test_runner/src/main/kotlin/ftl/util/Utils.kt index a15730a557..41b94f9cbb 100644 --- a/test_runner/src/main/kotlin/ftl/util/Utils.kt +++ b/test_runner/src/main/kotlin/ftl/util/Utils.kt @@ -128,14 +128,3 @@ fun KMutableProperty.require() = fun getGACPathOrEmpty(): String = System.getenv("GOOGLE_APPLICATION_CREDENTIALS").orEmpty() fun saveToFlankLinks(vararg links: String) = File("flank-links.log").writeText(links.joinToString(System.lineSeparator())) - -fun getEnv(name: String): String? = System.getenv(name) - -fun List.parseEnvsIfNeeded() = this - .partition { it.startsWith("$") } - .let { (envs, commonTestTargets) -> - commonTestTargets + envs - .mapNotNull { getEnv(it.drop(1)) } - .flatMap { it.split(",") } - .map { it.trim() } - } diff --git a/test_runner/src/test/kotlin/ftl/args/AndroidArgsFileTest.kt b/test_runner/src/test/kotlin/ftl/args/AndroidArgsFileTest.kt index 73bcff2d07..962ab70926 100644 --- a/test_runner/src/test/kotlin/ftl/args/AndroidArgsFileTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/AndroidArgsFileTest.kt @@ -13,7 +13,6 @@ import ftl.test.util.TestHelper.absolutePath import ftl.test.util.TestHelper.assert import ftl.test.util.TestHelper.getPath import ftl.test.util.TestHelper.getString -import ftl.util.getEnv import io.mockk.every import io.mockk.mockkStatic import kotlinx.coroutines.runBlocking @@ -107,7 +106,7 @@ class AndroidArgsFileTest { @Test fun `should parse test-targets from env`() { - mockkStatic("ftl.util.Utils") + mockkStatic("ftl.args.ArgsHelperKt") every { getEnv("FROM_ENV") } returns "class from.env.Class,notAnnotation from.env.Annotation" val config = AndroidArgs.load(localYamlFile) assertThat(config.testTargets).containsExactly(