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: Logging refactor - android/ios test environment #1896

Merged
merged 6 commits into from
May 7, 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
42 changes: 42 additions & 0 deletions test_runner/src/main/kotlin/ftl/adapter/GoogleTestEnvironment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ftl.adapter

import ftl.api.Locale
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
import ftl.api.fetchOrientation
import ftl.api.fetchSoftwareCatalog

object FetchGoogleTestEnvironmentAndroid :
TestEnvironment.Android.Fetch,
(String) -> TestEnvironment.Android by { projectId ->
TestEnvironment.Android(
osVersions = fetchAndroidOsVersion(projectId),
models = fetchDeviceModelAndroid(projectId),
locales = fetchLocales(Locale.Identity(projectId, Platform.ANDROID)),
softwareCatalog = fetchSoftwareCatalog(),
networkProfiles = fetchNetworkProfiles(),
orientations = fetchOrientation(projectId, Platform.ANDROID),
ipBlocks = fetchIpBlocks()
)
}

object FetchGoogleTestEnvironmentIos :
TestEnvironment.Ios.Fetch,
(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
34 changes: 34 additions & 0 deletions test_runner/src/main/kotlin/ftl/api/TestEnvironment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ftl.api

import com.google.testing.model.ProvidedSoftwareCatalog
import ftl.adapter.FetchGoogleTestEnvironmentAndroid
import ftl.adapter.FetchGoogleTestEnvironmentIos

val fetchAndroidTestEnvironment: TestEnvironment.Android.Fetch get() = FetchGoogleTestEnvironmentAndroid
val fetchIosTestEnvironment: TestEnvironment.Ios.Fetch get() = FetchGoogleTestEnvironmentIos

object TestEnvironment {
data class Android(
val osVersions: List<OsVersion.Android>,
val models: List<DeviceModel.Android>,
val locales: List<Locale>,
val softwareCatalog: ProvidedSoftwareCatalog,
val networkProfiles: List<NetworkProfile>,
val orientations: List<Orientation>,
val ipBlocks: List<IpBlock>
) {
interface Fetch : (String) -> Android
}

data class Ios(
val osVersions: List<OsVersion.Ios>,
val models: List<DeviceModel.Ios>,
val locales: List<Locale>,
val softwareCatalog: ProvidedSoftwareCatalog,
val networkProfiles: List<NetworkProfile>,
val orientations: List<Orientation>,
val ipBlocks: List<IpBlock>
) {
interface Fetch : (String) -> Ios
}
}
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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.toCliTable
import ftl.environment.ios.iosVersionsToCliTable
import ftl.gc.GcTesting
import ftl.http.executeWithRetry

Expand All @@ -21,7 +21,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,34 +1,14 @@
package ftl.domain

import flank.common.logLn
import ftl.api.Locale.Identity
import ftl.api.Platform
import ftl.api.fetchAndroidOsVersion
import ftl.api.fetchDeviceModelAndroid
import ftl.api.fetchIpBlocks
import ftl.api.fetchLocales
import ftl.api.fetchNetworkProfiles
import ftl.api.fetchOrientation
import ftl.api.fetchSoftwareCatalog
import ftl.api.fetchAndroidTestEnvironment
import ftl.args.AndroidArgs
import ftl.environment.android.toCliTable
import ftl.environment.common.toCliTable
import ftl.environment.toCliTable
import ftl.presentation.cli.firebase.test.locale.toCliTable
import ftl.presentation.Output
import java.nio.file.Paths

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

fun DescribeAndroidTestEnvironment.invoke() {
val projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project
// TODO move toCliTable() to presentation layer during refactor of presentation after #1728
logLn(fetchAndroidOsVersion(projectId).toCliTable())
logLn(fetchDeviceModelAndroid(projectId).toCliTable()) // TODO move toCliTable() to presentation layer during refactor of presentation after #1728
logLn(fetchLocales(Identity(projectId, Platform.ANDROID)).toCliTable())
logLn(fetchSoftwareCatalog().toCliTable())
logLn(fetchNetworkProfiles().toCliTable())
logLn(fetchOrientation(projectId, Platform.ANDROID).toCliTable()) // TODO move toCliTable() to presentation layer during refactor of presentation after #1728
logLn(fetchIpBlocks().toCliTable()) // TODO move toCliTable() to presentation layer during refactor of presentation after #1728
fetchAndroidTestEnvironment(AndroidArgs.loadOrDefault(Paths.get(configPath)).project).out()
}
Original file line number Diff line number Diff line change
@@ -1,33 +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.cli.firebase.test.locale.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
@@ -1,8 +1,12 @@
package ftl.presentation.cli.firebase.test.android

import ftl.api.TestEnvironment
import ftl.config.FtlConstants
import ftl.domain.DescribeAndroidTestEnvironment
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 AndroidTestEnvironmentCommand :
var usageHelpRequested: Boolean = false

override fun run() = invoke()

override val out = outputLogger {
when (this) {
is TestEnvironment.Android -> prepareOutputString()
else -> throwUnknownType()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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
import ftl.presentation.cli.firebase.test.locale.toCliTable

fun TestEnvironment.Android.prepareOutputString() = buildString {
appendLine(osVersions.toCliTable())
appendLine(models.toCliTable())
appendLine(locales.toCliTable())
appendLine(softwareCatalog.toCliTable())
appendLine(networkProfiles.toCliTable())
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()
}
}
}