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

refactor: Structural output for iOS model list #1910

Merged
merged 2 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
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
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 @@ -14,6 +14,8 @@ object GoogleAndroidDeviceModel :

object GoogleIosDeviceModel :
DeviceModel.Ios.Fetch,
(String) -> List<DeviceModel.Ios> by { projectId ->
IosCatalog.getModels(projectId).toIosApiModel()
(String) -> DeviceModel.Ios.Available by { projectId ->
IosCatalog.getModels(projectId).toIosApiModel().available()
}

private fun List<DeviceModel.Ios>.available() = DeviceModel.Ios.Available(this)
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object FetchGoogleTestEnvironmentIos :
(String) -> TestEnvironment.Ios by { projectId ->
TestEnvironment.Ios(
osVersions = fetchIosOsVersion(projectId),
models = fetchDeviceModelIos(projectId),
models = fetchDeviceModelIos(projectId).list,
locales = fetchLocales(Locale.Identity(projectId, Platform.IOS)),
softwareCatalog = fetchSoftwareCatalog(),
networkProfiles = fetchNetworkProfiles(),
Expand Down
5 changes: 4 additions & 1 deletion test_runner/src/main/kotlin/ftl/api/DeviceModels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ object DeviceModel {
val deviceCapabilities: List<String>,
) {

interface Fetch : (String) -> List<Ios>
data class Available(
val list: List<Ios>
)
interface Fetch : (String) -> Available
}
}
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/ValidateIosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal fun isDeviceSupported(
modelId: String,
versionId: String,
projectId: String
) = fetchDeviceModelIos(projectId).find { it.id == modelId }?.supportedVersionIds?.contains(versionId) ?: false
) = fetchDeviceModelIos(projectId).list.find { it.id == modelId }?.supportedVersionIds?.contains(versionId) ?: false

private fun IosArgs.assertTestFiles() =
if (isXcTest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface DescribeIosModels : Output {
operator fun DescribeIosModels.invoke() {
if (modelId.isBlank()) throw FlankConfigurationError("Argument MODEL_ID must be specified.")
fetchDeviceModelIos(IosArgs.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/ListIosModels.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.fetchDeviceModelIos
import ftl.args.IosArgs
import ftl.environment.ios.toCliTable
import ftl.presentation.Output
import java.nio.file.Paths

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

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

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

fun List<DeviceModel.Ios>.toCliTable() = createTestEnvironmentInfo().createIoDevicesTable()

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

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

@CommandLine.Command(
Expand All @@ -26,6 +30,13 @@ class IosModelsListCommand :
)
override var configPath: String = FtlConstants.defaultIosConfig

override val out = outputLogger {
when (this) {
is DeviceModel.Ios.Available -> toCliTable()
else -> throwUnknownType()
}
}

@CommandLine.Option(
names = ["-h", "--help"],
usageHelp = true,
Expand Down