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

feat: Implement env parsing #2131

Merged
merged 2 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,14 @@ fun String.normalizeFilePath(): String =
fun List<String>.normalizeToTestTargets(): ShardChunks =
if (isEmpty()) emptyList()
else map { it.split(',', ';') }

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() }
}
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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 +35,7 @@ fun createAndroidArgs(
it.copy(
app = it.app?.normalizeFilePath(),
test = it.test.normalizeFilePath(),
testTargets = it.testTargets?.parseEnvsIfNeeded()
)
} ?: emptyList(),
useLegacyJUnitResult = flank::useLegacyJUnitResult.require(),
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/CreateIosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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
14 changes: 14 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,8 @@ 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 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 +104,18 @@ class AndroidArgsFileTest {
}
)

@Test
fun `should parse test-targets from env`() {
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(
"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
piotradamczyk5 marked this conversation as resolved.
Show resolved Hide resolved
device:
- model: NexusLowRes
version: 23
Expand Down