From 29aa637e4c97fed2d05e391dc17d63af1a168cf9 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 22 Apr 2021 11:19:05 +0200 Subject: [PATCH 1/6] Locales iteration 1 --- .../kotlin/ftl/adapter/GoogleLocalesFetch.kt | 16 +++++++++++++++ .../ftl/adapter/GoogleOrientationFetch.kt | 2 +- .../ftl/adapter/google/LocalesAdapter.kt | 12 +++++++++++ test_runner/src/main/kotlin/ftl/api/Locale.kt | 20 +++++++++++++++++++ .../src/main/kotlin/ftl/api/Orientation.kt | 5 ----- .../src/main/kotlin/ftl/api/Platform.kt | 6 ++++++ .../main/kotlin/ftl/args/ValidateIosArgs.kt | 4 ++-- .../ftl/client/google/AndroidCatalog.kt | 3 +-- .../ftl/{ios => client/google}/IosCatalog.kt | 4 ++-- .../kotlin/ftl/domain/DescribeIosLocales.kt | 2 +- .../kotlin/ftl/domain/DescribeIosModels.kt | 2 +- .../ftl/domain/DescribeIosTestEnvironment.kt | 2 +- .../kotlin/ftl/domain/DescribeIosVersions.kt | 2 +- .../main/kotlin/ftl/domain/ListIosLocales.kt | 2 +- .../main/kotlin/ftl/domain/ListIosModels.kt | 2 +- .../main/kotlin/ftl/domain/ListIosVersions.kt | 2 +- .../IosLocalesDescribeCommandTest.kt | 2 +- .../IosLocalesListCommandTest.kt | 2 +- .../IosOrientationCommandListTest.kt | 2 +- .../IosVersionsDescribeCommandTest.kt | 2 +- .../src/test/kotlin/ftl/ios/IosCatalogTest.kt | 1 + 21 files changed, 72 insertions(+), 23 deletions(-) create mode 100644 test_runner/src/main/kotlin/ftl/adapter/GoogleLocalesFetch.kt create mode 100644 test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt create mode 100644 test_runner/src/main/kotlin/ftl/api/Locale.kt create mode 100644 test_runner/src/main/kotlin/ftl/api/Platform.kt rename test_runner/src/main/kotlin/ftl/{ios => client/google}/IosCatalog.kt (96%) diff --git a/test_runner/src/main/kotlin/ftl/adapter/GoogleLocalesFetch.kt b/test_runner/src/main/kotlin/ftl/adapter/GoogleLocalesFetch.kt new file mode 100644 index 0000000000..cc6cf99972 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/adapter/GoogleLocalesFetch.kt @@ -0,0 +1,16 @@ +package ftl.adapter + +import ftl.adapter.google.toApiModel +import ftl.api.Locale +import ftl.api.Platform +import ftl.client.google.AndroidCatalog +import ftl.client.google.IosCatalog + +object GoogleLocalesFetch : + Locale.Fetch, + (Locale.Identity) -> List by { id -> + when (id.platform) { + Platform.ANDROID -> AndroidCatalog.getLocales(id.projectId).toApiModel() + Platform.IOS -> IosCatalog.getLocales(id.projectId).toApiModel() + } + } diff --git a/test_runner/src/main/kotlin/ftl/adapter/GoogleOrientationFetch.kt b/test_runner/src/main/kotlin/ftl/adapter/GoogleOrientationFetch.kt index 52193c23d8..92a477eba7 100644 --- a/test_runner/src/main/kotlin/ftl/adapter/GoogleOrientationFetch.kt +++ b/test_runner/src/main/kotlin/ftl/adapter/GoogleOrientationFetch.kt @@ -4,7 +4,7 @@ import ftl.adapter.google.toApiModel import ftl.api.Orientation import ftl.api.Platform import ftl.client.google.AndroidCatalog -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog object GoogleOrientationFetch : Orientation.Fetch, diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt new file mode 100644 index 0000000000..ca83622d97 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt @@ -0,0 +1,12 @@ +package ftl.adapter.google + +import ftl.api.Locale + +internal fun List.toApiModel(): List = map { locale -> + Locale( + id = locale.id, + name = locale.name, + region = locale.region, + tags = locale.tags + ) +} diff --git a/test_runner/src/main/kotlin/ftl/api/Locale.kt b/test_runner/src/main/kotlin/ftl/api/Locale.kt new file mode 100644 index 0000000000..a82aaf49f2 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/api/Locale.kt @@ -0,0 +1,20 @@ +package ftl.api + +import ftl.adapter.GoogleLocalesFetch + +val fetchLocales: Locale.Fetch get() = GoogleLocalesFetch + +data class Locale( + val id: String, + val name: String, + val region: String, + val tags: List, +) { + + data class Identity( + val projectId: String, + val platform: Platform + ) + + interface Fetch : (Identity) -> List +} diff --git a/test_runner/src/main/kotlin/ftl/api/Orientation.kt b/test_runner/src/main/kotlin/ftl/api/Orientation.kt index 27725ffb0f..cd084b160f 100644 --- a/test_runner/src/main/kotlin/ftl/api/Orientation.kt +++ b/test_runner/src/main/kotlin/ftl/api/Orientation.kt @@ -11,8 +11,3 @@ data class Orientation( ) { interface Fetch : (String, Platform) -> List } - -enum class Platform { - ANDROID, - IOS -} diff --git a/test_runner/src/main/kotlin/ftl/api/Platform.kt b/test_runner/src/main/kotlin/ftl/api/Platform.kt new file mode 100644 index 0000000000..618546fda5 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/api/Platform.kt @@ -0,0 +1,6 @@ +package ftl.api + +enum class Platform { + ANDROID, + IOS +} diff --git a/test_runner/src/main/kotlin/ftl/args/ValidateIosArgs.kt b/test_runner/src/main/kotlin/ftl/args/ValidateIosArgs.kt index bf7ec11980..14a4268690 100644 --- a/test_runner/src/main/kotlin/ftl/args/ValidateIosArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/ValidateIosArgs.kt @@ -2,8 +2,8 @@ package ftl.args import flank.common.logLn import ftl.args.yml.Type -import ftl.ios.IosCatalog -import ftl.ios.IosCatalog.getSupportedVersionId +import ftl.client.google.IosCatalog +import ftl.client.google.IosCatalog.getSupportedVersionId import ftl.ios.xctest.XcTestRunData import ftl.ios.xctest.common.XcTestRunVersion import ftl.ios.xctest.common.mapToRegex 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 9ca3481e37..6d8463df08 100644 --- a/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt @@ -8,7 +8,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 @@ -51,7 +50,7 @@ object AndroidCatalog { fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale) - private fun getLocales(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.locales + internal fun getLocales(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.locales fun androidModelIds(projectId: String) = modelMap.getOrPut(projectId) { deviceCatalog(projectId).models.map { it.id } } diff --git a/test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt b/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt similarity index 96% rename from test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt rename to test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt index f38fb4efd1..fca54ae615 100644 --- a/test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt @@ -1,4 +1,4 @@ -package ftl.ios +package ftl.client.google import com.google.testing.model.IosDeviceCatalog import com.google.testing.model.Orientation @@ -36,7 +36,7 @@ object IosCatalog { fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale) - private fun getLocales(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales + internal fun getLocales(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales fun supportedOrientations(projectId: String): List = iosDeviceCatalog(projectId).runtimeConfiguration.orientations diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt index 4f41b44a5b..d870b54b01 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt @@ -2,7 +2,7 @@ package ftl.domain import flank.common.log import ftl.args.IosArgs -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import ftl.run.exception.FlankConfigurationError import java.nio.file.Paths diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeIosModels.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeIosModels.kt index bab257a44b..bc8134daaa 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeIosModels.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeIosModels.kt @@ -2,7 +2,7 @@ package ftl.domain import flank.common.logLn import ftl.args.IosArgs -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import ftl.run.exception.FlankConfigurationError import java.nio.file.Paths diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt index c5530a3ded..f949e126f4 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt @@ -5,11 +5,11 @@ import ftl.api.Platform import ftl.api.fetchIpBlocks import ftl.api.fetchOrientation import ftl.args.IosArgs +import ftl.client.google.IosCatalog import ftl.environment.common.toCliTable import ftl.environment.networkConfigurationAsTable import ftl.environment.providedSoftwareAsTable import ftl.environment.toCliTable -import ftl.ios.IosCatalog import java.nio.file.Paths interface DescribeIosTestEnvironment { diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeIosVersions.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeIosVersions.kt index 6e79752ce4..5a00e5be1e 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeIosVersions.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeIosVersions.kt @@ -2,7 +2,7 @@ package ftl.domain import flank.common.logLn import ftl.args.IosArgs -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import ftl.run.exception.FlankConfigurationError import java.nio.file.Paths diff --git a/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt b/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt index 516d70b5f2..8c72118f23 100644 --- a/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt @@ -2,7 +2,7 @@ package ftl.domain import flank.common.logLn import ftl.args.IosArgs -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import java.nio.file.Paths interface ListIosLocales { diff --git a/test_runner/src/main/kotlin/ftl/domain/ListIosModels.kt b/test_runner/src/main/kotlin/ftl/domain/ListIosModels.kt index 7acc038122..fb1289fda4 100644 --- a/test_runner/src/main/kotlin/ftl/domain/ListIosModels.kt +++ b/test_runner/src/main/kotlin/ftl/domain/ListIosModels.kt @@ -2,7 +2,7 @@ package ftl.domain import flank.common.logLn import ftl.args.IosArgs -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import java.nio.file.Paths interface ListIosModels { diff --git a/test_runner/src/main/kotlin/ftl/domain/ListIosVersions.kt b/test_runner/src/main/kotlin/ftl/domain/ListIosVersions.kt index 189ed45cf2..0102adf8f6 100644 --- a/test_runner/src/main/kotlin/ftl/domain/ListIosVersions.kt +++ b/test_runner/src/main/kotlin/ftl/domain/ListIosVersions.kt @@ -2,7 +2,7 @@ package ftl.domain import flank.common.logLn import ftl.args.IosArgs -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import java.nio.file.Paths interface ListIosVersions { diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt index 45af5284e2..0ac8a0d0d5 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt @@ -1,6 +1,6 @@ package ftl.cli.firebase.test.ios.configuration -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import ftl.presentation.cli.firebase.test.ios.configuration.IosLocalesDescribeCommand import ftl.run.exception.FlankConfigurationError import ftl.test.util.TestHelper diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt index f6b0a7b21e..a6d26c0245 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt @@ -1,7 +1,7 @@ package ftl.cli.firebase.test.ios.configuration import com.google.common.truth.Truth -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import ftl.presentation.cli.firebase.test.ios.configuration.IosLocalesListCommand import io.mockk.mockkObject import io.mockk.verify diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/orientations/IosOrientationCommandListTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/orientations/IosOrientationCommandListTest.kt index 3c5d8bc311..5ffa4b6610 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/orientations/IosOrientationCommandListTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/orientations/IosOrientationCommandListTest.kt @@ -1,6 +1,6 @@ package ftl.cli.firebase.test.ios.orientations -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import ftl.presentation.cli.firebase.test.ios.orientations.IosOrientationsListCommand import io.mockk.mockkObject import io.mockk.verify diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommandTest.kt index abd74f8e77..eb5b6570c5 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommandTest.kt @@ -1,6 +1,6 @@ package ftl.cli.firebase.test.ios.versions -import ftl.ios.IosCatalog +import ftl.client.google.IosCatalog import ftl.presentation.cli.firebase.test.ios.versions.IosVersionsDescribeCommand import ftl.run.exception.FlankConfigurationError import ftl.test.util.TestHelper.getThrowable diff --git a/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt b/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt index 55a72d8e53..03410b7fe2 100644 --- a/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt @@ -1,6 +1,7 @@ package ftl.ios import com.google.common.truth.Truth.assertThat +import ftl.client.google.IosCatalog import ftl.test.util.FlankTestRunner import org.junit.Test import org.junit.runner.RunWith From 1da297551baaa82385df85100b9c4ba870da524e Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 22 Apr 2021 12:01:16 +0200 Subject: [PATCH 2/6] Iteration 2 --- .../ftl/adapter/google/LocalesAdapter.kt | 62 +++++++++++++++++-- .../ftl/client/google/AndroidCatalog.kt | 4 +- .../kotlin/ftl/client/google/IosCatalog.kt | 4 +- .../ftl/domain/DescribeAndroidLocales.kt | 14 ++++- .../domain/DescribeAndroidTestEnvironment.kt | 5 +- .../kotlin/ftl/domain/DescribeIosLocales.kt | 9 ++- .../ftl/domain/DescribeIosTestEnvironment.kt | 5 +- .../kotlin/ftl/domain/ListAndroidLocales.kt | 9 ++- .../main/kotlin/ftl/domain/ListIosLocales.kt | 7 ++- .../kotlin/ftl/android/AndroidCatalogTest.kt | 6 +- .../AndroidLocalesDescribeCommandTest.kt | 2 +- .../locales/AndroidLocalesListCommandTest.kt | 2 +- .../IosLocalesDescribeCommandTest.kt | 9 ++- .../IosLocalesListCommandTest.kt | 2 +- .../src/test/kotlin/ftl/ios/IosCatalogTest.kt | 6 +- 15 files changed, 122 insertions(+), 24 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt index ca83622d97..a68bab71c1 100644 --- a/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt +++ b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt @@ -1,12 +1,66 @@ package ftl.adapter.google import ftl.api.Locale +import ftl.environment.TAGS +import ftl.environment.TestEnvironmentInfo +import ftl.environment.createTableColumnFor +import ftl.environment.getOrCreateList +import ftl.environment.tagToSystemOutColorMapper +import ftl.run.exception.FlankGeneralError +import ftl.util.applyColorsUsing +import ftl.util.buildTable internal fun List.toApiModel(): List = map { locale -> Locale( - id = locale.id, - name = locale.name, - region = locale.region, - tags = locale.tags + id = locale.id.orEmpty(), + name = locale.name.orEmpty(), + region = locale.region.orEmpty(), + tags = locale.tags.orEmpty() ) } + +fun List.asPrintableTable() = createTestEnvironment().createLocalesTable() + +private fun List.createTestEnvironment() = + fold(mutableMapOf>()) { allLocales, locale -> + allLocales.apply { + getOrCreateList(LOCALE).add(locale.id.orEmpty()) + getOrCreateList(NAME).add(locale.name.orEmpty()) + getOrCreateList(REGION).add(locale.region.orEmpty()) + getOrCreateList(TAGS).add(locale.tags?.joinToString().orEmpty()) + } + } + +private fun TestEnvironmentInfo.createLocalesTable() = buildTable( + createTableColumnFor(LOCALE), + createTableColumnFor(NAME), + createTableColumnFor(REGION), + createTableColumnFor(TAGS).applyColorsUsing(tagToSystemOutColorMapper) +) + +private const val LOCALE = "LOCALE" +private const val NAME = "NAME" +private const val REGION = "REGION" + +fun List.getLocaleDescription(localeId: String) = findLocales(localeId)?.prepareDescription().orErrorMessage(localeId).plus("\n") + +private fun List.findLocales(localeId: String) = find { it.id == localeId } + +private fun Locale.prepareDescription() = """ + id: $id + name: $name +""".trimIndent().addRegionIfExist(region).addTagsIfExists(this) + +private fun String.addRegionIfExist(region: String?) = + if (!region.isNullOrEmpty()) StringBuilder(this).appendLine("\nregion: $region").trim().toString() + else this + +private fun String.addTagsIfExists(locale: Locale) = + if (!locale.tags.isNullOrEmpty()) StringBuilder(this).appendLine("\ntags:").appendTagsToList(locale) + else this + +private fun StringBuilder.appendTagsToList(locale: Locale) = apply { + locale.tags.filterNotNull().forEach { tag -> appendLine("- $tag") } +}.trim().toString() + +private fun String?.orErrorMessage(locale: String) = this ?: throw FlankGeneralError("ERROR: '$locale' is not a valid locale") 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 6d8463df08..371866437c 100644 --- a/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt @@ -46,9 +46,9 @@ object AndroidCatalog { fun supportedOrientations(projectId: String): List = deviceCatalog(projectId).runtimeConfiguration.orientations - fun localesAsTable(projectId: String) = getLocales(projectId).asPrintableTable() + private fun localesAsTable(projectId: String) = getLocales(projectId).asPrintableTable() - fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale) + private fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale) internal fun getLocales(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.locales diff --git a/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt b/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt index fca54ae615..d090f5c322 100644 --- a/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt @@ -32,9 +32,9 @@ object IosCatalog { private fun getVersionsList(projectId: String) = iosDeviceCatalog(projectId).versions - fun localesAsTable(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales.asPrintableTable() + private fun localesAsTable(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales.asPrintableTable() - fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale) + private fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale) internal fun getLocales(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt index a0917348a2..ff2abeb9d3 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt @@ -1,8 +1,11 @@ package ftl.domain import flank.common.log +import ftl.adapter.google.getLocaleDescription +import ftl.api.Locale +import ftl.api.Platform +import ftl.api.fetchLocales import ftl.args.AndroidArgs -import ftl.client.google.AndroidCatalog import ftl.run.exception.FlankConfigurationError import java.nio.file.Paths @@ -13,5 +16,12 @@ interface DescribeAndroidLocales { fun DescribeAndroidLocales.invoke() { if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.") - log(AndroidCatalog.getLocaleDescription(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, locale)) + log( + fetchLocales( + Locale.Identity( + AndroidArgs.loadOrDefault(Paths.get(configPath)).project, + Platform.ANDROID + ) + ).getLocaleDescription(locale) + ) } diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt index b34c1c2861..352edb93cf 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt @@ -1,8 +1,11 @@ package ftl.domain import flank.common.logLn +import ftl.adapter.google.asPrintableTable +import ftl.api.Locale.Identity import ftl.api.Platform import ftl.api.fetchIpBlocks +import ftl.api.fetchLocales import ftl.api.fetchOrientation import ftl.args.AndroidArgs import ftl.client.google.AndroidCatalog @@ -20,7 +23,7 @@ fun DescribeAndroidTestEnvironment.invoke() { val projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project logLn(AndroidCatalog.devicesCatalogAsTable(projectId)) logLn(AndroidCatalog.supportedVersionsAsTable(projectId)) - logLn(AndroidCatalog.localesAsTable(projectId)) + logLn(fetchLocales(Identity(projectId, Platform.ANDROID)).asPrintableTable()) logLn(providedSoftwareAsTable()) logLn(networkConfigurationAsTable()) // TODO move toCliTable() to presentation layer during refactor of presentation after #1728 diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt index d870b54b01..061dd927fa 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt @@ -1,8 +1,11 @@ package ftl.domain import flank.common.log +import ftl.adapter.google.getLocaleDescription +import ftl.api.Locale.Identity +import ftl.api.Platform +import ftl.api.fetchLocales import ftl.args.IosArgs -import ftl.client.google.IosCatalog import ftl.run.exception.FlankConfigurationError import java.nio.file.Paths @@ -13,5 +16,7 @@ interface DescribeIosLocales { fun DescribeIosLocales.invoke() { if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.") - log(IosCatalog.getLocaleDescription(IosArgs.loadOrDefault(Paths.get(configPath)).project, locale)) + log( + fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS)).getLocaleDescription(locale) + ) } diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt index f949e126f4..93f222c4bc 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt @@ -1,8 +1,11 @@ package ftl.domain import flank.common.logLn +import ftl.adapter.google.asPrintableTable +import ftl.api.Locale.Identity import ftl.api.Platform import ftl.api.fetchIpBlocks +import ftl.api.fetchLocales import ftl.api.fetchOrientation import ftl.args.IosArgs import ftl.client.google.IosCatalog @@ -20,7 +23,7 @@ operator fun DescribeIosTestEnvironment.invoke() { val projectId = IosArgs.loadOrDefault(Paths.get(configPath)).project logLn(IosCatalog.devicesCatalogAsTable(projectId)) logLn(IosCatalog.softwareVersionsAsTable(projectId)) - logLn(IosCatalog.localesAsTable(projectId)) + logLn(fetchLocales(Identity(projectId, Platform.IOS)).asPrintableTable()) logLn(providedSoftwareAsTable()) logLn(networkConfigurationAsTable()) // TODO move toCliTable() and printing presentation layer during refactor of presentation after #1728 diff --git a/test_runner/src/main/kotlin/ftl/domain/ListAndroidLocales.kt b/test_runner/src/main/kotlin/ftl/domain/ListAndroidLocales.kt index f61ed9fc82..f1c0d41bb3 100644 --- a/test_runner/src/main/kotlin/ftl/domain/ListAndroidLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/ListAndroidLocales.kt @@ -1,8 +1,11 @@ package ftl.domain import flank.common.logLn +import ftl.adapter.google.asPrintableTable +import ftl.api.Locale.Identity +import ftl.api.Platform +import ftl.api.fetchLocales import ftl.args.AndroidArgs -import ftl.client.google.AndroidCatalog import java.nio.file.Paths interface ListAndroidLocales { @@ -10,5 +13,7 @@ interface ListAndroidLocales { } operator fun ListAndroidLocales.invoke() { - logLn(AndroidCatalog.localesAsTable(projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn( + fetchLocales(Identity(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, Platform.ANDROID)).asPrintableTable() + ) } diff --git a/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt b/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt index 8c72118f23..280b31a0c6 100644 --- a/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt @@ -1,8 +1,11 @@ package ftl.domain import flank.common.logLn +import ftl.adapter.google.asPrintableTable +import ftl.api.Locale.Identity +import ftl.api.Platform +import ftl.api.fetchLocales import ftl.args.IosArgs -import ftl.client.google.IosCatalog import java.nio.file.Paths interface ListIosLocales { @@ -10,5 +13,5 @@ interface ListIosLocales { } operator fun ListIosLocales.invoke() { - logLn(IosCatalog.localesAsTable(projectId = IosArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn(fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS)).asPrintableTable()) } diff --git a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt index 7a38560c8e..805d3a6386 100644 --- a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt @@ -2,6 +2,10 @@ package ftl.android import com.google.common.truth.Truth.assertThat import com.google.testing.model.AndroidDevice +import ftl.adapter.google.asPrintableTable +import ftl.api.Locale +import ftl.api.Platform +import ftl.api.fetchLocales import ftl.client.google.AndroidCatalog import ftl.client.google.IncompatibleModelVersion import ftl.client.google.SupportedDeviceConfig @@ -125,7 +129,7 @@ class AndroidCatalogTest { val expectedSeparatorCount = expectedHeaders.size + 1 // when - val devicesTable = AndroidCatalog.localesAsTable(projectId) + val devicesTable = fetchLocales(Locale.Identity(projectId, Platform.ANDROID)).asPrintableTable() val headers = devicesTable.lines()[1] // then diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/locales/AndroidLocalesDescribeCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/locales/AndroidLocalesDescribeCommandTest.kt index f3b87caff8..d982ea55b6 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/locales/AndroidLocalesDescribeCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/locales/AndroidLocalesDescribeCommandTest.kt @@ -20,7 +20,7 @@ class AndroidLocalesDescribeCommandTest { fun `should execute AndroidCatalog getLocaleDescription when run AndroidLocalesDescribeCommand`() { mockkObject(AndroidCatalog) { CommandLine(AndroidLocalesDescribeCommand()).execute("pl") - verify { AndroidCatalog.getLocaleDescription(any(), any()) } + verify { AndroidCatalog.getLocales(any()) } } } diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/locales/AndroidLocalesListCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/locales/AndroidLocalesListCommandTest.kt index 87a223c37a..37b7632061 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/locales/AndroidLocalesListCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/locales/AndroidLocalesListCommandTest.kt @@ -14,7 +14,7 @@ class AndroidLocalesListCommandTest { fun `should execute AndroidCatalog localesAsTable when run AndroidLocalesListCommand`() { mockkObject(AndroidCatalog) { CommandLine(AndroidLocalesListCommand()).execute() - verify { AndroidCatalog.localesAsTable(any()) } + verify { AndroidCatalog.getLocales(any()) } } } diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt index 0ac8a0d0d5..e78028a5d0 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt @@ -23,10 +23,17 @@ class IosLocalesDescribeCommandTest { fun `should execute IosCatalog getLocaleDescription when run IosLocalesDescribeCommand`() { mockkObject(IosCatalog) { CommandLine(IosLocalesDescribeCommand()).execute("pl", "--config=$simpleFlankPath") - verify { IosCatalog.getLocaleDescription(any(), any()) } + verify { IosCatalog.getLocales(any()) } } } + /* + every { fetchLocales(any()) } returns emptyList() + every { any>().asPrintableTable() } returns "" + CommandLine(AndroidLocalesListCommand()).execute() + verify { any>().asPrintableTable() } + * */ + @Test(expected = FlankConfigurationError::class) fun `should throw if locale not specified`() { CommandLine(IosLocalesDescribeCommand()).execute("--config=$simpleFlankPath") diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt index a6d26c0245..54680221d4 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt @@ -14,7 +14,7 @@ class IosLocalesListCommandTest { fun `should execute IosCatalog localesAsTable when run IosLocalesListCommand`() { mockkObject(IosCatalog) { CommandLine(IosLocalesListCommand()).execute() - verify { IosCatalog.localesAsTable(any()) } + verify { IosCatalog.getLocales(any()) } } } diff --git a/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt b/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt index 03410b7fe2..9d3ca65936 100644 --- a/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt @@ -1,6 +1,10 @@ package ftl.ios import com.google.common.truth.Truth.assertThat +import ftl.adapter.google.asPrintableTable +import ftl.api.Locale.Identity +import ftl.api.Platform +import ftl.api.fetchLocales import ftl.client.google.IosCatalog import ftl.test.util.FlankTestRunner import org.junit.Test @@ -70,7 +74,7 @@ class IosCatalogTest { val expectedSeparatorCount = expectedHeaders.size + 1 // when - val devicesTable = IosCatalog.localesAsTable(projectId) + val devicesTable = fetchLocales(Identity(projectId, Platform.IOS)).asPrintableTable() val headers = devicesTable.lines()[1] // then From a4b5a5c0763c655412ab05e66fe08fe0f2b9476d Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Sat, 24 Apr 2021 10:28:25 +0200 Subject: [PATCH 3/6] remove safe call --- .../src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt index a68bab71c1..badf92abe4 100644 --- a/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt +++ b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt @@ -27,7 +27,7 @@ private fun List.createTestEnvironment() = getOrCreateList(LOCALE).add(locale.id.orEmpty()) getOrCreateList(NAME).add(locale.name.orEmpty()) getOrCreateList(REGION).add(locale.region.orEmpty()) - getOrCreateList(TAGS).add(locale.tags?.joinToString().orEmpty()) + getOrCreateList(TAGS).add(locale.tags.joinToString().orEmpty()) } } From 0758e88f003046d85f5cd7f746bce80f4210ac5d Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Mon, 26 Apr 2021 15:45:50 +0200 Subject: [PATCH 4/6] Removed unused code --- .../ios/configuration/IosLocalesDescribeCommandTest.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt index e78028a5d0..1a2d595a77 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommandTest.kt @@ -27,13 +27,6 @@ class IosLocalesDescribeCommandTest { } } - /* - every { fetchLocales(any()) } returns emptyList() - every { any>().asPrintableTable() } returns "" - CommandLine(AndroidLocalesListCommand()).execute() - verify { any>().asPrintableTable() } - * */ - @Test(expected = FlankConfigurationError::class) fun `should throw if locale not specified`() { CommandLine(IosLocalesDescribeCommand()).execute("--config=$simpleFlankPath") From e43f9876b4b9c5cac04efcc78f8dd2c663f62359 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Mon, 26 Apr 2021 15:50:05 +0200 Subject: [PATCH 5/6] Move to new file --- .../kotlin/ftl/adapter/google/ListLocales.kt | 59 +++++++++++++++++++ .../ftl/adapter/google/LocalesAdapter.kt | 54 ----------------- 2 files changed, 59 insertions(+), 54 deletions(-) create mode 100644 test_runner/src/main/kotlin/ftl/adapter/google/ListLocales.kt diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/ListLocales.kt b/test_runner/src/main/kotlin/ftl/adapter/google/ListLocales.kt new file mode 100644 index 0000000000..90f043edfb --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/adapter/google/ListLocales.kt @@ -0,0 +1,59 @@ +package ftl.adapter.google + +import ftl.api.Locale +import ftl.environment.TAGS +import ftl.environment.TestEnvironmentInfo +import ftl.environment.createTableColumnFor +import ftl.environment.getOrCreateList +import ftl.environment.tagToSystemOutColorMapper +import ftl.run.exception.FlankGeneralError +import ftl.util.applyColorsUsing +import ftl.util.buildTable + +fun List.asPrintableTable() = createTestEnvironment().createLocalesTable() + +fun List.createTestEnvironment() = + fold(mutableMapOf>()) { allLocales, locale -> + allLocales.apply { + getOrCreateList(LOCALE).add(locale.id.orEmpty()) + getOrCreateList(NAME).add(locale.name.orEmpty()) + getOrCreateList(REGION).add(locale.region.orEmpty()) + getOrCreateList(TAGS).add(locale.tags.joinToString().orEmpty()) + } + } + +fun TestEnvironmentInfo.createLocalesTable() = buildTable( + createTableColumnFor(LOCALE), + createTableColumnFor(NAME), + createTableColumnFor(REGION), + createTableColumnFor(ftl.environment.TAGS).applyColorsUsing(tagToSystemOutColorMapper) +) + +private const val LOCALE = "LOCALE" +private const val NAME = "NAME" +private const val REGION = "REGION" + +fun List.getLocaleDescription(localeId: String) = + findLocales(localeId)?.prepareDescription().orErrorMessage(localeId).plus("\n") + +private fun List.findLocales(localeId: String) = find { it.id == localeId } + +private fun Locale.prepareDescription() = """ + id: $id + name: $name +""".trimIndent().addRegionIfExist(region).addTagsIfExists(this) + +private fun String.addRegionIfExist(region: String?) = + if (!region.isNullOrEmpty()) StringBuilder(this).appendLine("\nregion: $region").trim().toString() + else this + +private fun String.addTagsIfExists(locale: Locale) = + if (!locale.tags.isNullOrEmpty()) StringBuilder(this).appendLine("\ntags:").appendTagsToList(locale) + else this + +private fun StringBuilder.appendTagsToList(locale: Locale) = apply { + locale.tags.filterNotNull().forEach { tag -> appendLine("- $tag") } +}.trim().toString() + +private fun String?.orErrorMessage(locale: String) = + this ?: throw FlankGeneralError("ERROR: '$locale' is not a valid locale") diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt index badf92abe4..297975e376 100644 --- a/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt +++ b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt @@ -1,14 +1,6 @@ package ftl.adapter.google import ftl.api.Locale -import ftl.environment.TAGS -import ftl.environment.TestEnvironmentInfo -import ftl.environment.createTableColumnFor -import ftl.environment.getOrCreateList -import ftl.environment.tagToSystemOutColorMapper -import ftl.run.exception.FlankGeneralError -import ftl.util.applyColorsUsing -import ftl.util.buildTable internal fun List.toApiModel(): List = map { locale -> Locale( @@ -18,49 +10,3 @@ internal fun List.toApiModel(): List = tags = locale.tags.orEmpty() ) } - -fun List.asPrintableTable() = createTestEnvironment().createLocalesTable() - -private fun List.createTestEnvironment() = - fold(mutableMapOf>()) { allLocales, locale -> - allLocales.apply { - getOrCreateList(LOCALE).add(locale.id.orEmpty()) - getOrCreateList(NAME).add(locale.name.orEmpty()) - getOrCreateList(REGION).add(locale.region.orEmpty()) - getOrCreateList(TAGS).add(locale.tags.joinToString().orEmpty()) - } - } - -private fun TestEnvironmentInfo.createLocalesTable() = buildTable( - createTableColumnFor(LOCALE), - createTableColumnFor(NAME), - createTableColumnFor(REGION), - createTableColumnFor(TAGS).applyColorsUsing(tagToSystemOutColorMapper) -) - -private const val LOCALE = "LOCALE" -private const val NAME = "NAME" -private const val REGION = "REGION" - -fun List.getLocaleDescription(localeId: String) = findLocales(localeId)?.prepareDescription().orErrorMessage(localeId).plus("\n") - -private fun List.findLocales(localeId: String) = find { it.id == localeId } - -private fun Locale.prepareDescription() = """ - id: $id - name: $name -""".trimIndent().addRegionIfExist(region).addTagsIfExists(this) - -private fun String.addRegionIfExist(region: String?) = - if (!region.isNullOrEmpty()) StringBuilder(this).appendLine("\nregion: $region").trim().toString() - else this - -private fun String.addTagsIfExists(locale: Locale) = - if (!locale.tags.isNullOrEmpty()) StringBuilder(this).appendLine("\ntags:").appendTagsToList(locale) - else this - -private fun StringBuilder.appendTagsToList(locale: Locale) = apply { - locale.tags.filterNotNull().forEach { tag -> appendLine("- $tag") } -}.trim().toString() - -private fun String?.orErrorMessage(locale: String) = this ?: throw FlankGeneralError("ERROR: '$locale' is not a valid locale") From d58ebb903c91480a8e1cd2e0560c5984aff410b9 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Tue, 27 Apr 2021 13:05:48 +0200 Subject: [PATCH 6/6] Updates --- .../kotlin/ftl/adapter/google/ListLocales.kt | 59 ------------------- .../ftl/adapter/google/LocalesAdapter.kt | 3 +- .../ftl/client/google/AndroidCatalog.kt | 3 - .../kotlin/ftl/client/google/IosCatalog.kt | 3 - .../ftl/domain/DescribeAndroidLocales.kt | 2 +- .../domain/DescribeAndroidTestEnvironment.kt | 3 +- .../kotlin/ftl/domain/DescribeIosLocales.kt | 2 +- .../ftl/domain/DescribeIosTestEnvironment.kt | 3 +- .../kotlin/ftl/domain/ListAndroidLocales.kt | 4 +- .../main/kotlin/ftl/domain/ListIosLocales.kt | 4 +- .../kotlin/ftl/environment/ListLocales.kt | 38 ++++++++++-- .../kotlin/ftl/android/AndroidCatalogTest.kt | 4 +- .../src/test/kotlin/ftl/ios/IosCatalogTest.kt | 4 +- 13 files changed, 46 insertions(+), 86 deletions(-) delete mode 100644 test_runner/src/main/kotlin/ftl/adapter/google/ListLocales.kt diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/ListLocales.kt b/test_runner/src/main/kotlin/ftl/adapter/google/ListLocales.kt deleted file mode 100644 index 90f043edfb..0000000000 --- a/test_runner/src/main/kotlin/ftl/adapter/google/ListLocales.kt +++ /dev/null @@ -1,59 +0,0 @@ -package ftl.adapter.google - -import ftl.api.Locale -import ftl.environment.TAGS -import ftl.environment.TestEnvironmentInfo -import ftl.environment.createTableColumnFor -import ftl.environment.getOrCreateList -import ftl.environment.tagToSystemOutColorMapper -import ftl.run.exception.FlankGeneralError -import ftl.util.applyColorsUsing -import ftl.util.buildTable - -fun List.asPrintableTable() = createTestEnvironment().createLocalesTable() - -fun List.createTestEnvironment() = - fold(mutableMapOf>()) { allLocales, locale -> - allLocales.apply { - getOrCreateList(LOCALE).add(locale.id.orEmpty()) - getOrCreateList(NAME).add(locale.name.orEmpty()) - getOrCreateList(REGION).add(locale.region.orEmpty()) - getOrCreateList(TAGS).add(locale.tags.joinToString().orEmpty()) - } - } - -fun TestEnvironmentInfo.createLocalesTable() = buildTable( - createTableColumnFor(LOCALE), - createTableColumnFor(NAME), - createTableColumnFor(REGION), - createTableColumnFor(ftl.environment.TAGS).applyColorsUsing(tagToSystemOutColorMapper) -) - -private const val LOCALE = "LOCALE" -private const val NAME = "NAME" -private const val REGION = "REGION" - -fun List.getLocaleDescription(localeId: String) = - findLocales(localeId)?.prepareDescription().orErrorMessage(localeId).plus("\n") - -private fun List.findLocales(localeId: String) = find { it.id == localeId } - -private fun Locale.prepareDescription() = """ - id: $id - name: $name -""".trimIndent().addRegionIfExist(region).addTagsIfExists(this) - -private fun String.addRegionIfExist(region: String?) = - if (!region.isNullOrEmpty()) StringBuilder(this).appendLine("\nregion: $region").trim().toString() - else this - -private fun String.addTagsIfExists(locale: Locale) = - if (!locale.tags.isNullOrEmpty()) StringBuilder(this).appendLine("\ntags:").appendTagsToList(locale) - else this - -private fun StringBuilder.appendTagsToList(locale: Locale) = apply { - locale.tags.filterNotNull().forEach { tag -> appendLine("- $tag") } -}.trim().toString() - -private fun String?.orErrorMessage(locale: String) = - this ?: throw FlankGeneralError("ERROR: '$locale' is not a valid locale") diff --git a/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt index 297975e376..52c89b6403 100644 --- a/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt +++ b/test_runner/src/main/kotlin/ftl/adapter/google/LocalesAdapter.kt @@ -1,8 +1,9 @@ package ftl.adapter.google import ftl.api.Locale +import com.google.testing.model.Locale as GoogleApiLocale -internal fun List.toApiModel(): List = map { locale -> +internal fun List.toApiModel(): List = map { locale -> Locale( id = locale.id.orEmpty(), name = locale.name.orEmpty(), 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 4772cac9a2..e205612543 100644 --- a/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/client/google/AndroidCatalog.kt @@ -8,7 +8,6 @@ import flank.common.logLn import ftl.api.fetchAndroidOsVersion import ftl.environment.android.getDescription import ftl.environment.android.toCliTable -import ftl.environment.asPrintableTable import ftl.environment.getLocaleDescription import ftl.gc.GcTesting import ftl.http.executeWithRetry @@ -40,8 +39,6 @@ object AndroidCatalog { fun supportedOrientations(projectId: String): List = deviceCatalog(projectId).runtimeConfiguration.orientations - private fun localesAsTable(projectId: String) = getLocales(projectId).asPrintableTable() - private fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale) internal fun getLocales(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.locales diff --git a/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt b/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt index 1a9a7c02b1..a7cb741a52 100644 --- a/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/client/google/IosCatalog.kt @@ -4,7 +4,6 @@ import com.google.testing.model.IosDeviceCatalog import com.google.testing.model.IosModel import com.google.testing.model.Orientation import ftl.config.Device -import ftl.environment.asPrintableTable import ftl.environment.getLocaleDescription import ftl.environment.ios.getDescription import ftl.environment.ios.toCliTable @@ -29,8 +28,6 @@ object IosCatalog { private fun getVersionsList(projectId: String) = iosDeviceCatalog(projectId).versions - private fun localesAsTable(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales.asPrintableTable() - private fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale) internal fun getLocales(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt index ff2abeb9d3..e575f5b519 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidLocales.kt @@ -1,11 +1,11 @@ package ftl.domain import flank.common.log -import ftl.adapter.google.getLocaleDescription import ftl.api.Locale import ftl.api.Platform import ftl.api.fetchLocales import ftl.args.AndroidArgs +import ftl.environment.getLocaleDescription import ftl.run.exception.FlankConfigurationError import java.nio.file.Paths diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt index 4437d28953..0c7cfb77b6 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeAndroidTestEnvironment.kt @@ -1,7 +1,6 @@ package ftl.domain import flank.common.logLn -import ftl.adapter.google.asPrintableTable import ftl.api.Locale.Identity import ftl.api.Platform import ftl.api.fetchAndroidOsVersion @@ -26,7 +25,7 @@ fun DescribeAndroidTestEnvironment.invoke() { // 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)).asPrintableTable()) + 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 diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt index 061dd927fa..7ad05b9569 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeIosLocales.kt @@ -1,11 +1,11 @@ package ftl.domain import flank.common.log -import ftl.adapter.google.getLocaleDescription import ftl.api.Locale.Identity import ftl.api.Platform import ftl.api.fetchLocales import ftl.args.IosArgs +import ftl.environment.getLocaleDescription import ftl.run.exception.FlankConfigurationError import java.nio.file.Paths diff --git a/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt b/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt index e2739d9d75..ca10e57819 100644 --- a/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt +++ b/test_runner/src/main/kotlin/ftl/domain/DescribeIosTestEnvironment.kt @@ -1,7 +1,6 @@ package ftl.domain import flank.common.logLn -import ftl.adapter.google.asPrintableTable import ftl.api.Locale.Identity import ftl.api.Platform import ftl.api.fetchDeviceModelIos @@ -25,7 +24,7 @@ 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)).asPrintableTable()) + 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 diff --git a/test_runner/src/main/kotlin/ftl/domain/ListAndroidLocales.kt b/test_runner/src/main/kotlin/ftl/domain/ListAndroidLocales.kt index f1c0d41bb3..2e8353c8b5 100644 --- a/test_runner/src/main/kotlin/ftl/domain/ListAndroidLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/ListAndroidLocales.kt @@ -1,11 +1,11 @@ package ftl.domain import flank.common.logLn -import ftl.adapter.google.asPrintableTable import ftl.api.Locale.Identity import ftl.api.Platform import ftl.api.fetchLocales import ftl.args.AndroidArgs +import ftl.environment.toCliTable import java.nio.file.Paths interface ListAndroidLocales { @@ -14,6 +14,6 @@ interface ListAndroidLocales { operator fun ListAndroidLocales.invoke() { logLn( - fetchLocales(Identity(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, Platform.ANDROID)).asPrintableTable() + fetchLocales(Identity(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, Platform.ANDROID)).toCliTable() ) } diff --git a/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt b/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt index 280b31a0c6..9050b19717 100644 --- a/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt +++ b/test_runner/src/main/kotlin/ftl/domain/ListIosLocales.kt @@ -1,11 +1,11 @@ package ftl.domain import flank.common.logLn -import ftl.adapter.google.asPrintableTable import ftl.api.Locale.Identity import ftl.api.Platform import ftl.api.fetchLocales import ftl.args.IosArgs +import ftl.environment.toCliTable import java.nio.file.Paths interface ListIosLocales { @@ -13,5 +13,5 @@ interface ListIosLocales { } operator fun ListIosLocales.invoke() { - logLn(fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS)).asPrintableTable()) + logLn(fetchLocales(Identity(IosArgs.loadOrDefault(Paths.get(configPath)).project, Platform.IOS)).toCliTable()) } diff --git a/test_runner/src/main/kotlin/ftl/environment/ListLocales.kt b/test_runner/src/main/kotlin/ftl/environment/ListLocales.kt index a377b7b0f8..3e146e8702 100644 --- a/test_runner/src/main/kotlin/ftl/environment/ListLocales.kt +++ b/test_runner/src/main/kotlin/ftl/environment/ListLocales.kt @@ -1,28 +1,54 @@ package ftl.environment -import com.google.testing.model.Locale +import ftl.api.Locale +import ftl.run.exception.FlankGeneralError import ftl.util.applyColorsUsing import ftl.util.buildTable -fun List.asPrintableTable() = createTestEnvironment().createLocalesTable() +fun List.toCliTable() = createTestEnvironment().createLocalesTable() -private fun List.createTestEnvironment() = +fun List.createTestEnvironment() = fold(mutableMapOf>()) { allLocales, locale -> allLocales.apply { getOrCreateList(LOCALE).add(locale.id.orEmpty()) getOrCreateList(NAME).add(locale.name.orEmpty()) getOrCreateList(REGION).add(locale.region.orEmpty()) - getOrCreateList(TAGS).add(locale.tags?.joinToString().orEmpty()) + getOrCreateList(TAGS).add(locale.tags.joinToString().orEmpty()) } } -private fun TestEnvironmentInfo.createLocalesTable() = buildTable( +fun TestEnvironmentInfo.createLocalesTable() = buildTable( createTableColumnFor(LOCALE), createTableColumnFor(NAME), createTableColumnFor(REGION), - createTableColumnFor(TAGS).applyColorsUsing(tagToSystemOutColorMapper) + createTableColumnFor(ftl.environment.TAGS).applyColorsUsing(tagToSystemOutColorMapper) ) private const val LOCALE = "LOCALE" private const val NAME = "NAME" private const val REGION = "REGION" + +fun List.getLocaleDescription(localeId: String) = + findLocales(localeId)?.prepareDescription().orErrorMessage(localeId).plus("\n") + +private fun List.findLocales(localeId: String) = find { it.id == localeId } + +private fun Locale.prepareDescription() = """ + id: $id + name: $name +""".trimIndent().addRegionIfExist(region).addTagsIfExists(this) + +private fun String.addRegionIfExist(region: String?) = + if (!region.isNullOrEmpty()) StringBuilder(this).appendLine("\nregion: $region").trim().toString() + else this + +private fun String.addTagsIfExists(locale: Locale) = + if (!locale.tags.isNullOrEmpty()) StringBuilder(this).appendLine("\ntags:").appendTagsToList(locale) + else this + +private fun StringBuilder.appendTagsToList(locale: Locale) = apply { + locale.tags.filterNotNull().forEach { tag -> appendLine("- $tag") } +}.trim().toString() + +private fun String?.orErrorMessage(locale: String) = + this ?: throw FlankGeneralError("ERROR: '$locale' is not a valid locale") diff --git a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt index cdee6f8c6e..3b43448a86 100644 --- a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt @@ -2,7 +2,6 @@ package ftl.android import com.google.common.truth.Truth.assertThat import com.google.testing.model.AndroidDevice -import ftl.adapter.google.asPrintableTable import ftl.api.Locale import ftl.api.Platform import ftl.api.fetchAndroidOsVersion @@ -10,6 +9,7 @@ import ftl.api.fetchDeviceModelAndroid import ftl.api.fetchLocales import ftl.client.google.AndroidCatalog import ftl.environment.android.toCliTable +import ftl.environment.toCliTable import ftl.test.util.FlankTestRunner import io.mockk.every import io.mockk.mockk @@ -114,7 +114,7 @@ class AndroidCatalogTest { val expectedSeparatorCount = expectedHeaders.size + 1 // when - val devicesTable = fetchLocales(Locale.Identity(projectId, Platform.ANDROID)).asPrintableTable() + val devicesTable = fetchLocales(Locale.Identity(projectId, Platform.ANDROID)).toCliTable() val headers = devicesTable.lines()[1] // then diff --git a/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt b/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt index a9787a3763..38cf899d43 100644 --- a/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt @@ -1,11 +1,11 @@ package ftl.ios import com.google.common.truth.Truth.assertThat -import ftl.adapter.google.asPrintableTable import ftl.api.Locale.Identity import ftl.api.Platform import ftl.api.fetchLocales import ftl.client.google.IosCatalog +import ftl.environment.toCliTable import ftl.test.util.FlankTestRunner import org.junit.Test import org.junit.runner.RunWith @@ -48,7 +48,7 @@ class IosCatalogTest { val expectedSeparatorCount = expectedHeaders.size + 1 // when - val devicesTable = fetchLocales(Identity(projectId, Platform.IOS)).asPrintableTable() + val devicesTable = fetchLocales(Identity(projectId, Platform.IOS)).toCliTable() val headers = devicesTable.lines()[1] // then