From 3465ff43a7c07b490c4f27f8415b04069f081fed Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Tue, 8 Jan 2019 14:57:35 -0500 Subject: [PATCH] Update directories to download --- .../src/main/kotlin/ftl/args/IosArgs.kt | 3 +++ .../src/main/kotlin/ftl/args/yml/FlankYml.kt | 1 + .../test/android/AndroidRunCommand.kt | 20 +++++++++--------- .../cli/firebase/test/ios/IosRunCommand.kt | 10 +++++++++ .../src/test/kotlin/ftl/args/IosArgsTest.kt | 21 +++++++++++++++++++ .../test/android/AndroidRunCommandTest.kt | 9 ++++++++ .../firebase/test/ios/IosRunCommandTest.kt | 9 ++++++++ .../kotlin/ftl/test/util/FlankTestRunner.kt | 4 ++++ .../src/test/kotlin/ftl/test/util/LocalGcs.kt | 10 +++++++++ .../test/kotlin/ftl/util/ArtifactRegexTest.kt | 7 +++---- 10 files changed, 80 insertions(+), 14 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/args/IosArgs.kt b/test_runner/src/main/kotlin/ftl/args/IosArgs.kt index 67c44d979e..71b267b2c2 100644 --- a/test_runner/src/main/kotlin/ftl/args/IosArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/IosArgs.kt @@ -52,6 +52,7 @@ class IosArgs( override val repeatTests = cli?.repeatTests ?: flank.repeatTests override val smartFlankGcsPath = flank.smartFlankGcsPath override val testTargetsAlwaysRun = cli?.testTargetsAlwaysRun ?: flank.testTargetsAlwaysRun + val directoriesToDownload = cli?.directoriesToDownload ?: flank.directoriesToDownload private val iosFlank = iosFlankYml.flank val testTargets = cli?.testTargets ?: iosFlank.testTargets @@ -123,6 +124,8 @@ ${devicesToString(devices)} smartFlankGcsPath: $smartFlankGcsPath test-targets-always-run: ${listToString(testTargetsAlwaysRun)} + directories-to-download: +${listToString(directoriesToDownload)} # iOS flank test-targets: ${listToString(testTargets)} diff --git a/test_runner/src/main/kotlin/ftl/args/yml/FlankYml.kt b/test_runner/src/main/kotlin/ftl/args/yml/FlankYml.kt index b0d622e5fa..23f9f6251b 100644 --- a/test_runner/src/main/kotlin/ftl/args/yml/FlankYml.kt +++ b/test_runner/src/main/kotlin/ftl/args/yml/FlankYml.kt @@ -14,6 +14,7 @@ class FlankYmlParams( @field:JsonProperty("test-targets-always-run") val testTargetsAlwaysRun: List = emptyList(), + @field:JsonProperty("directories-to-download") val directoriesToDownload: List = emptyList() ) { diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidRunCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidRunCommand.kt index 237a76a987..3d3c4748f6 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidRunCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidRunCommand.kt @@ -138,16 +138,6 @@ class AndroidRunCommand : Runnable { ) var directoriesToPull: List? = null - @Option( - names = ["--directories-to-download"], - split = ",", - description = ["A list of paths that will be downloaded from the resulting bucket " + - "to the designated local results folder after the test is complete. These must be absolute paths " + - "(for example, --directories-to-download /images/tempDir1,/data/local/tmp/tempDir2). " + - "Path names are restricted to the characters a-zA-Z0-9_-./+."] - ) - var directoriesToDownload: List? = null - @Option( names = ["--device"], split = ",", @@ -245,6 +235,16 @@ class AndroidRunCommand : Runnable { ) var testTargetsAlwaysRun: List? = null + @Option( + names = ["--directories-to-download"], + split = ",", + description = ["A list of paths that will be downloaded from the resulting bucket " + + "to the local results folder after the test is complete. These must be absolute paths " + + "(for example, --directories-to-download /images/tempDir1,/data/local/tmp/tempDir2). " + + "Path names are restricted to the characters a-zA-Z0-9_-./+."] + ) + var directoriesToDownload: List? = null + @Option( names = ["--results-dir"], description = [ diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosRunCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosRunCommand.kt index f3882f1755..7cd7d3f86d 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosRunCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosRunCommand.kt @@ -126,6 +126,16 @@ class IosRunCommand : Runnable { ) var testTargets: List? = null + @Option( + names = ["--directories-to-download"], + split = ",", + description = ["A list of paths that will be downloaded from the resulting bucket " + + "to the local results folder after the test is complete. These must be absolute paths " + + "(for example, --directories-to-download /images/tempDir1,/data/local/tmp/tempDir2). " + + "Path names are restricted to the characters a-zA-Z0-9_-./+."] + ) + var directoriesToDownload: List? = null + @Option( names = ["--test"], description = ["The path to the test package (a zip file containing the iOS app " + diff --git a/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt b/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt index d84fe154e4..b1dc58cbd8 100644 --- a/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt @@ -53,6 +53,8 @@ class IosArgsTest { flank: testShards: 7 repeatTests: 8 + directories-to-download: + - /sdcard/screenshots test-targets-always-run: - a/testGrantPermissions - a/testGrantPermissions2 @@ -159,6 +161,8 @@ IosArgs test-targets-always-run: - a/testGrantPermissions - a/testGrantPermissions2 + directories-to-download: + - /sdcard/screenshots # iOS flank test-targets: - b/testBasicSelection @@ -194,6 +198,7 @@ IosArgs assert(testShards, 1) assert(repeatTests, 1) assert(testTargetsAlwaysRun, emptyList()) + assert(directoriesToDownload, emptyList()) // IosFlankYml assert(testTargets, empty) @@ -507,4 +512,20 @@ IosArgs assertThat(IosArgs.load(yaml).resultsDir).isEqualTo("a") assertThat(IosArgs.load(yaml, cli).resultsDir).isEqualTo("b") } + + @Test + fun cli_directoriesToDownload() { + val cli = IosRunCommand() + CommandLine(cli).parse("--directories-to-download=a,b,c") + + val yaml = """ + gcloud: + test: $testPath + xctestrun-file: $testPath + """ + assertThat(IosArgs.load(yaml).directoriesToDownload).isEmpty() + + val androidArgs = IosArgs.load(yaml, cli) + assertThat(androidArgs.directoriesToDownload).isEqualTo(listOf("a", "b")) + } } 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 525179c1a6..136289b37f 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,6 +80,7 @@ class AndroidRunCommandTest { assertThat(cmd.testShards).isNull() assertThat(cmd.repeatTests).isNull() assertThat(cmd.testTargetsAlwaysRun).isNull() + assertThat(cmd.directoriesToDownload).isNull() assertThat(cmd.resultsDir).isNull() } @@ -273,4 +274,12 @@ class AndroidRunCommandTest { assertThat(cmd.resultsDir).isEqualTo("a") } + + @Test + fun directoriesToDownload_parse() { + val cmd = AndroidRunCommand() + CommandLine(cmd).parse("--directories-to-download=a,b") + + assertThat(cmd.directoriesToDownload).isEqualTo(arrayListOf("a", "b")) + } } 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 bab82a7c67..91516b9577 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 @@ -69,6 +69,7 @@ class IosRunCommandTest { assertThat(cmd.repeatTests).isNull() assertThat(cmd.testTargetsAlwaysRun).isNull() assertThat(cmd.testTargets).isNull() + assertThat(cmd.directoriesToDownload).isNull() assertThat(cmd.test).isNull() assertThat(cmd.xctestrunFile).isNull() assertThat(cmd.xcodeVersion).isNull() @@ -207,4 +208,12 @@ class IosRunCommandTest { assertThat(cmd.resultsDir).isEqualTo("a") } + + @Test + fun directoriesToDownload_parse() { + val cmd = IosRunCommand() + CommandLine(cmd).parse("--directories-to-download=a,b") + + assertThat(cmd.directoriesToDownload).isEqualTo(arrayListOf("a", "b")) + } } diff --git a/test_runner/src/test/kotlin/ftl/test/util/FlankTestRunner.kt b/test_runner/src/test/kotlin/ftl/test/util/FlankTestRunner.kt index f2200a29c5..7796794b7d 100644 --- a/test_runner/src/test/kotlin/ftl/test/util/FlankTestRunner.kt +++ b/test_runner/src/test/kotlin/ftl/test/util/FlankTestRunner.kt @@ -1,9 +1,13 @@ package ftl.test.util +import com.google.auth.oauth2.ComputeEngineCredentials import ftl.config.FtlConstants +import ftl.gc.GcStorage import ftl.util.Bash import org.junit.runners.BlockJUnit4ClassRunner import java.net.BindException +import java.util.logging.Level +import java.util.logging.Logger class FlankTestRunner(klass: Class<*>) : BlockJUnit4ClassRunner(klass) { diff --git a/test_runner/src/test/kotlin/ftl/test/util/LocalGcs.kt b/test_runner/src/test/kotlin/ftl/test/util/LocalGcs.kt index 2c52001910..a192ba3b3f 100644 --- a/test_runner/src/test/kotlin/ftl/test/util/LocalGcs.kt +++ b/test_runner/src/test/kotlin/ftl/test/util/LocalGcs.kt @@ -1,11 +1,14 @@ package ftl.test.util +import com.google.auth.oauth2.ComputeEngineCredentials import com.google.cloud.storage.BlobInfo import ftl.gc.GcStorage import org.junit.Assert import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths +import java.util.logging.Level +import java.util.logging.Logger object LocalGcs { @@ -28,6 +31,13 @@ object LocalGcs { ) } + private fun silenceComputeEngine() { + // Set log level then access the storage var to lazy load it. + // Silence info log about "Failed to detect whether we are running on Google Compute Engine." + Logger.getLogger(ComputeEngineCredentials::class.java.name).level = Level.OFF + GcStorage.storage + } + fun uploadFiles() { val appApk = "../test_app/apks/app-debug.apk" val testApk = "../test_app/apks/app-debug-androidTest.apk" diff --git a/test_runner/src/test/kotlin/ftl/util/ArtifactRegexTest.kt b/test_runner/src/test/kotlin/ftl/util/ArtifactRegexTest.kt index cbf041e275..6718fb92c7 100644 --- a/test_runner/src/test/kotlin/ftl/util/ArtifactRegexTest.kt +++ b/test_runner/src/test/kotlin/ftl/util/ArtifactRegexTest.kt @@ -23,13 +23,12 @@ class ArtifactRegexTest { @Test fun regexExists() { assertThat(ArtifactRegex.testResultRgx).isNotNull() - assertThat(ArtifactRegex.screenshotRgx).isNotNull() } @Test fun `artifactsToDownload should return just testResult and screenshot regex if no directoriesToDownload`() { assertRegexEquals(ArtifactRegex.artifactsToDownload(matrix, emptyList()), - listOf(ArtifactRegex.testResultRgx, ArtifactRegex.screenshotRgx)) + listOf(ArtifactRegex.testResultRgx)) } @Test @@ -37,7 +36,7 @@ class ArtifactRegexTest { `when`(matrix.gcsPathWithoutRootBucket).thenReturn(MATRIX_GCS_PATH_WITHOUT_ROOT_BUCKET) assertRegexEquals(ArtifactRegex.artifactsToDownload(matrix, listOf(TO_DOWNLOAD_1)), - listOf(ArtifactRegex.testResultRgx, ArtifactRegex.screenshotRgx, TO_DOWNLOAD_REGEX_1)) + listOf(ArtifactRegex.testResultRgx, TO_DOWNLOAD_REGEX_1)) } @Test @@ -45,7 +44,7 @@ class ArtifactRegexTest { `when`(matrix.gcsPathWithoutRootBucket).thenReturn(MATRIX_GCS_PATH_WITHOUT_ROOT_BUCKET) assertRegexEquals(ArtifactRegex.artifactsToDownload(matrix, listOf(TO_DOWNLOAD_1, TO_DOWNLOAD_2)), - listOf(ArtifactRegex.testResultRgx, ArtifactRegex.screenshotRgx, TO_DOWNLOAD_REGEX_1, TO_DOWNLOAD_REGEX_2)) + listOf(ArtifactRegex.testResultRgx, TO_DOWNLOAD_REGEX_1, TO_DOWNLOAD_REGEX_2)) } private fun assertRegexEquals(expected: List, actual: List) {