Skip to content

Commit

Permalink
#884 added printing available locales for Android devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Adamczyk committed Jul 21, 2020
1 parent bc7097d commit 0429bc9
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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[]

Expand All @@ -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[]

Expand Down
5 changes: 4 additions & 1 deletion test_runner/docs/ascii/flank.jar_-android.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]

Expand All @@ -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[]

Expand Down
5 changes: 4 additions & 1 deletion test_runner/docs/ascii/flank.jar_-firebase-test-android.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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[]

Expand Down
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,6 +17,7 @@ import picocli.CommandLine.Command
AndroidDoctorCommand::class,
AndroidModelsCommand::class,
AndroidVersionsCommand::class,
AndroidLocalesCommand::class,
AndroidTestEnvironmentCommand::class
],
usageHelpAutoWidth = true
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 28 additions & 0 deletions test_runner/src/main/kotlin/ftl/environment/ListLocales.kt
Original file line number Diff line number Diff line change
@@ -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<Locale>.asPrintableTable() = createTestEnvironment().createLocalesTable()

private fun List<Locale>.createTestEnvironment() =
fold(mutableMapOf<String, MutableList<String>>()) { 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"
20 changes: 20 additions & 0 deletions test_runner/src/test/kotlin/ftl/android/AndroidCatalogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 0429bc9

Please sign in to comment.