Skip to content

Commit

Permalink
refactor: Refactor data scratch-orientation (#1820)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotradamczyk5 authored Apr 20, 2021
1 parent 3b3bb5a commit e4c9e25
Show file tree
Hide file tree
Showing 33 changed files with 178 additions and 52 deletions.
16 changes: 16 additions & 0 deletions test_runner/src/main/kotlin/ftl/adapter/GoogleOrientationFetch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ftl.adapter

import ftl.adapter.google.toApiModel
import ftl.api.Orientation
import ftl.api.Platform
import ftl.client.google.AndroidCatalog
import ftl.ios.IosCatalog

object GoogleOrientationFetch :
Orientation.Fetch,
(String, Platform) -> List<Orientation> by { projectId, platform ->
when (platform) {
Platform.ANDROID -> AndroidCatalog.supportedOrientations(projectId).toApiModel()
Platform.IOS -> IosCatalog.supportedOrientations(projectId).toApiModel()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ftl.adapter.google

import ftl.api.Orientation
import com.google.testing.model.Orientation as GoogleApiOrientation

internal fun List<GoogleApiOrientation>.toApiModel(): List<Orientation> = map { googleApiOrientation ->
Orientation(
id = googleApiOrientation.id ?: UNABLE,
name = googleApiOrientation.name ?: UNABLE,
tags = googleApiOrientation.tags ?: emptyList()
)
}

private const val UNABLE = "[Unable to fetch]"
18 changes: 18 additions & 0 deletions test_runner/src/main/kotlin/ftl/api/Orientation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ftl.api

import ftl.adapter.GoogleOrientationFetch

val fetchOrientation: Orientation.Fetch get() = GoogleOrientationFetch

data class Orientation(
val id: String,
val name: String,
val tags: List<String>,
) {
interface Fetch : (String, Platform) -> List<Orientation>
}

enum class Platform {
ANDROID,
IOS
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ftl.args

import ftl.android.AndroidCatalog
import ftl.client.google.AndroidCatalog
import ftl.config.AndroidConfig
import ftl.config.Device
import ftl.config.containsPhysicalDevices
Expand Down
12 changes: 6 additions & 6 deletions test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ftl.args

import flank.common.logLn
import ftl.android.AndroidCatalog
import ftl.android.AndroidCatalog.getSupportedVersionId
import ftl.android.IncompatibleModelVersion
import ftl.android.SupportedDeviceConfig
import ftl.android.UnsupportedModelId
import ftl.android.UnsupportedVersionId
import ftl.args.yml.Type
import ftl.client.google.AndroidCatalog
import ftl.client.google.AndroidCatalog.getSupportedVersionId
import ftl.client.google.IncompatibleModelVersion
import ftl.client.google.SupportedDeviceConfig
import ftl.client.google.UnsupportedModelId
import ftl.client.google.UnsupportedVersionId
import ftl.config.containsPhysicalDevices
import ftl.config.containsVirtualDevices
import ftl.run.exception.FlankConfigurationError
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package ftl.android
package ftl.client.google

import com.google.testing.model.AndroidDevice
import com.google.testing.model.AndroidDeviceCatalog
import com.google.testing.model.Orientation
import flank.common.logLn
import ftl.config.Device
import ftl.environment.android.asPrintableTable
import ftl.environment.android.getDescription
import ftl.environment.android.toCliTable
import ftl.environment.asPrintableTable
import ftl.environment.common.asPrintableTable
import ftl.environment.common.toCliTable
import ftl.environment.getLocaleDescription
import ftl.gc.GcTesting
import ftl.http.executeWithRetry
Expand All @@ -29,7 +30,7 @@ object AndroidCatalog {
.androidDeviceCatalog
}

fun devicesCatalogAsTable(projectId: String) = getModels(projectId).asPrintableTable()
fun devicesCatalogAsTable(projectId: String) = getModels(projectId).toCliTable()

fun describeModel(projectId: String, modelId: String) = getModels(projectId).getDescription(modelId)

Expand All @@ -38,13 +39,13 @@ object AndroidCatalog {
fun Device.getSupportedVersionId(projectId: String): List<String> = getModels(projectId).find { it.id == model }?.supportedVersionIds
?: emptyList()

fun supportedVersionsAsTable(projectId: String) = getVersionsList(projectId).asPrintableTable()
fun supportedVersionsAsTable(projectId: String) = getVersionsList(projectId).toCliTable()

fun describeSoftwareVersion(projectId: String, versionId: String) = getVersionsList(projectId).getDescription(versionId)

private fun getVersionsList(projectId: String) = deviceCatalog(projectId).versions

fun supportedOrientationsAsTable(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.orientations.asPrintableTable()
fun supportedOrientations(projectId: String): List<Orientation> = deviceCatalog(projectId).runtimeConfiguration.orientations

fun localesAsTable(projectId: String) = getLocales(projectId).asPrintableTable()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ftl.domain

import flank.common.log
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.client.google.AndroidCatalog
import ftl.run.exception.FlankConfigurationError
import java.nio.file.Paths

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ftl.domain

import flank.common.logLn
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.client.google.AndroidCatalog
import ftl.run.exception.FlankConfigurationError
import java.nio.file.Paths

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package ftl.domain

import flank.common.logLn
import ftl.android.AndroidCatalog
import ftl.api.Platform
import ftl.api.fetchIpBlocks
import ftl.api.fetchOrientation
import ftl.args.AndroidArgs
import ftl.client.google.AndroidCatalog
import ftl.environment.common.toCliTable
import ftl.environment.networkConfigurationAsTable
import ftl.environment.providedSoftwareAsTable
import ftl.environment.toCliTable
Expand All @@ -20,7 +23,7 @@ fun DescribeAndroidTestEnvironment.invoke() {
logLn(AndroidCatalog.localesAsTable(projectId))
logLn(providedSoftwareAsTable())
logLn(networkConfigurationAsTable())
logLn(AndroidCatalog.supportedOrientationsAsTable(projectId))
// TODO move toCliTable() to presentation layer during refactor of presentation after #1728
logLn(fetchOrientation(projectId, Platform.ANDROID).toCliTable())
logLn(fetchIpBlocks().toCliTable())
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ftl.domain

import flank.common.logLn
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.client.google.AndroidCatalog
import ftl.run.exception.FlankConfigurationError
import java.nio.file.Paths

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package ftl.domain

import flank.common.logLn
import ftl.api.Platform
import ftl.api.fetchIpBlocks
import ftl.api.fetchOrientation
import ftl.args.IosArgs
import ftl.environment.common.toCliTable
import ftl.environment.networkConfigurationAsTable
import ftl.environment.providedSoftwareAsTable
import ftl.environment.toCliTable
Expand All @@ -20,7 +23,7 @@ operator fun DescribeIosTestEnvironment.invoke() {
logLn(IosCatalog.localesAsTable(projectId))
logLn(providedSoftwareAsTable())
logLn(networkConfigurationAsTable())
logLn(IosCatalog.supportedOrientationsAsTable(projectId))
// TODO move toCliTable() and printing presentation layer during refactor of presentation after #1728
logLn(fetchOrientation(projectId, Platform.IOS).toCliTable())
logLn(fetchIpBlocks().toCliTable())
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ftl.domain

import flank.common.logLn
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.client.google.AndroidCatalog
import java.nio.file.Paths

interface ListAndroidLocales {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ftl.domain

import flank.common.logLn
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.client.google.AndroidCatalog
import java.nio.file.Paths

interface ListAndroidModels {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package ftl.domain

import flank.common.logLn
import ftl.android.AndroidCatalog
import ftl.api.Platform
import ftl.api.fetchOrientation
import ftl.args.AndroidArgs
import ftl.environment.common.toCliTable
import java.nio.file.Paths

interface ListAndroidOrientations {
val configPath: String
}

operator fun ListAndroidOrientations.invoke() {
logLn(AndroidCatalog.supportedOrientationsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project))
logLn(
fetchOrientation(
AndroidArgs.loadOrDefault(Paths.get(configPath)).project,
Platform.ANDROID
).toCliTable()
)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ftl.domain

import flank.common.logLn
import ftl.android.AndroidCatalog
import ftl.args.AndroidArgs
import ftl.client.google.AndroidCatalog
import java.nio.file.Paths

interface ListAndroidVersions {
Expand Down
12 changes: 10 additions & 2 deletions test_runner/src/main/kotlin/ftl/domain/ListIosOrientations.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package ftl.domain

import flank.common.logLn
import ftl.api.Platform
import ftl.api.fetchOrientation
import ftl.args.IosArgs
import ftl.ios.IosCatalog
import ftl.environment.common.toCliTable
import java.nio.file.Paths

interface ListIosOrientations {
var configPath: String
}

operator fun ListIosOrientations.invoke() {
logLn(IosCatalog.supportedOrientationsAsTable(IosArgs.loadOrDefault(Paths.get(configPath)).project))
// TODO move toCliTable() to presentation layer during refactor of presentation after #1728
logLn(
fetchOrientation(
IosArgs.loadOrDefault(Paths.get(configPath)).project,
Platform.IOS
).toCliTable()
)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ftl.environment

import ftl.environment.common.asPrintableTable
import ftl.environment.common.toCliTable
import ftl.gc.GcTesting
import ftl.http.executeWithRetry

fun networkConfigurationAsTable() = getNetworkConfiguration().asPrintableTable()
fun networkConfigurationAsTable() = getNetworkConfiguration().toCliTable()

fun getNetworkConfiguration() = GcTesting.get.testEnvironmentCatalog()
.get("NETWORK_CONFIGURATION")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ftl.util.SystemOutColor
import ftl.util.applyColorsUsing
import ftl.util.buildTable

fun List<AndroidModel>.asPrintableTable() = createTestEnvironmentInfo().createAndroidDevicesTable()
fun List<AndroidModel>.toCliTable() = createTestEnvironmentInfo().createAndroidDevicesTable()

private fun List<AndroidModel>.createTestEnvironmentInfo() =
fold(mutableMapOf<String, MutableList<String>>()) { devicesInfo, androidDevice ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ftl.reports.api.twoDigitString
import ftl.util.applyColorsUsing
import ftl.util.buildTable

fun List<AndroidVersion>.asPrintableTable() = createTestEnvironmentInfo().createAndroidSoftwareVersionsTable()
fun List<AndroidVersion>.toCliTable() = createTestEnvironmentInfo().createAndroidSoftwareVersionsTable()

private fun List<AndroidVersion>.createTestEnvironmentInfo() =
fold(mutableMapOf<String, MutableList<String>>()) { softwareInfo, softwareVersion ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ftl.environment.getOrCreateList
import ftl.util.TableStyle
import ftl.util.buildTable

fun List<NetworkConfiguration>.asPrintableTable() = createConfigurationDetails().createConfigurationsTable()
fun List<NetworkConfiguration>.toCliTable() = createConfigurationDetails().createConfigurationsTable()

private fun List<NetworkConfiguration>.createConfigurationDetails() = fold(mutableMapOf<String, MutableList<String>>()) { networkInfo, networkConfiguration ->
networkInfo.apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package ftl.environment.common

import com.google.testing.model.Orientation
import ftl.api.Orientation
import ftl.environment.TestEnvironmentInfo
import ftl.environment.createTableColumnFor
import ftl.environment.getOrCreateList
import ftl.environment.tagToSystemOutColorMapper
import ftl.util.applyColorsUsing
import ftl.util.buildTable

fun List<Orientation>.asPrintableTable() = createOrientationsDetails().createOrientationsTable()
fun List<Orientation>.toCliTable() = createOrientationsDetails().createOrientationsTable()

private fun List<Orientation>.createOrientationsDetails() = fold(mutableMapOf<String, MutableList<String>>()) { orientationInfo, orientation ->
orientationInfo.apply {
getOrCreateList(ORIENTATION_ID).add(orientation.id.orEmpty())
getOrCreateList(NAME).add(orientation.name.orEmpty())
getOrCreateList(TAG).add(orientation.tags?.joinToString(TAG_SEPARATOR).orEmpty())
getOrCreateList(ORIENTATION_ID).add(orientation.id)
getOrCreateList(NAME).add(orientation.name)
getOrCreateList(TAG).add(orientation.tags.joinToString(TAG_SEPARATOR))
}
}

Expand Down
6 changes: 3 additions & 3 deletions test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package ftl.ios

import com.google.testing.model.IosDeviceCatalog
import com.google.testing.model.Orientation
import ftl.config.Device
import ftl.environment.asPrintableTable
import ftl.environment.common.asPrintableTable
import ftl.environment.getLocaleDescription
import ftl.environment.ios.asPrintableTable
import ftl.environment.ios.getDescription
Expand Down Expand Up @@ -38,8 +38,8 @@ object IosCatalog {

private fun getLocales(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales

fun supportedOrientationsAsTable(projectId: String) =
iosDeviceCatalog(projectId).runtimeConfiguration.orientations.asPrintableTable()
fun supportedOrientations(projectId: String): List<Orientation> =
iosDeviceCatalog(projectId).runtimeConfiguration.orientations

fun supportedXcode(version: String, projectId: String) = xcodeVersions(projectId).contains(version)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ftl.reports.api

import com.google.api.services.toolresults.model.PerfMetricsSummary
import com.google.testing.model.TestExecution
import ftl.android.AndroidCatalog
import ftl.args.IArgs
import ftl.client.google.AndroidCatalog
import ftl.gc.GcStorage
import ftl.gc.GcToolResults
import kotlinx.coroutines.Dispatchers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ftl.reports.outcome

import com.google.api.services.toolresults.model.Step
import ftl.android.AndroidCatalog
import ftl.android.DeviceType
import ftl.client.google.AndroidCatalog
import ftl.client.google.DeviceType
import ftl.environment.orUnknown
import ftl.util.billableMinutes
import kotlin.math.min
Expand Down
Loading

0 comments on commit e4c9e25

Please sign in to comment.