From 80d2ea6eb8fcb9be14cb5a2490145c525ab7531e Mon Sep 17 00:00:00 2001 From: pawelpasterz <32893017+pawelpasterz@users.noreply.github.com> Date: Mon, 9 Aug 2021 09:44:05 +0200 Subject: [PATCH] fix: Envs from additional apks not override default values (#2122) --- .../kotlin/ftl/run/platform/android/ResolveApks.kt | 7 +++++-- .../android/CreateAndroidTestContextKtTest.kt | 14 ++++++++++++-- .../ftl/run/platform/android/ResolveApksKtTest.kt | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/run/platform/android/ResolveApks.kt b/test_runner/src/main/kotlin/ftl/run/platform/android/ResolveApks.kt index cd154152c1..6c2c31028a 100644 --- a/test_runner/src/main/kotlin/ftl/run/platform/android/ResolveApks.kt +++ b/test_runner/src/main/kotlin/ftl/run/platform/android/ResolveApks.kt @@ -41,10 +41,11 @@ private fun AndroidArgs.mainApkContext() = appApk?.let { appApk -> private fun AndroidArgs.additionalApksContexts() = additionalAppTestApks.map { val appApk = (it.app ?: appApk) ?: throw FlankGeneralError("Cannot create app-test apks pair for instrumentation tests, missing app apk for test ${it.test}") + val envs = it.environmentVariables.takeIf { envs -> envs.isNotEmpty() } ?: environmentVariables InstrumentationTestContext( app = appApk.asFileReference(), test = it.test.asFileReference(), - environmentVariables = it.environmentVariables, + environmentVariables = envs, testTargetsForShard = testTargetsForShard, args = copy( commonArgs = commonArgs.copy( @@ -52,8 +53,10 @@ private fun AndroidArgs.additionalApksContexts() = additionalAppTestApks.map { devices = it.devices ?: devices, clientDetails = it.clientDetails ?: clientDetails ), + testApk = it.test, testTargets = it.testTargets ?: testTargets, - parameterizedTests = it.parameterizedTests ?: parameterizedTests + parameterizedTests = it.parameterizedTests ?: parameterizedTests, + environmentVariables = envs ) ) }.toTypedArray() diff --git a/test_runner/src/test/kotlin/ftl/run/platform/android/CreateAndroidTestContextKtTest.kt b/test_runner/src/test/kotlin/ftl/run/platform/android/CreateAndroidTestContextKtTest.kt index cd04a3a614..abfdbd2427 100644 --- a/test_runner/src/test/kotlin/ftl/run/platform/android/CreateAndroidTestContextKtTest.kt +++ b/test_runner/src/test/kotlin/ftl/run/platform/android/CreateAndroidTestContextKtTest.kt @@ -56,14 +56,24 @@ class CreateAndroidTestContextKtTest { test = should { local.endsWith("app-single-success-debug-androidTest.apk") }, shards = should { size == 1 }, ignoredTestCases = should { size == 2 }, - args = should { maxTestShards == 1 } + environmentVariables = should { equals(args.environmentVariables) }, + args = should { + maxTestShards == 1 && + testApk?.endsWith("app-single-success-debug-androidTest.apk") == true && + environmentVariables == args.environmentVariables + } ), InstrumentationTestContext( app = should { local.endsWith("app-debug.apk") }, test = should { local.endsWith("app-multiple-flaky-debug-androidTest.apk") }, shards = should { size == 2 }, ignoredTestCases = should { size == 2 }, - args = should { testTargets == listOf("class com.example.test_app.InstrumentedTest") } + environmentVariables = should { equals(args.environmentVariables) }, + args = should { + testTargets == listOf("class com.example.test_app.InstrumentedTest") && + testApk?.endsWith("app-multiple-flaky-debug-androidTest.apk") == true && + environmentVariables == args.environmentVariables + } ) ) diff --git a/test_runner/src/test/kotlin/ftl/run/platform/android/ResolveApksKtTest.kt b/test_runner/src/test/kotlin/ftl/run/platform/android/ResolveApksKtTest.kt index 7a63404628..5847c709c6 100644 --- a/test_runner/src/test/kotlin/ftl/run/platform/android/ResolveApksKtTest.kt +++ b/test_runner/src/test/kotlin/ftl/run/platform/android/ResolveApksKtTest.kt @@ -58,7 +58,7 @@ class ResolveApksKtTest { InstrumentationTestContext( app = "app".asFileReference(), test = "test".asFileReference(), - args = args + args = args.copy(testApk = "test") ) ), args.resolveApks().toTypedArray()