diff --git a/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt b/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt index be1f2abfbf..f59b180974 100644 --- a/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt @@ -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 diff --git a/test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt b/test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt index 813cb82dc4..cbb934eaad 100644 --- a/test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt +++ b/test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt @@ -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 = emptyList(), - val device: List = listOf(Device("NexusLowRes", "28")) + val device: List = listOf(Device(defaultAndroidModel, defaultAndroidVersion)) ) { companion object : IYmlKeys { override val keys = listOf( 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 2b17086210..6259a71fe6 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 @@ -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? = 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?) { + 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? = null } diff --git a/test_runner/src/main/kotlin/ftl/config/Device.kt b/test_runner/src/main/kotlin/ftl/config/Device.kt index 6afa5be3eb..860b8aa1b1 100644 --- a/test_runner/src/main/kotlin/ftl/config/Device.kt +++ b/test_runner/src/main/kotlin/ftl/config/Device.kt @@ -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 { diff --git a/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt b/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt index bcd1bdd483..0130c3c867 100644 --- a/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt +++ b/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt @@ -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 = " " diff --git a/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt b/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt index 15c559e7ba..5a8fb30125 100644 --- a/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt @@ -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) + } } 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 be691bb7c9..ce4616b1a2 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 @@ -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) + } }