From 81b137708dfa178505f4b83f79b4261189ab7177 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 20 Apr 2021 15:39:35 +0200 Subject: [PATCH 1/7] Create OsVersion.kt --- .../src/main/kotlin/ftl/data/OsVersion.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test_runner/src/main/kotlin/ftl/data/OsVersion.kt diff --git a/test_runner/src/main/kotlin/ftl/data/OsVersion.kt b/test_runner/src/main/kotlin/ftl/data/OsVersion.kt new file mode 100644 index 0000000000..8b7ec7cde8 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/data/OsVersion.kt @@ -0,0 +1,36 @@ +package ftl.data + +val fetchAndroidOsVersion: OsVersion.Android.Fetch get() = TODO() +val fetchIosOsVersion: OsVersion.Ios.Fetch get() = TODO() + +object OsVersion { + + data class Android( + val apiLevel: Int, + val codeName: String, + val distribution: Distribution, + val id: String, + val releaseDate: Date, + val tags: List, + val versionString: String, + ) { + interface Fetch : (String) -> List + } + + data class Ios( + val id: String, + val majorVersion: Int, + val minorVersion: Int, + val supportedXcodeVersionIds: List, + val tags: List, + ) { + interface Fetch : (String) -> List + } +} + +data class Distribution( + val marketShare: Double, + val measurementTime: String, +) + +data class Date(val day: Int, val month: Int, val year: Int) From 30fada5f9bfc1999a2424d1b323344fa79f4028c Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 21 Apr 2021 18:35:47 +0200 Subject: [PATCH 2/7] Refactored os versions --- .../ftl/adapter/AndroidOsVersionsFetch.kt | 11 ++++++ .../kotlin/ftl/adapter/IosVersionsFetch.kt | 11 ++++++ .../ftl/adapter/google/AndroidOsVersions.kt | 24 ++++++++++++ .../ftl/adapter/google/IosOsVersions.kt | 10 +++++ .../main/kotlin/ftl/android/AndroidCatalog.kt | 22 ++++++----- .../src/main/kotlin/ftl/api/OsVersion.kt | 39 +++++++++++++++++++ .../kotlin/ftl/client/google/OsVersion.kt | 24 ++++++++++++ .../src/main/kotlin/ftl/data/OsVersion.kt | 36 ----------------- .../domain/DescribeAndroidTestEnvironment.kt | 5 ++- .../kotlin/ftl/domain/ListAndroidVersions.kt | 6 ++- .../environment/android/ListAndroidDevices.kt | 2 +- .../android/ListAndroidSofwareVersions.kt | 8 ++-- .../kotlin/ftl/android/AndroidCatalogTest.kt | 4 +- 13 files changed, 148 insertions(+), 54 deletions(-) create mode 100644 test_runner/src/main/kotlin/ftl/adapter/AndroidOsVersionsFetch.kt create mode 100644 test_runner/src/main/kotlin/ftl/adapter/IosVersionsFetch.kt create mode 100644 test_runner/src/main/kotlin/ftl/adapter/google/AndroidOsVersions.kt create mode 100644 test_runner/src/main/kotlin/ftl/adapter/google/IosOsVersions.kt create mode 100644 test_runner/src/main/kotlin/ftl/api/OsVersion.kt create mode 100644 test_runner/src/main/kotlin/ftl/client/google/OsVersion.kt delete mode 100644 test_runner/src/main/kotlin/ftl/data/OsVersion.kt diff --git a/test_runner/src/main/kotlin/ftl/adapter/AndroidOsVersionsFetch.kt b/test_runner/src/main/kotlin/ftl/adapter/AndroidOsVersionsFetch.kt new file mode 100644 index 0000000000..3e173c5fc1 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/adapter/AndroidOsVersionsFetch.kt @@ -0,0 +1,11 @@ +package ftl.adapter + +import ftl.adapter.google.toApiModel +import ftl.api.OsVersion +import ftl.client.google.androidOsVersions + +object AndroidOsVersionsFetch : + OsVersion.Android.Fetch, + (String) -> List by { + androidOsVersions(it).toApiModel() + } diff --git a/test_runner/src/main/kotlin/ftl/adapter/IosVersionsFetch.kt b/test_runner/src/main/kotlin/ftl/adapter/IosVersionsFetch.kt new file mode 100644 index 0000000000..69a298ccdb --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/adapter/IosVersionsFetch.kt @@ -0,0 +1,11 @@ +package ftl.adapter + +import ftl.adapter.google.toApiModel +import ftl.api.OsVersion +import ftl.client.google.iosOsVersions + +object IosVersionsFetch : + OsVersion.Ios.Fetch, + (String) -> List by { + iosOsVersions(it).toApiModel() + } diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/AndroidOsVersions.kt b/test_runner/src/main/kotlin/ftl/adapter/google/AndroidOsVersions.kt new file mode 100644 index 0000000000..05ab1cd2f6 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/adapter/google/AndroidOsVersions.kt @@ -0,0 +1,24 @@ +package ftl.adapter.google + +import com.google.testing.model.AndroidVersion +import com.google.testing.model.Distribution +import ftl.api.Date +import ftl.api.OsVersion + +fun List.toApiModel() = map { + it.toApiModel() +} + +private fun AndroidVersion.toApiModel() = OsVersion.Android( + apiLevel, + codeName, + distribution?.toApiModel(), + id, + releaseDate?.toApiModel(), + tags, + versionString +) + +private fun Distribution.toApiModel() = ftl.api.Distribution(marketShare, measurementTime) + +private fun com.google.testing.model.Date.toApiModel() = Date(day, month, year) diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/IosOsVersions.kt b/test_runner/src/main/kotlin/ftl/adapter/google/IosOsVersions.kt new file mode 100644 index 0000000000..1c1cdd61de --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/adapter/google/IosOsVersions.kt @@ -0,0 +1,10 @@ +package ftl.adapter.google + +import com.google.testing.model.IosVersion +import ftl.api.OsVersion + +fun List.toApiModel() = map { + it.toApiModel() +} + +private fun IosVersion.toApiModel() = OsVersion.Ios(id, majorVersion, minorVersion, supportedXcodeVersionIds, tags) diff --git a/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt b/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt index 9e13df92be..ea6c7ab9a9 100644 --- a/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt @@ -4,8 +4,8 @@ import com.google.testing.model.AndroidDevice import com.google.testing.model.AndroidDeviceCatalog 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.getLocaleDescription @@ -29,22 +29,23 @@ 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) private fun getModels(projectId: String) = deviceCatalog(projectId).models - fun Device.getSupportedVersionId(projectId: String): List = getModels(projectId).find { it.id == model }?.supportedVersionIds - ?: emptyList() + fun Device.getSupportedVersionId(projectId: String): List = + getModels(projectId).find { it.id == model }?.supportedVersionIds + ?: emptyList() - fun supportedVersionsAsTable(projectId: String) = getVersionsList(projectId).asPrintableTable() - - fun describeSoftwareVersion(projectId: String, versionId: String) = getVersionsList(projectId).getDescription(versionId) + 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 supportedOrientationsAsTable(projectId: String) = + deviceCatalog(projectId).runtimeConfiguration.orientations.asPrintableTable() fun localesAsTable(projectId: String) = getLocales(projectId).asPrintableTable() @@ -81,7 +82,10 @@ object AndroidCatalog { logLn("Unable to find device type for $modelId. PHYSICAL used as fallback in cost calculations") } - return form.equals(DeviceType.VIRTUAL.name, ignoreCase = true) || form.equals(DeviceType.EMULATOR.name, ignoreCase = true) + return form.equals(DeviceType.VIRTUAL.name, ignoreCase = true) || form.equals( + DeviceType.EMULATOR.name, + ignoreCase = true + ) } } diff --git a/test_runner/src/main/kotlin/ftl/api/OsVersion.kt b/test_runner/src/main/kotlin/ftl/api/OsVersion.kt new file mode 100644 index 0000000000..65dd51327e --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/api/OsVersion.kt @@ -0,0 +1,39 @@ +package ftl.api + +import ftl.adapter.AndroidOsVersionsFetch +import ftl.adapter.IosVersionsFetch + +val fetchAndroidOsVersion: OsVersion.Android.Fetch get() = AndroidOsVersionsFetch +val fetchIosOsVersion: OsVersion.Ios.Fetch get() = IosVersionsFetch + +object OsVersion { + + data class Android( + val apiLevel: Int?, + val codeName: String?, + val distribution: Distribution?, + val id: String?, + val releaseDate: Date?, + val tags: List?, + val versionString: String?, + ) { + interface Fetch : (String) -> List + } + + data class Ios( + val id: String, + val majorVersion: Int, + val minorVersion: Int, + val supportedXcodeVersionIds: List, + val tags: List, + ) { + interface Fetch : (String) -> List + } +} + +data class Distribution( + val marketShare: Double, + val measurementTime: String, +) + +data class Date(val day: Int?, val month: Int?, val year: Int?) diff --git a/test_runner/src/main/kotlin/ftl/client/google/OsVersion.kt b/test_runner/src/main/kotlin/ftl/client/google/OsVersion.kt new file mode 100644 index 0000000000..943b979d6c --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/client/google/OsVersion.kt @@ -0,0 +1,24 @@ +package ftl.client.google + +import com.google.testing.model.AndroidVersion +import com.google.testing.model.IosVersion +import ftl.gc.GcTesting +import ftl.http.executeWithRetry + +fun androidOsVersions(projectId: String): List = + GcTesting.get.testEnvironmentCatalog() + .get("android") + .setProjectId(projectId) + .executeWithRetry() + .androidDeviceCatalog + .versions + .orEmpty() + +fun iosOsVersions(projectId: String): List = + GcTesting.get.testEnvironmentCatalog() + .get("ios") + .setProjectId(projectId) + .executeWithRetry() + .iosDeviceCatalog + .versions + .orEmpty() diff --git a/test_runner/src/main/kotlin/ftl/data/OsVersion.kt b/test_runner/src/main/kotlin/ftl/data/OsVersion.kt deleted file mode 100644 index 8b7ec7cde8..0000000000 --- a/test_runner/src/main/kotlin/ftl/data/OsVersion.kt +++ /dev/null @@ -1,36 +0,0 @@ -package ftl.data - -val fetchAndroidOsVersion: OsVersion.Android.Fetch get() = TODO() -val fetchIosOsVersion: OsVersion.Ios.Fetch get() = TODO() - -object OsVersion { - - data class Android( - val apiLevel: Int, - val codeName: String, - val distribution: Distribution, - val id: String, - val releaseDate: Date, - val tags: List, - val versionString: String, - ) { - interface Fetch : (String) -> List - } - - data class Ios( - val id: String, - val majorVersion: Int, - val minorVersion: Int, - val supportedXcodeVersionIds: List, - val tags: List, - ) { - interface Fetch : (String) -> List - } -} - -data class Distribution( - val marketShare: Double, - val measurementTime: String, -) - -data class Date(val day: Int, val month: Int, val year: Int) diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt index a0ccc1ca65..5ddebf5bf1 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt @@ -2,8 +2,10 @@ package ftl.domain import flank.common.logLn import ftl.android.AndroidCatalog +import ftl.api.fetchAndroidOsVersion import ftl.api.fetchIpBlocks import ftl.args.AndroidArgs +import ftl.environment.android.toCliTable import ftl.environment.networkConfigurationAsTable import ftl.environment.providedSoftwareAsTable import ftl.environment.toCliTable @@ -16,7 +18,8 @@ interface DescribeAndroidTestEnvironment { fun DescribeAndroidTestEnvironment.invoke() { val projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project logLn(AndroidCatalog.devicesCatalogAsTable(projectId)) - logLn(AndroidCatalog.supportedVersionsAsTable(projectId)) + // TODO move toCliTable() to presentation layer during refactor of presentation after #1728 + logLn(fetchAndroidOsVersion(projectId).toCliTable()) logLn(AndroidCatalog.localesAsTable(projectId)) logLn(providedSoftwareAsTable()) logLn(networkConfigurationAsTable()) diff --git a/test_runner/src/main/kotlin/ftl/domain/ListAndroidVersions.kt b/test_runner/src/main/kotlin/ftl/domain/ListAndroidVersions.kt index 0bfb3219c0..3f8ba0482d 100644 --- a/test_runner/src/main/kotlin/ftl/domain/ListAndroidVersions.kt +++ b/test_runner/src/main/kotlin/ftl/domain/ListAndroidVersions.kt @@ -1,8 +1,9 @@ package ftl.domain import flank.common.logLn -import ftl.android.AndroidCatalog +import ftl.api.fetchAndroidOsVersion import ftl.args.AndroidArgs +import ftl.environment.android.toCliTable import java.nio.file.Paths interface ListAndroidVersions { @@ -10,5 +11,6 @@ interface ListAndroidVersions { } operator fun ListAndroidVersions.invoke() { - logLn(AndroidCatalog.supportedVersionsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) + // TODO move toCliTable() to presentation layer during refactor of presentation after #1728 + logLn(fetchAndroidOsVersion(AndroidArgs.loadOrDefault(Paths.get(configPath)).project).toCliTable()) } diff --git a/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidDevices.kt b/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidDevices.kt index c0daf40110..fc4eefc0b9 100644 --- a/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidDevices.kt +++ b/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidDevices.kt @@ -20,7 +20,7 @@ import ftl.util.SystemOutColor import ftl.util.applyColorsUsing import ftl.util.buildTable -fun List.asPrintableTable() = createTestEnvironmentInfo().createAndroidDevicesTable() +fun List.toCliTable() = createTestEnvironmentInfo().createAndroidDevicesTable() private fun List.createTestEnvironmentInfo() = fold(mutableMapOf>()) { devicesInfo, androidDevice -> diff --git a/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidSofwareVersions.kt b/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidSofwareVersions.kt index 13b472cab5..6870c0fab7 100644 --- a/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidSofwareVersions.kt +++ b/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidSofwareVersions.kt @@ -1,7 +1,7 @@ package ftl.environment.android -import com.google.testing.model.AndroidVersion -import com.google.testing.model.Date +import ftl.api.Date +import ftl.api.OsVersion import ftl.environment.OS_VERSION_ID import ftl.environment.TAGS import ftl.environment.TestEnvironmentInfo @@ -13,9 +13,9 @@ import ftl.reports.api.twoDigitString import ftl.util.applyColorsUsing import ftl.util.buildTable -fun List.asPrintableTable() = createTestEnvironmentInfo().createAndroidSoftwareVersionsTable() +fun List.toCliTable() = createTestEnvironmentInfo().createAndroidSoftwareVersionsTable() -private fun List.createTestEnvironmentInfo() = +private fun List.createTestEnvironmentInfo() = fold(mutableMapOf>()) { softwareInfo, softwareVersion -> softwareInfo.apply { getOrCreateList(OS_VERSION_ID).add(softwareVersion.id.orUnknown()) diff --git a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt index 0eeedce4cc..9700de0728 100644 --- a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt @@ -2,6 +2,8 @@ package ftl.android import com.google.common.truth.Truth.assertThat import com.google.testing.model.AndroidDevice +import ftl.api.fetchAndroidOsVersion +import ftl.environment.android.toCliTable import ftl.test.util.FlankTestRunner import io.mockk.every import io.mockk.mockk @@ -96,7 +98,7 @@ class AndroidCatalogTest { val expectedSeparatorCount = expectedHeaders.size + 1 // when - val devicesTable = AndroidCatalog.supportedVersionsAsTable(projectId) + val devicesTable = fetchAndroidOsVersion(projectId).toCliTable() val headers = devicesTable.lines()[1] // then From 8011a1e9bb3e9dbd301887b2ea6597928d37ca1a Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 22 Apr 2021 16:26:05 +0200 Subject: [PATCH 3/7] Update after merge --- .../src/main/kotlin/ftl/client/google/AndroidCatalog.kt | 3 ++- .../main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt | 2 ++ .../src/test/kotlin/ftl/android/AndroidCatalogTest.kt | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt b/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt index 5fd9678d1e..eadf7b33ed 100644 --- a/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt @@ -4,6 +4,7 @@ import com.google.testing.model.AndroidDevice import com.google.testing.model.AndroidDeviceCatalog import com.google.testing.model.Orientation import flank.common.logLn +import ftl.api.fetchAndroidOsVersion import ftl.config.Device import ftl.environment.android.getDescription import ftl.environment.android.toCliTable @@ -40,7 +41,7 @@ object AndroidCatalog { getModels(projectId).find { it.id == model }?.supportedVersionIds ?: emptyList() - fun supportedVersionsAsTable(projectId: String) = getVersionsList(projectId).toCliTable() + fun supportedVersionsAsTable(projectId: String) = fetchAndroidOsVersion(projectId).toCliTable() fun describeSoftwareVersion(projectId: String, versionId: String) = getVersionsList(projectId).getDescription(versionId) diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt index 256e64f13e..0e4b6b56eb 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt @@ -2,11 +2,13 @@ package ftl.domain import flank.common.logLn import ftl.api.Platform +import ftl.api.fetchAndroidOsVersion import ftl.api.fetchIpBlocks import ftl.api.fetchNetworkProfiles import ftl.api.fetchOrientation import ftl.args.AndroidArgs import ftl.client.google.AndroidCatalog +import ftl.environment.android.toCliTable import ftl.environment.common.toCliTable import ftl.environment.providedSoftwareAsTable import ftl.environment.toCliTable diff --git a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt index a0579fee23..37907caf3f 100644 --- a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt @@ -3,6 +3,11 @@ package ftl.android import com.google.common.truth.Truth.assertThat import com.google.testing.model.AndroidDevice import ftl.api.fetchAndroidOsVersion +import ftl.client.google.AndroidCatalog +import ftl.client.google.IncompatibleModelVersion +import ftl.client.google.SupportedDeviceConfig +import ftl.client.google.UnsupportedModelId +import ftl.client.google.UnsupportedVersionId import ftl.environment.android.toCliTable import ftl.test.util.FlankTestRunner import io.mockk.every From ab4e27b38e0c5b074752b09b65dd4d7424d7810d Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 22 Apr 2021 17:00:58 +0200 Subject: [PATCH 4/7] updated describe command --- .../ftl/client/google/AndroidCatalog.kt | 5 +- .../AndroidSoftwareVersionDescription.kt | 17 +++--- .../AndroidSoftwareVersionDescriptionTest.kt | 53 ++++++++++--------- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt b/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt index eadf7b33ed..1096ce6935 100644 --- a/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt @@ -9,7 +9,6 @@ import ftl.config.Device import ftl.environment.android.getDescription import ftl.environment.android.toCliTable import ftl.environment.asPrintableTable -import ftl.environment.common.toCliTable import ftl.environment.getLocaleDescription import ftl.gc.GcTesting import ftl.http.executeWithRetry @@ -43,9 +42,7 @@ object AndroidCatalog { fun supportedVersionsAsTable(projectId: String) = fetchAndroidOsVersion(projectId).toCliTable() - fun describeSoftwareVersion(projectId: String, versionId: String) = getVersionsList(projectId).getDescription(versionId) - - private fun getVersionsList(projectId: String) = deviceCatalog(projectId).versions + fun describeSoftwareVersion(projectId: String, versionId: String) = fetchAndroidOsVersion(projectId).getDescription(versionId) fun supportedOrientations(projectId: String): List = deviceCatalog(projectId).runtimeConfiguration.orientations diff --git a/test_runner/src/main/kotlin/ftl/environment/android/AndroidSoftwareVersionDescription.kt b/test_runner/src/main/kotlin/ftl/environment/android/AndroidSoftwareVersionDescription.kt index 839e85d0c0..71a1790aa4 100644 --- a/test_runner/src/main/kotlin/ftl/environment/android/AndroidSoftwareVersionDescription.kt +++ b/test_runner/src/main/kotlin/ftl/environment/android/AndroidSoftwareVersionDescription.kt @@ -1,21 +1,22 @@ package ftl.environment.android -import com.google.testing.model.AndroidVersion +import ftl.api.OsVersion +import ftl.environment.orUnknown import ftl.run.exception.FlankGeneralError -fun List.getDescription(versionId: String) = findVersion(versionId)?.prepareDescription().orErrorMessage(versionId) +fun List.getDescription(versionId: String) = findVersion(versionId)?.prepareDescription().orErrorMessage(versionId) -private fun List.findVersion(versionId: String) = firstOrNull { it.id == versionId } +private fun List.findVersion(versionId: String) = firstOrNull { it.id == versionId } -private fun AndroidVersion.prepareDescription() = """ +private fun OsVersion.Android.prepareDescription() = """ apiLevel: $apiLevel codeName: $codeName id: '$id' releaseDate: - day: ${releaseDate.day} - month: ${releaseDate.month} - year: ${releaseDate.year} -""".trimIndent().addDataIfExists(tags).addVersion(versionString).trim() + day: ${releaseDate?.day} + month: ${releaseDate?.month} + year: ${releaseDate?.year} +""".trimIndent().addDataIfExists(tags).addVersion(versionString.orUnknown()).trim() private fun String.addVersion(versionString: String) = StringBuilder(this).appendLine("\nversionString: $versionString") .toString() diff --git a/test_runner/src/test/kotlin/ftl/environment/android/AndroidSoftwareVersionDescriptionTest.kt b/test_runner/src/test/kotlin/ftl/environment/android/AndroidSoftwareVersionDescriptionTest.kt index 78aaa46e65..cc93cd267b 100644 --- a/test_runner/src/test/kotlin/ftl/environment/android/AndroidSoftwareVersionDescriptionTest.kt +++ b/test_runner/src/test/kotlin/ftl/environment/android/AndroidSoftwareVersionDescriptionTest.kt @@ -1,7 +1,7 @@ package ftl.environment.android -import com.google.testing.model.AndroidVersion -import com.google.testing.model.Date +import ftl.api.Date +import ftl.api.OsVersion import ftl.test.util.TestHelper.getThrowable import org.junit.Assert import org.junit.Test @@ -10,18 +10,19 @@ class AndroidSoftwareVersionDescriptionTest { @Test fun `should return software version with tag if any tag exists`() { val versions = listOf( - AndroidVersion().apply { - id = "26" - apiLevel = 26 - codeName = "Oreo" - versionString = "8.0.x" - releaseDate = Date().apply { - day = 21 - month = 8 + OsVersion.Android( + id = "26", + apiLevel = 26, + codeName = "Oreo", + versionString = "8.0.x", + releaseDate = Date( + day = 21, + month = 8, year = 2017 - } - tags = listOf("default") - } + ), + tags = listOf("default"), + distribution = null + ) ) val localesDescription = versions.getDescription("26") @@ -43,17 +44,19 @@ class AndroidSoftwareVersionDescriptionTest { @Test fun `should return software version without tag if no tags`() { val versions = listOf( - AndroidVersion().apply { - id = "23" - apiLevel = 23 - codeName = "Marshmallow" - versionString = "6.0.x" - releaseDate = Date().apply { - day = 5 - month = 10 - year = 2015 - } - } + OsVersion.Android( + id = "23", + apiLevel = 23, + codeName = "Marshmallow", + versionString = "6.0.x", + releaseDate = Date( + day = 5, + month = 10, + year = 2015, + ), + distribution = null, + tags = null + ) ) val localesDescription = versions.getDescription("23") @@ -72,7 +75,7 @@ class AndroidSoftwareVersionDescriptionTest { @Test fun `should return error message if version not found`() { - val versions = listOf() + val versions = listOf() val versionName = "test" val localesDescription = getThrowable { versions.getDescription(versionName) } val expected = "ERROR: '$versionName' is not a valid OS version" From 10d90d6cc251f682584ebdeac5262296343d920d Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 23 Apr 2021 16:43:03 +0200 Subject: [PATCH 5/7] cr changes --- .../kotlin/ftl/adapter/google/AndroidOsVersions.kt | 6 +++--- test_runner/src/main/kotlin/ftl/api/OsVersion.kt | 12 ++++++------ .../android/ListAndroidSofwareVersions.kt | 3 +-- .../android/AndroidSoftwareVersionDescriptionTest.kt | 5 ++--- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/AndroidOsVersions.kt b/test_runner/src/main/kotlin/ftl/adapter/google/AndroidOsVersions.kt index 05ab1cd2f6..a5dd51c6c7 100644 --- a/test_runner/src/main/kotlin/ftl/adapter/google/AndroidOsVersions.kt +++ b/test_runner/src/main/kotlin/ftl/adapter/google/AndroidOsVersions.kt @@ -1,8 +1,8 @@ package ftl.adapter.google import com.google.testing.model.AndroidVersion +import com.google.testing.model.Date import com.google.testing.model.Distribution -import ftl.api.Date import ftl.api.OsVersion fun List.toApiModel() = map { @@ -19,6 +19,6 @@ private fun AndroidVersion.toApiModel() = OsVersion.Android( versionString ) -private fun Distribution.toApiModel() = ftl.api.Distribution(marketShare, measurementTime) +private fun Distribution.toApiModel() = OsVersion.Distribution(marketShare, measurementTime) -private fun com.google.testing.model.Date.toApiModel() = Date(day, month, year) +private fun Date.toApiModel() = OsVersion.Date(day, month, year) diff --git a/test_runner/src/main/kotlin/ftl/api/OsVersion.kt b/test_runner/src/main/kotlin/ftl/api/OsVersion.kt index 65dd51327e..54c6169896 100644 --- a/test_runner/src/main/kotlin/ftl/api/OsVersion.kt +++ b/test_runner/src/main/kotlin/ftl/api/OsVersion.kt @@ -29,11 +29,11 @@ object OsVersion { ) { interface Fetch : (String) -> List } -} -data class Distribution( - val marketShare: Double, - val measurementTime: String, -) + data class Distribution( + val marketShare: Double, + val measurementTime: String, + ) -data class Date(val day: Int?, val month: Int?, val year: Int?) + data class Date(val day: Int?, val month: Int?, val year: Int?) +} diff --git a/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidSofwareVersions.kt b/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidSofwareVersions.kt index 6870c0fab7..3baa33216a 100644 --- a/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidSofwareVersions.kt +++ b/test_runner/src/main/kotlin/ftl/environment/android/ListAndroidSofwareVersions.kt @@ -1,6 +1,5 @@ package ftl.environment.android -import ftl.api.Date import ftl.api.OsVersion import ftl.environment.OS_VERSION_ID import ftl.environment.TAGS @@ -27,7 +26,7 @@ private fun List.createTestEnvironmentInfo() = } } -private fun Date?.printableReleaseDate() = +private fun OsVersion.Date?.printableReleaseDate() = if (this == null || year == null || month == null || day == null) "UNKNOWN" else "$year-${month.twoDigitString()}-${day.twoDigitString()}" diff --git a/test_runner/src/test/kotlin/ftl/environment/android/AndroidSoftwareVersionDescriptionTest.kt b/test_runner/src/test/kotlin/ftl/environment/android/AndroidSoftwareVersionDescriptionTest.kt index cc93cd267b..c88f68ffb7 100644 --- a/test_runner/src/test/kotlin/ftl/environment/android/AndroidSoftwareVersionDescriptionTest.kt +++ b/test_runner/src/test/kotlin/ftl/environment/android/AndroidSoftwareVersionDescriptionTest.kt @@ -1,6 +1,5 @@ package ftl.environment.android -import ftl.api.Date import ftl.api.OsVersion import ftl.test.util.TestHelper.getThrowable import org.junit.Assert @@ -15,7 +14,7 @@ class AndroidSoftwareVersionDescriptionTest { apiLevel = 26, codeName = "Oreo", versionString = "8.0.x", - releaseDate = Date( + releaseDate = OsVersion.Date( day = 21, month = 8, year = 2017 @@ -49,7 +48,7 @@ class AndroidSoftwareVersionDescriptionTest { apiLevel = 23, codeName = "Marshmallow", versionString = "6.0.x", - releaseDate = Date( + releaseDate = OsVersion.Date( day = 5, month = 10, year = 2015, From 96dd247b0b9782a8d60d5d0b063c0979d00a4743 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 23 Apr 2021 18:16:15 +0200 Subject: [PATCH 6/7] Update AndroidCatalogTest.kt --- .../src/test/kotlin/ftl/android/AndroidCatalogTest.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt index 41d95cc4ff..08e47f5859 100644 --- a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt @@ -3,11 +3,6 @@ package ftl.android import com.google.common.truth.Truth.assertThat import com.google.testing.model.AndroidDevice import ftl.api.fetchAndroidOsVersion -import ftl.client.google.AndroidCatalog -import ftl.client.google.IncompatibleModelVersion -import ftl.client.google.SupportedDeviceConfig -import ftl.client.google.UnsupportedModelId -import ftl.client.google.UnsupportedVersionId import ftl.api.fetchDeviceModelAndroid import ftl.client.google.AndroidCatalog import ftl.environment.android.toCliTable From d2e52ca2b1adf91479f75e7b94f47c55a95e1adb Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 23 Apr 2021 18:27:54 +0200 Subject: [PATCH 7/7] Merge fix --- .../kotlin/ftl/client/google/AndroidCatalog.kt | 17 +++-------------- .../domain/DescribeAndroidTestEnvironment.kt | 1 - 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt b/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt index f69b44dc16..d4b84f82e2 100644 --- a/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt @@ -6,7 +6,6 @@ import com.google.testing.model.AndroidModel import com.google.testing.model.Orientation import flank.common.logLn import ftl.api.fetchAndroidOsVersion -import ftl.config.Device import ftl.environment.android.getDescription import ftl.environment.android.toCliTable import ftl.environment.asPrintableTable @@ -31,21 +30,14 @@ object AndroidCatalog { .androidDeviceCatalog } - fun devicesCatalogAsTable(projectId: String) = getModels(projectId).toCliTable() - - fun describeModel(projectId: String, modelId: String) = getModels(projectId).getDescription(modelId) - - private fun getModels(projectId: String) = deviceCatalog(projectId).models - - fun Device.getSupportedVersionId(projectId: String): List = - getModels(projectId).find { it.id == model }?.supportedVersionIds - ?: emptyList() fun getModels(projectId: String): List = deviceCatalog(projectId).models.orEmpty() fun supportedVersionsAsTable(projectId: String) = fetchAndroidOsVersion(projectId).toCliTable() fun describeSoftwareVersion(projectId: String, versionId: String) = fetchAndroidOsVersion(projectId).getDescription(versionId) + private fun getVersionsList(projectId: String) = deviceCatalog(projectId).versions + fun supportedOrientations(projectId: String): List = deviceCatalog(projectId).runtimeConfiguration.orientations fun localesAsTable(projectId: String) = getLocales(projectId).asPrintableTable() @@ -72,10 +64,7 @@ object AndroidCatalog { logLn("Unable to find device type for $modelId. PHYSICAL used as fallback in cost calculations") } - return form.equals(DeviceType.VIRTUAL.name, ignoreCase = true) || form.equals( - DeviceType.EMULATOR.name, - ignoreCase = true - ) + return form.equals(DeviceType.VIRTUAL.name, ignoreCase = true) || form.equals(DeviceType.EMULATOR.name, ignoreCase = true) } } diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt index 71fee62305..e26137120c 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt @@ -21,7 +21,6 @@ interface DescribeAndroidTestEnvironment { fun DescribeAndroidTestEnvironment.invoke() { val projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project - logLn(AndroidCatalog.devicesCatalogAsTable(projectId)) // 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