Skip to content

Commit

Permalink
-app param
Browse files Browse the repository at this point in the history
  • Loading branch information
csessa committed Nov 13, 2018
1 parent 00bc89e commit e20c32e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 23 deletions.
13 changes: 8 additions & 5 deletions test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +35,8 @@ class AndroidArgs(
gcloudYml: GcloudYml,
androidGcloudYml: AndroidGcloudYml,
flankYml: FlankYml,
override val data: String
override val data: String,
val cmd: AndroidRunCommand = AndroidRunCommand()
) : IArgs {
private val gcloud = gcloudYml.gcloud
override val resultsBucket: String
Expand All @@ -45,7 +47,7 @@ class AndroidArgs(
override val resultsHistoryName = gcloud.resultsHistoryName

private val androidGcloud = androidGcloudYml.gcloud
val appApk = androidGcloud.app
val appApk = cmd.app ?: androidGcloud.app
val testApk = androidGcloud.test
val autoGoogleLogin = androidGcloud.autoGoogleLogin
val useOrchestrator = androidGcloud.useOrchestrator
Expand Down Expand Up @@ -160,9 +162,9 @@ ${listToString(testTargetsAlwaysRun)}
mergeYmlMaps(GcloudYml, AndroidGcloudYml, FlankYml)
}

fun load(data: Path): AndroidArgs = load(String(Files.readAllBytes(data)))
fun load(data: Path, cmd: AndroidRunCommand = AndroidRunCommand()): AndroidArgs = load(String(Files.readAllBytes(data)), cmd)

fun load(data: String): AndroidArgs {
fun load(data: String, cmd: 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)
Expand All @@ -171,7 +173,8 @@ ${listToString(testTargetsAlwaysRun)}
gcloudYml,
androidGcloudYml,
flankYml,
data
data,
cmd
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
24 changes: 22 additions & 2 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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
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 {
Expand Down Expand Up @@ -223,8 +225,6 @@ AndroidArgs
assert(projectId, "mockProjectId")

// AndroidGcloudYml
assert(appApk, appApk)
assert(testApk, testApk)
assert(autoGoogleLogin, true)
assert(useOrchestrator, true)
assert(environmentVariables, emptyMap<String, String>())
Expand Down Expand Up @@ -275,4 +275,24 @@ AndroidArgs
assertThat(androidArgs.appApk).isEqualTo(appApk)
assertThat(androidArgs.testApk).isEqualTo(testApk)
}

@Test
fun androidArgs_overrideAppFromCmdLine() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parse("--app", testApk)

val androidArgs = AndroidArgs.load(
"""
gcloud:
app: $appApk
test: $testApk
flank:
""",
cmd
)

assertThat(androidArgs.appApk).isEqualTo(testApk)
assertThat(androidArgs.cmd).isEqualTo(cmd)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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=<configPath>]\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=<configPath>\n" +
" YAML config file path\n" +
" -h, --help Prints this help message\n"
"""
Run tests on Firebase Test Lab
run [-h] [--app=<app>] [-c=<configPath>]
Description:
Uploads the app and test apk to GCS.
Runs the espresso tests using orchestrator.
Configuration is read from flank.yml
Options:
-c, --config=<configPath>
YAML config file path
-h, --help Prints this help message
--app=<app> The path to the application binary file.
""".trimIndent()
)

assertThat(android.usageHelpRequested).isTrue()
Expand All @@ -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")
}
}

0 comments on commit e20c32e

Please sign in to comment.