From fb8e99f8f1d7c165d93c074134d1f33e8881470b Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 23 Oct 2020 15:21:17 +0200 Subject: [PATCH] Moved directories to pull to CommonArgs, added tests --- .../src/main/kotlin/ftl/args/AndroidArgs.kt | 1 - .../src/main/kotlin/ftl/args/CommonArgs.kt | 1 + .../main/kotlin/ftl/args/CreateAndroidArgs.kt | 1 - .../main/kotlin/ftl/args/CreateCommonArgs.kt | 2 +- test_runner/src/main/kotlin/ftl/args/IArgs.kt | 1 + .../src/main/kotlin/ftl/args/IosArgs.kt | 3 +- .../ftl/config/android/AndroidGcloudConfig.kt | 14 --------- .../ftl/config/common/CommonGcloudConfig.kt | 14 +++++++++ .../src/main/kotlin/ftl/gc/GcIosTestMatrix.kt | 4 +++ .../test/android/AndroidRunCommandTest.kt | 4 +-- .../firebase/test/ios/IosRunCommandTest.kt | 1 + .../test/kotlin/ftl/gc/GcIosTestMatrixTest.kt | 30 +++++++++++++++++++ 12 files changed, 56 insertions(+), 20 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt b/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt index 4b1c414979..037acaa3ba 100644 --- a/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt @@ -13,7 +13,6 @@ data class AndroidArgs( val roboDirectives: List, val roboScript: String?, val environmentVariables: Map, // should not be printed, becuase could contains sensitive informations - val directoriesToPull: List, val grantPermissions: String?, val type: Type?, val scenarioNumbers: List, diff --git a/test_runner/src/main/kotlin/ftl/args/CommonArgs.kt b/test_runner/src/main/kotlin/ftl/args/CommonArgs.kt index c4e1505299..cc67b24f35 100644 --- a/test_runner/src/main/kotlin/ftl/args/CommonArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/CommonArgs.kt @@ -17,6 +17,7 @@ data class CommonArgs( override val flakyTestAttempts: Int, override val clientDetails: Map?, override val networkProfile: String?, + override val directoriesToPull: List, // flank override val project: String, diff --git a/test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt b/test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt index 99e0ccdd37..46e2c73d74 100644 --- a/test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt @@ -25,7 +25,6 @@ fun createAndroidArgs( otherFiles = gcloud.otherFiles!!.mapValues { (_, path) -> path.normalizeFilePath() }, numUniformShards = gcloud.numUniformShards, environmentVariables = gcloud.environmentVariables!!, - directoriesToPull = gcloud.directoriesToPull!!, autoGoogleLogin = gcloud.autoGoogleLogin!!, additionalApks = gcloud.additionalApks!!.map { it.normalizeFilePath() }, roboScript = gcloud.roboScript?.normalizeFilePath(), diff --git a/test_runner/src/main/kotlin/ftl/args/CreateCommonArgs.kt b/test_runner/src/main/kotlin/ftl/args/CreateCommonArgs.kt index 897eaa8c08..76b29e3686 100644 --- a/test_runner/src/main/kotlin/ftl/args/CreateCommonArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/CreateCommonArgs.kt @@ -24,7 +24,7 @@ fun CommonConfig.createCommonArgs( flakyTestAttempts = gcloud.flakyTestAttempts!!, networkProfile = gcloud.networkProfile, clientDetails = gcloud.clientDetails, - + directoriesToPull = gcloud.directoriesToPull!!, // flank maxTestShards = flank.maxTestShards!!, shardTime = flank.shardTime!!, diff --git a/test_runner/src/main/kotlin/ftl/args/IArgs.kt b/test_runner/src/main/kotlin/ftl/args/IArgs.kt index fc16a9b4a1..d7e16f2da7 100644 --- a/test_runner/src/main/kotlin/ftl/args/IArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/IArgs.kt @@ -22,6 +22,7 @@ interface IArgs { val project: String val resultsHistoryName: String? val flakyTestAttempts: Int + val directoriesToPull: List // FlankYml val maxTestShards: Int diff --git a/test_runner/src/main/kotlin/ftl/args/IosArgs.kt b/test_runner/src/main/kotlin/ftl/args/IosArgs.kt index 7000730049..47756d0de3 100644 --- a/test_runner/src/main/kotlin/ftl/args/IosArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/IosArgs.kt @@ -38,7 +38,8 @@ IosArgs xcode-version: $xcodeVersion device:${ArgsToString.objectsToString(devices)} num-flaky-test-attempts: $flakyTestAttempts - + directories-to-pull: ${ArgsToString.listToString(directoriesToPull)} + flank: max-test-shards: $maxTestShards shard-time: $shardTime diff --git a/test_runner/src/main/kotlin/ftl/config/android/AndroidGcloudConfig.kt b/test_runner/src/main/kotlin/ftl/config/android/AndroidGcloudConfig.kt index 1d85cead76..e145a228ab 100644 --- a/test_runner/src/main/kotlin/ftl/config/android/AndroidGcloudConfig.kt +++ b/test_runner/src/main/kotlin/ftl/config/android/AndroidGcloudConfig.kt @@ -109,19 +109,6 @@ data class AndroidGcloudConfig @JsonIgnore constructor( @set:JsonProperty("type") var type: String? by data - @set:CommandLine.Option( - names = ["--directories-to-pull"], - split = ",", - description = ["A list of paths that will be copied from the device's " + - "storage to the designated results bucket after the test is complete. These must be absolute paths under " + - "/sdcard or /data/local/tmp (for example, --directories-to-pull /sdcard/tempDir1,/data/local/tmp/tempDir2). " + - "Path names are restricted to the characters a-zA-Z0-9_-./+. The paths /sdcard and /data will be made available " + - "and treated as implicit path substitutions. E.g. if /sdcard on a particular device does not map to external " + - "storage, the system will replace it with the external storage path prefix for that device."] - ) - @set:JsonProperty("directories-to-pull") - var directoriesToPull: List? by data - @set:CommandLine.Option( names = ["--other-files"], split = ",", @@ -257,7 +244,6 @@ data class AndroidGcloudConfig @JsonIgnore constructor( useOrchestrator = true environmentVariables = emptyMap() grantPermissions = FlankDefaults.GRANT_PERMISSIONS_ALL - directoriesToPull = emptyList() otherFiles = emptyMap() scenarioNumbers = emptyList() scenarioLabels = emptyList() diff --git a/test_runner/src/main/kotlin/ftl/config/common/CommonGcloudConfig.kt b/test_runner/src/main/kotlin/ftl/config/common/CommonGcloudConfig.kt index c1e165f53e..a6c366dfe4 100644 --- a/test_runner/src/main/kotlin/ftl/config/common/CommonGcloudConfig.kt +++ b/test_runner/src/main/kotlin/ftl/config/common/CommonGcloudConfig.kt @@ -120,6 +120,19 @@ data class CommonGcloudConfig @JsonIgnore constructor( @set:JsonProperty("num-flaky-test-attempts") var flakyTestAttempts: Int? by data + @set:CommandLine.Option( + names = ["--directories-to-pull"], + split = ",", + description = ["A list of paths that will be copied from the device's " + + "storage to the designated results bucket after the test is complete. These must be absolute paths under " + + "/sdcard or /data/local/tmp (for example, --directories-to-pull /sdcard/tempDir1,/data/local/tmp/tempDir2). " + + "Path names are restricted to the characters a-zA-Z0-9_-./+. The paths /sdcard and /data will be made available " + + "and treated as implicit path substitutions. E.g. if /sdcard on a particular device does not map to external " + + "storage, the system will replace it with the external storage path prefix for that device."] + ) + @set:JsonProperty("directories-to-pull") + var directoriesToPull: List? by data + constructor() : this(mutableMapOf().withDefault { null }) companion object : IYmlKeys { @@ -143,6 +156,7 @@ data class CommonGcloudConfig @JsonIgnore constructor( clientDetails = null networkProfile = null devices = listOf(defaultDevice(android)) + directoriesToPull = emptyList() } } } diff --git a/test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt b/test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt index 76f7504a86..ecb9299c9b 100644 --- a/test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt +++ b/test_runner/src/main/kotlin/ftl/gc/GcIosTestMatrix.kt @@ -6,6 +6,7 @@ import com.google.api.services.testing.model.ClientInfo import com.google.api.services.testing.model.EnvironmentMatrix import com.google.api.services.testing.model.FileReference import com.google.api.services.testing.model.GoogleCloudStorage +import com.google.api.services.testing.model.IosDeviceFile import com.google.api.services.testing.model.IosDeviceList import com.google.api.services.testing.model.IosTestSetup import com.google.api.services.testing.model.IosXcTest @@ -62,6 +63,7 @@ object GcIosTestMatrix { val iOSTestSetup = IosTestSetup() .setNetworkProfile(args.networkProfile) + .setPullDirectories(args.directoriesToPull.toIosDeviceFiles()) val testTimeoutSeconds = timeoutToSeconds(args.testTimeout) @@ -91,3 +93,5 @@ object GcIosTestMatrix { } } } + +private fun List.toIosDeviceFiles() = map { path -> IosDeviceFile().apply { devicePath = path } } diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/AndroidRunCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/AndroidRunCommandTest.kt index a76fd976fc..1bea9aaeb4 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/AndroidRunCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/AndroidRunCommandTest.kt @@ -80,7 +80,6 @@ class AndroidRunCommandTest { assertThat(cmd.config.platform.gcloud.numUniformShards).isNull() assertThat(cmd.config.platform.gcloud.testRunnerClass).isNull() assertThat(cmd.config.platform.gcloud.environmentVariables).isNull() - assertThat(cmd.config.platform.gcloud.directoriesToPull).isNull() assertThat(cmd.config.platform.gcloud.otherFiles).isNull() assertThat(cmd.config.common.gcloud.devices).isNull() assertThat(cmd.config.common.gcloud.resultsBucket).isNull() @@ -98,6 +97,7 @@ class AndroidRunCommandTest { assertThat(cmd.config.common.flank.filesToDownload).isNull() assertThat(cmd.config.common.gcloud.resultsDir).isNull() assertThat(cmd.config.common.gcloud.flakyTestAttempts).isNull() + assertThat(cmd.config.common.gcloud.directoriesToPull).isNull() assertThat(cmd.config.common.flank.disableSharding).isNull() assertThat(cmd.config.common.flank.localResultsDir).isNull() assertThat(cmd.config.common.flank.smartFlankDisableUpload).isNull() @@ -219,7 +219,7 @@ class AndroidRunCommandTest { val cmd = AndroidRunCommand() CommandLine(cmd).parseArgs("--directories-to-pull=a,b") - assertThat(cmd.config.platform.gcloud.directoriesToPull).hasSize(2) + assertThat(cmd.config.common.gcloud.directoriesToPull).hasSize(2) } @Test diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/IosRunCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/IosRunCommandTest.kt index 987dcb4f73..25dd6540ba 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/IosRunCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/IosRunCommandTest.kt @@ -90,6 +90,7 @@ class IosRunCommandTest { assertThat(cmd.config.common.gcloud.devices).isNull() assertThat(cmd.config.common.gcloud.resultsDir).isNull() assertThat(cmd.config.common.gcloud.flakyTestAttempts).isNull() + assertThat(cmd.config.common.gcloud.directoriesToPull).isNull() assertThat(cmd.config.common.flank.localResultsDir).isNull() assertThat(cmd.config.common.flank.smartFlankDisableUpload).isNull() assertThat(cmd.config.common.flank.smartFlankGcsPath).isNull() diff --git a/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt b/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt index 8b712257f0..ab90b5e580 100644 --- a/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt +++ b/test_runner/src/test/kotlin/ftl/gc/GcIosTestMatrixTest.kt @@ -11,8 +11,10 @@ import io.mockk.every import io.mockk.mockk import io.mockk.unmockkAll import org.junit.After +import org.junit.Assert import org.junit.Test import org.junit.runner.RunWith +import java.io.StringReader @RunWith(FlankTestRunner::class) class GcIosTestMatrixTest { @@ -73,4 +75,32 @@ class GcIosTestMatrixTest { toolResultsHistory = GcToolResults.createToolResultsHistory(iosArgs) ) } + + @Test + fun `should fill directoriesToPull`() { + val iosArgs = IosArgs.load(StringReader(""" + gcloud: + test: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/earlgrey_example.zip + xctestrun-file: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/EarlGreyExampleSwiftTests_iphoneos13.4-arm64e.xctestrun + results-dir: test_dir + directories-to-pull: + - test/test/test + """.trimIndent())) + + val expected = listOf("test/test/test") + Assert.assertEquals(expected, iosArgs.directoriesToPull) + } + + @Test + fun `should not fill directoriesToPull`() { + val iosArgs = IosArgs.load(StringReader(""" + gcloud: + test: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/earlgrey_example.zip + xctestrun-file: ./test_runner/src/test/kotlin/ftl/fixtures/tmp/EarlGreyExampleSwiftTests_iphoneos13.4-arm64e.xctestrun + results-dir: test_dir + """.trimIndent())) + + val expected = emptyList() + Assert.assertEquals(expected, iosArgs.directoriesToPull) + } }