Skip to content

Commit

Permalink
added initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfilipow92 authored and mergify-bot committed May 10, 2021
1 parent 5f570cd commit 08291e0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 13 deletions.
6 changes: 4 additions & 2 deletions test_runner/src/main/kotlin/ftl/adapter/GoogleDeviceModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import ftl.client.google.IosCatalog

object GoogleAndroidDeviceModel :
DeviceModel.Android.Fetch,
(String) -> List<DeviceModel.Android> by { projectId ->
AndroidCatalog.getModels(projectId).toAndroidApiModel()
(String) -> DeviceModel.Android.Available by { projectId ->
AndroidCatalog.getModels(projectId).toAndroidApiModel().available()
}

private fun List<DeviceModel.Android>.available() = DeviceModel.Android.Available(this)

object GoogleIosDeviceModel :
DeviceModel.Ios.Fetch,
(String) -> List<DeviceModel.Ios> by { projectId ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object FetchGoogleTestEnvironmentAndroid :
(String) -> TestEnvironment.Android by { projectId ->
TestEnvironment.Android(
osVersions = fetchAndroidOsVersion(projectId),
models = fetchDeviceModelAndroid(projectId),
models = fetchDeviceModelAndroid(projectId).list,
locales = fetchLocales(Locale.Identity(projectId, Platform.ANDROID)),
softwareCatalog = fetchSoftwareCatalog(),
networkProfiles = fetchNetworkProfiles(),
Expand Down
6 changes: 4 additions & 2 deletions test_runner/src/main/kotlin/ftl/api/DeviceModels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ object DeviceModel {
val supportedAbis: List<String>,
val lowFpsVideoRecording: Boolean,
) {

interface Fetch : (String) -> List<Android>
data class Available(
val list: List<Android>
)
interface Fetch : (String) -> Available
}

data class Ios(
Expand Down
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private fun AndroidArgs.assertDevicesSupported() = devices

@VisibleForTesting
internal fun supportedDeviceConfig(modelId: String, versionId: String, projectId: String): DeviceConfigCheck {
val foundModel = fetchDeviceModelAndroid(projectId).find { it.id == modelId } ?: return UnsupportedModelId
val foundModel = fetchDeviceModelAndroid(projectId).list.find { it.id == modelId } ?: return UnsupportedModelId
if (!AndroidCatalog.androidVersionIds(projectId).contains(versionId)) return UnsupportedVersionId
if (!foundModel.supportedVersionIds.contains(versionId)) return IncompatibleModelVersion

Expand All @@ -131,7 +131,7 @@ internal fun supportedDeviceConfig(modelId: String, versionId: String, projectId

fun Device.getSupportedVersionId(
projectId: String
): List<String> = fetchDeviceModelAndroid(projectId).find { it.id == model }?.supportedVersionIds.orEmpty()
): List<String> = fetchDeviceModelAndroid(projectId).list.find { it.id == model }?.supportedVersionIds.orEmpty()

private fun AndroidArgs.assertShards() {
if (numUniformShards != null && maxTestShards > 1) throw FlankConfigurationError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface DescribeAndroidModels : Output {
operator fun DescribeAndroidModels.invoke() {
if (modelId.isBlank()) throw FlankConfigurationError("Argument MODEL_ID must be specified.")
fetchDeviceModelAndroid(AndroidArgs.loadOrDefault(Paths.get(configPath)).project)
.list
.find { it.id == modelId }
?.out()
?: throw FlankGeneralError("ERROR: '$modelId' is not a valid model")
Expand Down
8 changes: 3 additions & 5 deletions test_runner/src/main/kotlin/ftl/domain/ListAndroidModels.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package ftl.domain

import flank.common.logLn
import ftl.api.fetchDeviceModelAndroid
import ftl.args.AndroidArgs
import ftl.environment.android.toCliTable
import ftl.presentation.Output
import java.nio.file.Paths

interface ListAndroidModels {
interface ListAndroidModels : Output {
val configPath: String
}

operator fun ListAndroidModels.invoke() {
// TODO move toCliTable() and printing presentation layer during refactor of presentation after #1728
logLn(fetchDeviceModelAndroid(AndroidArgs.loadOrDefault(Paths.get(configPath)).project).toCliTable())
fetchDeviceModelAndroid(AndroidArgs.loadOrDefault(Paths.get(configPath)).project).out()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import ftl.util.SystemOutColor
import ftl.util.applyColorsUsing
import ftl.util.buildTable

fun DeviceModel.Android.Available.toCliTable() = list.toCliTable()

fun List<DeviceModel.Android>.toCliTable() = createTestEnvironmentInfo().createAndroidDevicesTable()

private fun List<DeviceModel.Android>.createTestEnvironmentInfo() =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package ftl.presentation.cli.firebase.test.android.models

import ftl.api.DeviceModel
import ftl.config.FtlConstants
import ftl.domain.ListAndroidModels
import ftl.domain.invoke
import ftl.environment.android.toCliTable
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import picocli.CommandLine

@CommandLine.Command(
Expand All @@ -25,6 +29,12 @@ class AndroidModelsListCommand :
description = ["YAML config file path"]
)
override var configPath: String = FtlConstants.defaultAndroidConfig
override val out = outputLogger {
when (this) {
is DeviceModel.Android.Available -> toCliTable()
else -> throwUnknownType()
}
}

@CommandLine.Option(
names = ["-h", "--help"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AndroidCatalogTest {
val expectedSeparatorCount = expectedHeaders.size + 1

// when
val devicesTable = fetchDeviceModelAndroid(projectId).toCliTable()
val devicesTable = fetchDeviceModelAndroid(projectId).list.toCliTable()
val headers = devicesTable.lines()[1]

// then
Expand Down

0 comments on commit 08291e0

Please sign in to comment.