Skip to content

Commit

Permalink
Add --device
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline committed Dec 3, 2018
1 parent c7c50a8 commit 8381c90
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/IosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class IosArgs(
var xctestrunZip = cli?.test ?: iosGcloud.test
var xctestrunFile = cli?.xctestrunFile ?: iosGcloud.xctestrunFile
val xcodeVersion = cli?.xcodeVersion ?: iosGcloud.xcodeVersion
val devices = iosGcloud.device
val devices = cli?.device ?: iosGcloud.device

private val flank = flankYml.flank
override val testShards = cli?.testShards ?: flank.testShards
Expand Down
4 changes: 3 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/yml/IosGcloudYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.defaultIosModel
import ftl.config.FtlConstants.defaultIosVersion
import ftl.util.Utils.assertNotEmpty

/**
Expand All @@ -21,7 +23,7 @@ class IosGcloudYmlParams(
@field:JsonProperty("xcode-version")
val xcodeVersion: String? = null,

val device: List<Device> = listOf(Device("iphone8", "11.2"))
val device: List<Device> = listOf(Device(defaultIosModel, defaultIosVersion))
) {
companion object : IYmlKeys {
override val keys = listOf("test", "xctestrun-file", "xcode-version", "device")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package ftl.cli.firebase.test.ios

import ftl.args.IosArgs
import ftl.config.Device
import ftl.config.FtlConstants
import ftl.config.FtlConstants.defaultIosModel
import ftl.config.FtlConstants.defaultIosVersion
import ftl.run.TestRunner
import kotlinx.coroutines.runBlocking
import picocli.CommandLine.Command
Expand Down Expand Up @@ -98,4 +101,25 @@ class IosRunCommand : Runnable {
| Defaults to the latest Xcode version supported in Firebase Test Lab. This Xcode version must be supported by
| all iOS versions selected in the test matrix."""])
var xcodeVersion: String? = null

@Option(names = ["--device"], split = ",", description = ["""A list of DIMENSION=VALUE pairs which specify a target
|device to test against. This flag may be repeated to specify multiple devices. 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", defaultIosModel),
version = map.getOrDefault("version", defaultIosVersion),
locale = map.getOrDefault("locale", FtlConstants.defaultLocale),
orientation = map.getOrDefault("orientation", FtlConstants.defaultOrientation)
)

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

var device: MutableList<Device>? = null
}
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/config/FtlConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ object FtlConstants {

const val defaultLocale = "en"
const val defaultOrientation = "portrait"
const val defaultIosModel = "iphone8"
const val defaultIosVersion = "11.2"
const val defaultAndroidModel = "NexusLowRes"
const val defaultAndroidVersion = "28"
const val defaultIosConfig = "./flank.ios.yml"
Expand Down
43 changes: 43 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import ftl.args.yml.IosGcloudYml
import ftl.args.yml.IosGcloudYmlParams
import ftl.cli.firebase.test.ios.IosRunCommand
import ftl.config.Device
import ftl.config.FtlConstants.defaultIosModel
import ftl.config.FtlConstants.defaultIosVersion
import ftl.test.util.FlankTestRunner
import ftl.test.util.TestHelper.absolutePath
import ftl.test.util.TestHelper.assert
Expand Down Expand Up @@ -447,4 +449,45 @@ IosArgs
assertThat(IosArgs.load(yaml).xcodeVersion).isEqualTo("10.0")
assertThat(IosArgs.load(yaml, cli).xcodeVersion).isEqualTo("10.1")
}

@Test
fun cli_device() {
val cli = IosRunCommand()
CommandLine(cli).parse("--device=model=iphone8,version=12.0,locale=zh_CN,orientation=default")

val yaml = """
gcloud:
test: $testPath
xctestrun-file: $testPath
"""
val expectedDefaultDevice = Device(defaultIosModel, defaultIosVersion)
val defaultDevices = IosArgs.load(yaml).devices
assertThat(defaultDevices.first()).isEqualTo(expectedDefaultDevice)
assertThat(defaultDevices.size).isEqualTo(1)

val iosArgs = IosArgs.load(yaml, cli)
val expectedDevice = Device("iphone8", "12.0", "zh_CN", "default")
val actualDevices = iosArgs.devices
assertThat(actualDevices.first()).isEqualTo(expectedDevice)
assertThat(actualDevices.size).isEqualTo(1)
}

@Test
fun cli_device_repeat() {
val cli = IosRunCommand()
val deviceCmd = "--device=model=iphone8,version=12.0,locale=zh_CN,orientation=default"
CommandLine(cli).parse(deviceCmd, deviceCmd)

val yaml = """
gcloud:
test: $testPath
xctestrun-file: $testPath
"""
val iosArgs = IosArgs.load(yaml, cli)
val expectedDevice = Device("iphone8", "12.0", "zh_CN", "default")
val actualDevices = iosArgs.devices
assertThat(actualDevices.size).isEqualTo(2)
assertThat(actualDevices[0]).isEqualTo(expectedDevice)
assertThat(actualDevices[1]).isEqualTo(expectedDevice)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ftl.cli.firebase.test.ios

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
Expand Down Expand Up @@ -71,6 +72,7 @@ class IosRunCommandTest {
assertThat(cmd.test).isNull()
assertThat(cmd.xctestrunFile).isNull()
assertThat(cmd.xcodeVersion).isNull()
assertThat(cmd.device).isNull()
}

@Test
Expand Down Expand Up @@ -172,18 +174,28 @@ class IosRunCommandTest {
}

@Test
fun test_xctestrunFile() {
fun xctestrunFile_parse() {
val cmd = IosRunCommand()
CommandLine(cmd).parse("--xctestrun-file=a")

assertThat(cmd.xctestrunFile).isEqualTo("a")
}

@Test
fun test_xcodeVersion() {
fun xcodeVersion_parse() {
val cmd = IosRunCommand()
CommandLine(cmd).parse("--xcode-version=999")

assertThat(cmd.xcodeVersion).isEqualTo("999")
}

@Test
fun device_parse() {
val cmd = IosRunCommand()
CommandLine(cmd).parse("--device=model=iphone8,version=11.2,locale=zh_CN,orientation=default")

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

0 comments on commit 8381c90

Please sign in to comment.