From 0429bc953dd4e3e89fcd0f392c6f845de914998a Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Tue, 21 Jul 2020 18:02:25 +0200 Subject: [PATCH] #884 added printing available locales for Android devices --- .../flank.jar_-android-test-environment.adoc | 4 +-- .../docs/ascii/flank.jar_-android.adoc | 5 +++- ...irebase-test-android-test-environment.adoc | 4 +-- .../flank.jar_-firebase-test-android.adoc | 5 +++- .../main/kotlin/ftl/android/AndroidCatalog.kt | 2 ++ .../ftl/cli/firebase/test/AndroidCommand.kt | 2 ++ .../android/AndroidTestEnvironmentCommand.kt | 11 ++++--- .../configuration/AndroidLocalesCommand.kt | 21 +++++++++++++ .../AndroidLocalesListCommand.kt | 30 +++++++++++++++++++ .../kotlin/ftl/environment/ListLocales.kt | 28 +++++++++++++++++ .../kotlin/ftl/android/AndroidCatalogTest.kt | 20 +++++++++++++ .../AndroidLocalesListCommandTest.kt | 16 ++++++++++ 12 files changed, 138 insertions(+), 10 deletions(-) create mode 100644 test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesCommand.kt create mode 100644 test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommand.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/android/configuration/AndroidLocalesListCommandTest.kt diff --git a/test_runner/docs/ascii/flank.jar_-android-test-environment.adoc b/test_runner/docs/ascii/flank.jar_-android-test-environment.adoc index 4c5553896f..a643b038e2 100644 --- a/test_runner/docs/ascii/flank.jar_-android-test-environment.adoc +++ b/test_runner/docs/ascii/flank.jar_-android-test-environment.adoc @@ -4,7 +4,7 @@ == Name flank.jar --android-test-environment - Print available devices, OS versions, provided software list and network configuration to test against +-android-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 Android devices, Android OS versions list, provided software and network configuration to test against +Print available Android devices, Android 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_-android.adoc b/test_runner/docs/ascii/flank.jar_-android.adoc index 0087dcc265..8d1dbaae44 100644 --- a/test_runner/docs/ascii/flank.jar_-android.adoc +++ b/test_runner/docs/ascii/flank.jar_-android.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_-firebase-test-android-test-environment.adoc b/test_runner/docs/ascii/flank.jar_-firebase-test-android-test-environment.adoc index 332ee77266..fe38e91711 100644 --- a/test_runner/docs/ascii/flank.jar_-firebase-test-android-test-environment.adoc +++ b/test_runner/docs/ascii/flank.jar_-firebase-test-android-test-environment.adoc @@ -4,7 +4,7 @@ == Name flank.jar --firebase-test-android-test-environment - Print available devices, OS versions, provided software list and network configuration to test against +-firebase-test-android-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 Android devices, Android OS versions list, provided software and network configuration to test against +Print available Android devices, Android 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-android.adoc b/test_runner/docs/ascii/flank.jar_-firebase-test-android.adoc index 19b5eb7916..99937185bc 100644 --- a/test_runner/docs/ascii/flank.jar_-firebase-test-android.adoc +++ b/test_runner/docs/ascii/flank.jar_-firebase-test-android.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/android/AndroidCatalog.kt b/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt index 84e4001f32..9fb226f7b0 100644 --- a/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt @@ -27,6 +27,8 @@ object AndroidCatalog { fun supportedVersionsAsTable(projectId: String) = deviceCatalog(projectId).versions.asPrintableTable() + fun localesAsTable(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.locales.asPrintableTable() + fun androidModelIds(projectId: String) = modelMap.getOrPut(projectId) { deviceCatalog(projectId).models.map { it.id } } diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/AndroidCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/AndroidCommand.kt index 8013b03e5e..035a0b7973 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/AndroidCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/AndroidCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test import ftl.cli.firebase.test.android.AndroidDoctorCommand import ftl.cli.firebase.test.android.AndroidRunCommand import ftl.cli.firebase.test.android.AndroidTestEnvironmentCommand +import ftl.cli.firebase.test.android.configuration.AndroidLocalesCommand import ftl.cli.firebase.test.android.models.AndroidModelsCommand import ftl.cli.firebase.test.android.versions.AndroidVersionsCommand import picocli.CommandLine @@ -16,6 +17,7 @@ import picocli.CommandLine.Command AndroidDoctorCommand::class, AndroidModelsCommand::class, AndroidVersionsCommand::class, + AndroidLocalesCommand::class, AndroidTestEnvironmentCommand::class ], usageHelpAutoWidth = true diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidTestEnvironmentCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidTestEnvironmentCommand.kt index 09e08199e1..56d748a5d7 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidTestEnvironmentCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidTestEnvironmentCommand.kt @@ -1,6 +1,7 @@ package ftl.cli.firebase.test.android import ftl.android.AndroidCatalog.devicesCatalogAsTable +import ftl.android.AndroidCatalog.localesAsTable import ftl.android.AndroidCatalog.supportedVersionsAsTable import ftl.args.AndroidArgs import ftl.config.FtlConstants @@ -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 Android devices, Android 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 Android devices, Android OS versions list, locales, provided software and network configuration to test against"], usageHelpAutoWidth = true ) class AndroidTestEnvironmentCommand : Runnable { override fun run() { - println(devicesCatalogAsTable(AndroidArgs.load(Paths.get(configPath)).project)) - println(supportedVersionsAsTable(AndroidArgs.load(Paths.get(configPath)).project)) + val projectId = AndroidArgs.load(Paths.get(configPath)).project + println(devicesCatalogAsTable(projectId)) + println(supportedVersionsAsTable(projectId)) + println(localesAsTable(projectId)) println(providedSoftwareAsTable()) println(networkConfigurationAsTable()) } diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesCommand.kt new file mode 100644 index 0000000000..7029cc1215 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesCommand.kt @@ -0,0 +1,21 @@ +package ftl.cli.firebase.test.android.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 = [AndroidLocalesListCommand::class], + usageHelpAutoWidth = true +) +class AndroidLocalesCommand : Runnable { + override fun run() { + CommandLine.usage(AndroidLocalesCommand(), System.out) + } +} diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommand.kt new file mode 100644 index 0000000000..7e983e54a7 --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommand.kt @@ -0,0 +1,30 @@ +package ftl.cli.firebase.test.android.configuration + +import ftl.android.AndroidCatalog +import ftl.args.AndroidArgs +import ftl.config.FtlConstants +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 Android locales available to test against"], + usageHelpAutoWidth = true +) +class AndroidLocalesListCommand : Runnable { + override fun run() { + println(AndroidCatalog.localesAsTable(projectId = AndroidArgs.load(Paths.get(configPath)).project)) + } + + @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) + var configPath: String = FtlConstants.defaultAndroidConfig + + @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/test/kotlin/ftl/android/AndroidCatalogTest.kt b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt index 0b5fffb274..aebb9cec09 100644 --- a/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt +++ b/test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt @@ -107,4 +107,24 @@ class AndroidCatalogTest { // 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 = AndroidCatalog.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) + } } diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommandTest.kt new file mode 100644 index 0000000000..649f60ac52 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommandTest.kt @@ -0,0 +1,16 @@ +package ftl.cli.firebase.test.android.configuration + +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import picocli.CommandLine + +class AndroidLocalesListCommandTest { + + @Test + fun androidLocalesListCommandShouldParseConfig() { + val cmd = AndroidLocalesListCommand() + CommandLine(cmd).parseArgs("--config=a") + + assertThat(cmd.configPath).isEqualTo("a") + } +}