Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --device #409

Merged
merged 2 commits into from
Nov 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ class AndroidArgs(
val directoriesToPull = cli.directoriesToPull ?: androidGcloud.directoriesToPull
val performanceMetrics = cli.performanceMetrics ?: cli.noPerformanceMetrics?.not() ?: androidGcloud.performanceMetrics
val testTargets = cli.testTargets ?: androidGcloud.testTargets
val devices = androidGcloud.device
val devices = cli.device ?: androidGcloud.device

private val flank = flankYml.flank
override val testShards = flank.testShards
4 changes: 3 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ package ftl.args.yml
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import ftl.config.Device
import ftl.config.FtlConstants.defaultAndroidModel
import ftl.config.FtlConstants.defaultAndroidVersion
import ftl.util.Utils.assertNotEmpty

/**
@@ -33,7 +35,7 @@ class AndroidGcloudYmlParams(
@field:JsonProperty("test-targets")
val testTargets: List<String> = emptyList(),

val device: List<Device> = listOf(Device("NexusLowRes", "28"))
val device: List<Device> = listOf(Device(defaultAndroidModel, defaultAndroidVersion))
) {
companion object : IYmlKeys {
override val keys = listOf(
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package ftl.cli.firebase.test.android

import ftl.args.AndroidArgs
import ftl.config.Device
import ftl.config.FtlConstants
import ftl.config.FtlConstants.defaultAndroidModel
import ftl.config.FtlConstants.defaultAndroidVersion
import ftl.config.FtlConstants.defaultLocale
import ftl.config.FtlConstants.defaultOrientation
import ftl.run.TestRunner
import kotlinx.coroutines.runBlocking
import picocli.CommandLine.Command
@@ -89,4 +94,26 @@ class AndroidRunCommand : Runnable {
| 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."""])
var directoriesToPull: List<String>? = null

@Option(
names = ["--device"], split = ",", description = ["""A list of DIMENSION=VALUE pairs which specify a target
|device to test against. The four device dimensions are:
| model, version, locale, and orientation. If any dimensions are omitted, they will use a default value. Omitting
| all of the preceding dimension-related flags will run tests against a single device using defaults for all four
| device dimensions."""]
)
fun deviceMap(map: Map<String, String>?) {
if (map.isNullOrEmpty()) return
val androidDevice = Device(
model = map.getOrDefault("model", defaultAndroidModel),
version = map.getOrDefault("version", defaultAndroidVersion),
locale = map.getOrDefault("locale", defaultLocale),
orientation = map.getOrDefault("orientation", defaultOrientation)
)

if (device == null) device = mutableListOf()
device?.add(androidDevice)
}

var device: MutableList<Device>? = null
}
6 changes: 4 additions & 2 deletions test_runner/src/main/kotlin/ftl/config/Device.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ftl.config

import ftl.config.FtlConstants.defaultLocale
import ftl.config.FtlConstants.defaultOrientation
import ftl.util.Utils.trimStartLine

data class Device(
val model: String,
val version: String,
val locale: String = "en",
val orientation: String = "portrait"
val locale: String = defaultLocale,
val orientation: String = defaultOrientation
) {

override fun toString(): String {
4 changes: 4 additions & 0 deletions test_runner/src/main/kotlin/ftl/config/FtlConstants.kt
Original file line number Diff line number Diff line change
@@ -19,6 +19,10 @@ object FtlConstants {
val macOS = System.getProperty("os.name") == "Mac OS X"
const val localhost = "http://localhost:8080"

const val defaultLocale = "en"
const val defaultOrientation = "portrait"
const val defaultAndroidModel = "NexusLowRes"
const val defaultAndroidVersion = "28"
const val defaultIosConfig = "./flank.ios.yml"
const val defaultAndroidConfig = "./flank.yml"
const val indent = " "
24 changes: 24 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ package ftl.args
import com.google.common.truth.Truth.assertThat
import ftl.cli.firebase.test.android.AndroidRunCommand
import ftl.config.Device
import ftl.config.FtlConstants.defaultAndroidModel
import ftl.config.FtlConstants.defaultAndroidVersion
import ftl.test.util.FlankTestRunner
import ftl.test.util.TestHelper.absolutePath
import ftl.test.util.TestHelper.assert
@@ -471,4 +473,26 @@ AndroidArgs
val androidArgs = AndroidArgs.load(yaml, cli)
assertThat(androidArgs.directoriesToPull).isEqualTo(listOf("a", "b"))
}

@Test
fun cli_device() {
val cli = AndroidRunCommand()
CommandLine(cli).parse("--device=model=shamu,version=22,locale=zh_CN,orientation=default")

val yaml = """
gcloud:
app: $appApk
test: $testApk
"""
val expectedDefaultDevice = Device(defaultAndroidModel, defaultAndroidVersion)
val defaultDevices = AndroidArgs.load(yaml).devices
assertThat(defaultDevices.first()).isEqualTo(expectedDefaultDevice)
assertThat(defaultDevices.size).isEqualTo(1)

val androidArgs = AndroidArgs.load(yaml, cli)
val expectedDevice = Device("shamu", "22", "zh_CN", "default")
val actualDevices = androidArgs.devices
assertThat(actualDevices.first()).isEqualTo(expectedDevice)
assertThat(actualDevices.size).isEqualTo(1)
}
}
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package ftl.cli.firebase.test.android

import com.google.common.truth.Truth
import com.google.common.truth.Truth.assertThat
import ftl.config.Device
import ftl.config.FtlConstants
import ftl.test.util.FlankTestRunner
import org.junit.Rule
@@ -68,6 +69,7 @@ class AndroidRunCommandTest {
assertThat(cmd.noPerformanceMetrics).isNull()
assertThat(cmd.environmentVariables).isNull()
assertThat(cmd.directoriesToPull).isNull()
assertThat(cmd.device).isNull()
}

@Test
@@ -160,4 +162,14 @@ class AndroidRunCommandTest {

assertThat(cmd.directoriesToPull).hasSize(2)
}

@Test
fun device_parse() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parse("--device=model=shamu,version=22,locale=zh_CN,orientation=default")

val expectedDevice = Device("shamu", "22", "zh_CN", "default")
assertThat(cmd.device?.size).isEqualTo(1)
assertThat(cmd.device?.first()).isEqualTo(expectedDevice)
}
}