Skip to content

Commit

Permalink
Implement iOS part
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelpasterz committed May 6, 2021
1 parent 384c2dc commit b8a08cb
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 30 deletions.
14 changes: 13 additions & 1 deletion test_runner/src/main/kotlin/ftl/adapter/GoogleTestEnvironment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ftl.api.Platform
import ftl.api.TestEnvironment
import ftl.api.fetchAndroidOsVersion
import ftl.api.fetchDeviceModelAndroid
import ftl.api.fetchDeviceModelIos
import ftl.api.fetchIosOsVersion
import ftl.api.fetchIpBlocks
import ftl.api.fetchLocales
import ftl.api.fetchNetworkProfiles
Expand All @@ -27,4 +29,14 @@ object FetchGoogleTestEnvironmentAndroid :

object FetchGoogleTestEnvironmentIos :
TestEnvironment.Ios.Fetch,
(String) -> TestEnvironment.Ios by { TODO("Will be implemented in https://github.com/Flank/flank/issues/1851") }
(String) -> TestEnvironment.Ios by { projectId ->
TestEnvironment.Ios(
osVersions = fetchIosOsVersion(projectId),
models = fetchDeviceModelIos(projectId),
locales = fetchLocales(Locale.Identity(projectId, Platform.IOS)),
softwareCatalog = fetchSoftwareCatalog(),
networkProfiles = fetchNetworkProfiles(),
orientations = fetchOrientation(projectId, Platform.IOS),
ipBlocks = fetchIpBlocks(),
)
}
10 changes: 5 additions & 5 deletions test_runner/src/main/kotlin/ftl/api/OsVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ object OsVersion {
}

data class Ios(
val id: String,
val majorVersion: Int,
val minorVersion: Int,
val supportedXcodeVersionIds: List<String>,
val tags: List<String>,
val id: String?,
val majorVersion: Int?,
val minorVersion: Int?,
val supportedXcodeVersionIds: List<String>?,
val tags: List<String>?,
) {
interface Fetch : (String) -> List<Ios>
}
Expand Down
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.testing.model.Orientation
import ftl.config.Device
import ftl.environment.getLocaleDescription
import ftl.environment.ios.getDescription
import ftl.environment.ios.iosVersionsToCliTable
import ftl.environment.ios.toCliTable
import ftl.gc.GcTesting
import ftl.http.executeWithRetry
Expand All @@ -21,7 +22,7 @@ object IosCatalog {

fun getModels(projectId: String): List<IosModel> = iosDeviceCatalog(projectId).models.orEmpty()

fun softwareVersionsAsTable(projectId: String) = getVersionsList(projectId).toCliTable()
fun softwareVersionsAsTable(projectId: String) = getVersionsList(projectId).iosVersionsToCliTable()

fun describeSoftwareVersion(projectId: String, versionId: String) =
getVersionsList(projectId).getDescription(versionId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
package ftl.domain

import flank.common.logLn
import ftl.api.Locale.Identity
import ftl.api.Platform
import ftl.api.fetchDeviceModelIos
import ftl.api.fetchIpBlocks
import ftl.api.fetchLocales
import ftl.api.fetchNetworkProfiles
import ftl.api.fetchOrientation
import ftl.api.fetchSoftwareCatalog
import ftl.api.fetchIosTestEnvironment
import ftl.args.IosArgs
import ftl.client.google.IosCatalog
import ftl.environment.common.toCliTable
import ftl.environment.ios.toCliTable
import ftl.environment.toCliTable
import ftl.presentation.Output
import java.nio.file.Paths

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

operator fun DescribeIosTestEnvironment.invoke() {
val projectId = IosArgs.loadOrDefault(Paths.get(configPath)).project
logLn(fetchDeviceModelIos(projectId).toCliTable()) // TODO move toCliTable() and printing presentation layer during refactor of presentation after #1728
logLn(IosCatalog.softwareVersionsAsTable(projectId))
logLn(fetchLocales(Identity(projectId, Platform.IOS)).toCliTable())
logLn(fetchSoftwareCatalog().toCliTable())
logLn(fetchNetworkProfiles().toCliTable())
logLn(fetchOrientation(projectId, Platform.IOS).toCliTable()) // TODO move toCliTable() and printing presentation layer during refactor of presentation after #1728
logLn(fetchIpBlocks().toCliTable()) // TODO move toCliTable() and printing presentation layer during refactor of presentation after #1728
fetchIosTestEnvironment(projectId).out()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.environment.ios

import com.google.testing.model.IosVersion
import ftl.api.OsVersion
import ftl.environment.OS_VERSION_ID
import ftl.environment.TAGS
import ftl.environment.TestEnvironmentInfo
Expand All @@ -11,9 +12,23 @@ import ftl.environment.tagToSystemOutColorMapper
import ftl.util.applyColorsUsing
import ftl.util.buildTable

fun List<IosVersion>.toCliTable() = createTestEnvironmentInfo().createIOsSoftwareVersionsTable()
fun List<OsVersion.Ios>.toCliTable() = createTestEnvironmentInfo().createIOsSoftwareVersionsTable()

private fun List<IosVersion>.createTestEnvironmentInfo() =
private fun List<OsVersion.Ios>.createTestEnvironmentInfo() =
fold(mutableMapOf<String, MutableList<String>>()) { softwareInfo, softwareVersion ->
softwareInfo.apply {
getOrCreateList(OS_VERSION_ID).add(softwareVersion.id.orUnknown())
getOrCreateList(MAJOR_VERSION).add(softwareVersion.majorVersion?.toString().orUnknown())
getOrCreateList(MINOR_VERSION).add(softwareVersion.minorVersion?.toString().orUnknown())
getOrCreateList(TAGS).add(softwareVersion.tags.orEmpty().joinToString())
getOrCreateList(SUPPORTED_XCODE_VERSION_IDS).add(softwareVersion.supportedXcodeVersionIds.orEmpty().joinToString())
}
}

// todo code duplicated for backward compatibility -- will be removed in one of future refactor tasks
fun List<IosVersion>.iosVersionsToCliTable() = createTestEnvironmentInfoFromIosVersions().createIOsSoftwareVersionsTable()

private fun List<IosVersion>.createTestEnvironmentInfoFromIosVersions() =
fold(mutableMapOf<String, MutableList<String>>()) { softwareInfo, softwareVersion ->
softwareInfo.apply {
getOrCreateList(OS_VERSION_ID).add(softwareVersion.id.orUnknown())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ftl.presentation.cli.firebase.test.environment
import ftl.api.TestEnvironment
import ftl.environment.android.toCliTable
import ftl.environment.common.toCliTable
import ftl.environment.ios.toCliTable
import ftl.environment.toCliTable

fun TestEnvironment.Android.prepareOutputString() = buildString {
Expand All @@ -14,3 +15,13 @@ fun TestEnvironment.Android.prepareOutputString() = buildString {
appendLine(orientations.toCliTable())
appendLine(ipBlocks.toCliTable())
}

fun TestEnvironment.Ios.prepareOutputString() = buildString {
appendLine(osVersions.toCliTable())
appendLine(models.toCliTable())
appendLine(locales.toCliTable())
appendLine(softwareCatalog.toCliTable())
appendLine(networkProfiles.toCliTable())
appendLine(orientations.toCliTable())
appendLine(ipBlocks.toCliTable())
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package ftl.presentation.cli.firebase.test.ios

import ftl.api.TestEnvironment
import ftl.config.FtlConstants
import ftl.domain.DescribeIosTestEnvironment
import ftl.domain.invoke
import ftl.presentation.cli.firebase.test.environment.prepareOutputString
import ftl.presentation.outputLogger
import ftl.presentation.throwUnknownType
import picocli.CommandLine

@CommandLine.Command(
Expand Down Expand Up @@ -40,4 +44,11 @@ class IosTestEnvironmentCommand :
var usageHelpRequested: Boolean = false

override fun run() = invoke()

override val out = outputLogger {
when (this) {
is TestEnvironment.Ios -> prepareOutputString()
else -> throwUnknownType()
}
}
}

0 comments on commit b8a08cb

Please sign in to comment.