From 2a659eb8d9d2c3b2023e33ea1dfc14c10b02d47a Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Tue, 21 Jul 2020 18:26:17 +0200 Subject: [PATCH] #884 added printing available locales for iOS devices --- ...r_-firebase-test-ios-test-environment.adoc | 4 +-- .../ascii/flank.jar_-firebase-test-ios.adoc | 5 +++- .../flank.jar_-ios-test-environment.adoc | 4 +-- test_runner/docs/ascii/flank.jar_-ios.adoc | 5 +++- .../ftl/cli/firebase/test/IosCommand.kt | 2 ++ .../test/ios/IosTestEnvironmentCommand.kt | 11 ++++--- .../ios/configuration/IosLocalesCommand.kt | 21 +++++++++++++ .../configuration/IosLocalesListCommand.kt | 30 +++++++++++++++++++ .../kotlin/ftl/environment/ListLocales.kt | 28 +++++++++++++++++ .../src/main/kotlin/ftl/ios/IosCatalog.kt | 2 ++ .../IosLocalesListCommandTest.kt | 16 ++++++++++ .../src/test/kotlin/ftl/ios/IosCatalogTest.kt | 20 +++++++++++++ 12 files changed, 138 insertions(+), 10 deletions(-) create mode 100644 test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesCommand.kt create mode 100644 test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommand.kt create mode 100644 test_runner/src/main/kotlin/ftl/environment/ListLocales.kt create mode 100644 test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt diff --git a/test_runner/docs/ascii/flank.jar_-firebase-test-ios-test-environment.adoc b/test_runner/docs/ascii/flank.jar_-firebase-test-ios-test-environment.adoc index b7f9828989..e97024e71f 100644 --- a/test_runner/docs/ascii/flank.jar_-firebase-test-ios-test-environment.adoc +++ b/test_runner/docs/ascii/flank.jar_-firebase-test-ios-test-environment.adoc @@ -4,7 +4,7 @@ == Name flank.jar --firebase-test-ios-test-environment - Print available devices, OS versions, provided software list and network configuration to test against +-firebase-test-ios-test-environment - Print available devices, OS versions, locales, provided software list and network configuration to test against // end::picocli-generated-man-section-name[] @@ -19,7 +19,7 @@ flank.jar // tag::picocli-generated-man-section-description[] == Description -Print available iOS devices, iOS OS versions list, provided software and network configuration to test against +Print available iOS devices, iOS OS versions list, locales, provided software and network configuration to test against // end::picocli-generated-man-section-description[] diff --git a/test_runner/docs/ascii/flank.jar_-firebase-test-ios.adoc b/test_runner/docs/ascii/flank.jar_-firebase-test-ios.adoc index b112056a05..8833be8b45 100644 --- a/test_runner/docs/ascii/flank.jar_-firebase-test-ios.adoc +++ b/test_runner/docs/ascii/flank.jar_-firebase-test-ios.adoc @@ -38,8 +38,11 @@ flank.jar *versions*:: Information about available software versions +*locales*:: + Information about available locales on device + *test-environment*:: - Print available devices, OS versions, provided software list and network configuration to test against + Print available devices, OS versions, locales, provided software list and network configuration to test against // end::picocli-generated-man-section-commands[] diff --git a/test_runner/docs/ascii/flank.jar_-ios-test-environment.adoc b/test_runner/docs/ascii/flank.jar_-ios-test-environment.adoc index eb46b5d284..ca2cd3cb19 100644 --- a/test_runner/docs/ascii/flank.jar_-ios-test-environment.adoc +++ b/test_runner/docs/ascii/flank.jar_-ios-test-environment.adoc @@ -4,7 +4,7 @@ == Name flank.jar --ios-test-environment - Print available devices, OS versions, provided software list and network configuration to test against +-ios-test-environment - Print available devices, OS versions, locales, provided software list and network configuration to test against // end::picocli-generated-man-section-name[] @@ -19,7 +19,7 @@ flank.jar // tag::picocli-generated-man-section-description[] == Description -Print available iOS devices, iOS OS versions list, provided software and network configuration to test against +Print available iOS devices, iOS OS versions list, locales, provided software and network configuration to test against // end::picocli-generated-man-section-description[] diff --git a/test_runner/docs/ascii/flank.jar_-ios.adoc b/test_runner/docs/ascii/flank.jar_-ios.adoc index 8b91852d00..a380767e9a 100644 --- a/test_runner/docs/ascii/flank.jar_-ios.adoc +++ b/test_runner/docs/ascii/flank.jar_-ios.adoc @@ -38,8 +38,11 @@ flank.jar *versions*:: Information about available software versions +*locales*:: + Information about available locales on device + *test-environment*:: - Print available devices, OS versions, provided software list and network configuration to test against + Print available devices, OS versions, locales, provided software list and network configuration to test against // end::picocli-generated-man-section-commands[] diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/IosCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/IosCommand.kt index cdb99d881a..9115d01878 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/IosCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/IosCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test import ftl.cli.firebase.test.ios.IosDoctorCommand import ftl.cli.firebase.test.ios.IosRunCommand import ftl.cli.firebase.test.ios.IosTestEnvironmentCommand +import ftl.cli.firebase.test.ios.configuration.IosLocalesCommand import ftl.cli.firebase.test.ios.models.IosModelsCommand import ftl.cli.firebase.test.ios.versions.IosVersionsCommand import picocli.CommandLine @@ -16,6 +17,7 @@ import picocli.CommandLine.Command IosDoctorCommand::class, IosModelsCommand::class, IosVersionsCommand::class, + IosLocalesCommand::class, IosTestEnvironmentCommand::class ], usageHelpAutoWidth = true diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosTestEnvironmentCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosTestEnvironmentCommand.kt index 5550cd9600..6d927b1bef 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosTestEnvironmentCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosTestEnvironmentCommand.kt @@ -5,6 +5,7 @@ import ftl.config.FtlConstants import ftl.environment.providedSoftwareAsTable import ftl.environment.networkConfigurationAsTable import ftl.ios.IosCatalog.devicesCatalogAsTable +import ftl.ios.IosCatalog.localesAsTable import ftl.ios.IosCatalog.softwareVersionsAsTable import picocli.CommandLine import java.nio.file.Paths @@ -16,14 +17,16 @@ import java.nio.file.Paths descriptionHeading = "%n@|bold,underline Description:|@%n%n", parameterListHeading = "%n@|bold,underline Parameters:|@%n", optionListHeading = "%n@|bold,underline Options:|@%n", - header = ["Print available devices, OS versions, provided software list and network configuration to test against"], - description = ["Print available iOS devices, iOS OS versions list, provided software and network configuration to test against"], + header = ["Print available devices, OS versions, locales, provided software list and network configuration to test against"], + description = ["Print available iOS devices, iOS OS versions list, locales, provided software and network configuration to test against"], usageHelpAutoWidth = true ) class IosTestEnvironmentCommand : Runnable { override fun run() { - println(devicesCatalogAsTable(IosArgs.load(Paths.get(configPath)).project)) - println(softwareVersionsAsTable(IosArgs.load(Paths.get(configPath)).project)) + val projectId = IosArgs.load(Paths.get(configPath)).project + println(devicesCatalogAsTable(projectId)) + println(softwareVersionsAsTable(projectId)) + println(localesAsTable(projectId)) println(providedSoftwareAsTable()) println(networkConfigurationAsTable()) } diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesCommand.kt new file mode 100644 index 0000000000..9ba8da4fe3 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesCommand.kt @@ -0,0 +1,21 @@ +package ftl.cli.firebase.test.ios.configuration + +import picocli.CommandLine + +@CommandLine.Command( + name = "locales", + headerHeading = "", + synopsisHeading = "%n", + descriptionHeading = "%n@|bold,underline Description:|@%n%n", + parameterListHeading = "%n@|bold,underline Parameters:|@%n", + optionListHeading = "%n@|bold,underline Options:|@%n", + header = ["Information about available locales on device"], + description = ["Information about available locales on device. For example prints list of available locales to test against"], + subcommands = [IosLocalesListCommand::class], + usageHelpAutoWidth = true +) +class IosLocalesCommand : Runnable { + override fun run() { + CommandLine.usage(IosLocalesCommand(), System.out) + } +} diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommand.kt new file mode 100644 index 0000000000..56cf167571 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommand.kt @@ -0,0 +1,30 @@ +package ftl.cli.firebase.test.ios.configuration + +import ftl.args.IosArgs +import ftl.config.FtlConstants +import ftl.ios.IosCatalog.localesAsTable +import picocli.CommandLine +import java.nio.file.Paths + +@CommandLine.Command( + name = "list", + headerHeading = "", + synopsisHeading = "%n", + descriptionHeading = "%n@|bold,underline Description:|@%n%n", + parameterListHeading = "%n@|bold,underline Parameters:|@%n", + optionListHeading = "%n@|bold,underline Options:|@%n", + header = ["Print current list of locales available to test against"], + description = ["Print current list of iOS locales available to test against"], + usageHelpAutoWidth = true +) +class IosLocalesListCommand : Runnable { + override fun run() { + println(localesAsTable(projectId = IosArgs.load(Paths.get(configPath)).project)) + } + + @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) + var configPath: String = FtlConstants.defaultIosConfig + + @CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["Prints this help message"]) + var usageHelpRequested: Boolean = false +} diff --git a/test_runner/src/main/kotlin/ftl/environment/ListLocales.kt b/test_runner/src/main/kotlin/ftl/environment/ListLocales.kt new file mode 100644 index 0000000000..5a4e477084 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/environment/ListLocales.kt @@ -0,0 +1,28 @@ +package ftl.environment + +import com.google.api.services.testing.model.Locale +import ftl.util.applyColorsUsing +import ftl.util.buildTable + +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" diff --git a/test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt b/test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt index a4b58418d7..2f3a056f95 100644 --- a/test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt @@ -18,6 +18,8 @@ object IosCatalog { fun softwareVersionsAsTable(projectId: String) = iosDeviceCatalog(projectId).versions.asPrintableTable() + fun localesAsTable(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales.asPrintableTable() + fun supportedXcode(version: String, projectId: String) = xcodeVersions(projectId).contains(version) private fun xcodeVersions(projectId: String) = 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 new file mode 100644 index 0000000000..4bdc516285 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommandTest.kt @@ -0,0 +1,16 @@ +package ftl.cli.firebase.test.ios.configuration + +import com.google.common.truth.Truth +import org.junit.Test +import picocli.CommandLine + +class IosLocalesListCommandTest { + + @Test + fun androidLocalesListCommandShouldParseConfig() { + val cmd = IosLocalesListCommand() + CommandLine(cmd).parseArgs("--config=a") + + Truth.assertThat(cmd.configPath).isEqualTo("a") + } +} diff --git a/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt b/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt index d2e035a9e1..a1ab3841c8 100644 --- a/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt @@ -60,4 +60,24 @@ class IosCatalogTest { // number of separators match assertThat(headers.count { it == '│' }).isEqualTo(expectedSeparatorCount) } + + @Test + fun `should print available locales as table`() { + // given + val expectedHeaders = + arrayOf("LOCALE", "NAME", "REGION", "TAGS") + val expectedSeparatorCount = expectedHeaders.size + 1 + + // when + val devicesTable = IosCatalog.localesAsTable(projectId) + val headers = devicesTable.lines()[1] + + // then + // has all necessary headers + expectedHeaders.forEach { + assertThat(headers.contains(it)).isTrue() + } + // number of separators match + assertThat(headers.count { it == '│' }).isEqualTo(expectedSeparatorCount) + } }