Skip to content

Commit

Permalink
Implement env parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelpasterz authored and mergify-bot committed Aug 12, 2021
1 parent 5852a8d commit 8aa43a4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
4 changes: 3 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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

Expand All @@ -20,7 +21,7 @@ fun createAndroidArgs(
appApk = gcloud.app?.normalizeFilePath(),
testApk = gcloud.test?.normalizeFilePath(),
useOrchestrator = gcloud::useOrchestrator.require(),
testTargets = gcloud::testTargets.require().filterNotNull(),
testTargets = gcloud::testTargets.require().filterNotNull().parseEnvsIfNeeded(),
testRunnerClass = gcloud.testRunnerClass,
roboDirectives = gcloud::roboDirectives.require().parseRoboDirectives(),
performanceMetrics = gcloud::performanceMetrics.require(),
Expand All @@ -35,6 +36,7 @@ fun createAndroidArgs(
it.copy(
app = it.app?.normalizeFilePath(),
test = it.test.normalizeFilePath(),
testTargets = it.testTargets?.parseEnvsIfNeeded()
)
} ?: emptyList(),
useLegacyJUnitResult = flank::useLegacyJUnitResult.require(),
Expand Down
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/CreateIosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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(
Expand All @@ -30,7 +31,7 @@ private fun createIosArgs(
xctestrunFile = gcloud.xctestrunFile?.normalizeFilePath().orEmpty(),
xcodeVersion = gcloud.xcodeVersion,
additionalIpas = gcloud::additionalIpas.require().map { it.normalizeFilePath() },
testTargets = flank.testTargets?.filterNotNull().orEmpty(),
testTargets = flank.testTargets?.filterNotNull().orEmpty().parseEnvsIfNeeded(),
obfuscateDumpShards = obfuscate,
app = gcloud.app?.normalizeFilePath().orEmpty(),
testSpecialEntitlements = gcloud.testSpecialEntitlements ?: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ data class AndroidGcloudConfig @JsonIgnore constructor(
"(default: run all test targets). Each target filter must be fully qualified with the package name, class name, " +
"or test annotation desired. Any test filter supported by am instrument -e … is supported. " +
"See https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner for more " +
"information."
"information. You can also pass values as environment variables: \$TEST_TARGETS_IN_ENV. This can be also list of " +
"strings delimited by coma."
]
)
@set:JsonProperty("test-targets")
Expand Down
11 changes: 11 additions & 0 deletions test_runner/src/main/kotlin/ftl/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,14 @@ fun <T> KMutableProperty<T?>.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<String>.parseEnvsIfNeeded() = this
.partition { it.startsWith("$") }
.let { (envs, commonTestTargets) ->
commonTestTargets + envs
.mapNotNull { getEnv(it.drop(1)) }
.flatMap { it.split(",") }
.map { it.trim() }
}
15 changes: 15 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsFileTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ 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
import org.junit.Assert.assertEquals
import org.junit.Rule
Expand Down Expand Up @@ -102,6 +105,18 @@ class AndroidArgsFileTest {
}
)

@Test
fun `should parse test-targets from env`() {
mockkStatic("ftl.util.Utils")
every { getEnv("FROM_ENV") } returns "class from.env.Class,notAnnotation from.env.Annotation"
val config = AndroidArgs.load(localYamlFile)
assertThat(config.testTargets).containsExactly(
"class from.env.Class",
"notAnnotation from.env.Annotation",
"class com.example.app.ExampleUiTest#testPasses"
)
}

@Test
fun `calculateShards additionalAppTestApks`() {
val test1 = "src/test/kotlin/ftl/fixtures/tmp/apk/app-debug-androidTest_1.apk"
Expand Down
1 change: 1 addition & 0 deletions test_runner/src/test/kotlin/ftl/fixtures/flank.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gcloud:
async: true
test-targets:
- class com.example.app.ExampleUiTest#testPasses
- $FROM_ENV
device:
- model: NexusLowRes
version: 23
Expand Down

0 comments on commit 8aa43a4

Please sign in to comment.