diff --git a/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt b/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt index ba267f7228..a6f9c9078f 100644 --- a/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt @@ -19,6 +19,7 @@ import ftl.args.ArgsToString.mapToString import ftl.args.yml.AndroidGcloudYml import ftl.args.yml.FlankYml import ftl.args.yml.GcloudYml +import ftl.cli.firebase.test.android.AndroidRunCommand import ftl.config.Device import ftl.config.FtlConstants import ftl.config.FtlConstants.useMock @@ -34,7 +35,8 @@ class AndroidArgs( gcloudYml: GcloudYml, androidGcloudYml: AndroidGcloudYml, flankYml: FlankYml, - override val data: String + override val data: String, + val cli: AndroidRunCommand = AndroidRunCommand() ) : IArgs { private val gcloud = gcloudYml.gcloud override val resultsBucket: String @@ -45,7 +47,7 @@ class AndroidArgs( override val resultsHistoryName = gcloud.resultsHistoryName private val androidGcloud = androidGcloudYml.gcloud - val appApk = androidGcloud.app + val appApk = cli.app ?: androidGcloud.app val testApk = androidGcloud.test val autoGoogleLogin = androidGcloud.autoGoogleLogin val useOrchestrator = androidGcloud.useOrchestrator @@ -160,9 +162,9 @@ ${listToString(testTargetsAlwaysRun)} mergeYmlMaps(GcloudYml, AndroidGcloudYml, FlankYml) } - fun load(data: Path): AndroidArgs = load(String(Files.readAllBytes(data))) + fun load(data: Path, cli: AndroidRunCommand = AndroidRunCommand()): AndroidArgs = load(String(Files.readAllBytes(data)), cli) - fun load(data: String): AndroidArgs { + fun load(data: String, cli: AndroidRunCommand = AndroidRunCommand()): AndroidArgs { val flankYml = yamlMapper.readValue(data, FlankYml::class.java) val gcloudYml = yamlMapper.readValue(data, GcloudYml::class.java) val androidGcloudYml = yamlMapper.readValue(data, AndroidGcloudYml::class.java) @@ -171,7 +173,8 @@ ${listToString(testTargetsAlwaysRun)} gcloudYml, androidGcloudYml, flankYml, - data + data, + cli ) } } 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 5e8ab165e5..82b268c158 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 @@ -23,8 +23,9 @@ Configuration is read from flank.yml """] ) class AndroidRunCommand : Runnable { + override fun run() { - val config = AndroidArgs.load(Paths.get(configPath)) + val config = AndroidArgs.load(Paths.get(configPath), this) runBlocking { TestRunner.newRun(config) } @@ -35,4 +36,8 @@ class AndroidRunCommand : Runnable { @Option(names = ["-h", "--help"], usageHelp = true, description = ["Prints this help message"]) var usageHelpRequested: Boolean = false + + @Option(names = ["--app"], description = ["""The path to the application binary file. + |The path may be in the local filesystem or in Google Cloud Storage using gs:// notation."""]) + var app: String? = null } diff --git a/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt b/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt index 9f7b68b645..d90598b70a 100644 --- a/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt @@ -1,6 +1,7 @@ package ftl.args import com.google.common.truth.Truth.assertThat +import ftl.cli.firebase.test.android.AndroidRunCommand import ftl.config.Device import ftl.test.util.FlankTestRunner import ftl.test.util.TestHelper.assert @@ -8,6 +9,7 @@ import org.junit.Rule import org.junit.Test import org.junit.rules.ExpectedException import org.junit.runner.RunWith +import picocli.CommandLine @RunWith(FlankTestRunner::class) class AndroidArgsTest { @@ -223,8 +225,6 @@ AndroidArgs assert(projectId, "mockProjectId") // AndroidGcloudYml - assert(appApk, appApk) - assert(testApk, testApk) assert(autoGoogleLogin, true) assert(useOrchestrator, true) assert(environmentVariables, emptyMap()) @@ -275,4 +275,24 @@ AndroidArgs assertThat(androidArgs.appApk).isEqualTo(appApk) assertThat(androidArgs.testApk).isEqualTo(testApk) } + + @Test + fun androidArgs_overrideAppFromCmdLine() { + val cli = AndroidRunCommand() + CommandLine(cli).parse("--app", testApk) + + val androidArgs = AndroidArgs.load( + """ + gcloud: + app: $appApk + test: $testApk + + flank: + """, + cli + ) + + assertThat(androidArgs.appApk).isEqualTo(testApk) + assertThat(androidArgs.cli).isEqualTo(cli) + } } 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 3485f317ca..4e93db7818 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 @@ -28,21 +28,24 @@ class AndroidRunCommandTest { val output = systemOutRule.log Truth.assertThat(output).startsWith( - "Run tests on Firebase Test Lab\n" + - "\n" + - "run [-h] [-c=]\n" + - "\n" + - "Description:\n" + - "\n" + - "Uploads the app and test apk to GCS.\n" + - "Runs the espresso tests using orchestrator.\n" + - "Configuration is read from flank.yml\n" + - "\n" + - "\n" + - "Options:\n" + - " -c, --config=\n" + - " YAML config file path\n" + - " -h, --help Prints this help message\n" + """ + Run tests on Firebase Test Lab + + run [-h] [--app=] [-c=] + + Description: + + Uploads the app and test apk to GCS. + Runs the espresso tests using orchestrator. + Configuration is read from flank.yml + + + Options: + -c, --config= + YAML config file path + -h, --help Prints this help message + --app= The path to the application binary file. + """.trimIndent() ) assertThat(android.usageHelpRequested).isTrue() @@ -67,4 +70,11 @@ class AndroidRunCommandTest { cmd.usageHelpRequested = true assertThat(cmd.usageHelpRequested).isTrue() } + + @Test + fun androidRunCommandApp() { + val cmd = AndroidRunCommand() + CommandLine(cmd).parse("--app", "myApp.apk") + assertThat(cmd.app).isEqualTo("myApp.apk") + } }