Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#884 added printing available locales for iOS devices #908

Merged
merged 2 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [#901](https://github.com/Flank/flank/pull/901) Added option to print Android and iOS available test-environment. ([piotradamczyk5](https://github.com/piotradamczyk5))
- [#904](https://github.com/Flank/flank/pull/904) Added option to print provided software. ([piotradamczyk5](https://github.com/piotradamczyk5))
- [#906](https://github.com/Flank/flank/pull/906) Added option to print network profiles. ([adamfilipow92](https://github.com/adamfilipow92))
- [#908](https://github.com/Flank/flank/pull/908) Added option to print iOS available locales to test against. ([piotradamczyk5](https://github.com/piotradamczyk5))
-
-

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

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

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

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

Expand Down
5 changes: 4 additions & 1 deletion test_runner/docs/ascii/flank.jar_-ios.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 @@ -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
Expand All @@ -16,6 +17,7 @@ import picocli.CommandLine.Command
IosDoctorCommand::class,
IosModelsCommand::class,
IosVersionsCommand::class,
IosLocalesCommand::class,
IosTestEnvironmentCommand::class
],
usageHelpAutoWidth = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 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())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
}
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"
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
}
20 changes: 20 additions & 0 deletions test_runner/src/test/kotlin/ftl/ios/IosCatalogTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}