Skip to content

Commit e633445

Browse files
feat: add locales description command for ios and android (#969)
1 parent 7899ba7 commit e633445

11 files changed

Lines changed: 235 additions & 4 deletions

File tree

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [#987](https://github.com/Flank/flank/pull/987) Flank Error Monitoring readme addition ([sloox](https://github.com/Sloox))
44
- [#990](https://github.com/Flank/flank/pull/990) Fix: exclusion of @Suppress test. ([piotradamczyk5](https://github.com/piotradamczyk5))
55
- [#988](https://github.com/Flank/flank/pull/988) Add versions description command for ios and android. ([adamfilipow92](https://github.com/adamfilipow92))
6+
- [#969](https://github.com/Flank/flank/pull/969) Add locales description command for ios and android. ([adamfilipow92](https://github.com/adamfilipow92))
67
-
78

89
## v20.08.1

test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ftl.environment.android.asPrintableTable
66
import ftl.environment.android.getDescription
77
import ftl.environment.asPrintableTable
88
import ftl.environment.common.asPrintableTable
9+
import ftl.environment.getLocaleDescription
910
import ftl.gc.GcTesting
1011
import ftl.http.executeWithRetry
1112

@@ -36,7 +37,11 @@ object AndroidCatalog {
3637

3738
fun supportedOrientationsAsTable(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.orientations.asPrintableTable()
3839

39-
fun localesAsTable(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.locales.asPrintableTable()
40+
fun localesAsTable(projectId: String) = getLocales(projectId).asPrintableTable()
41+
42+
fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale)
43+
44+
private fun getLocales(projectId: String) = deviceCatalog(projectId).runtimeConfiguration.locales
4045

4146
fun androidModelIds(projectId: String) =
4247
modelMap.getOrPut(projectId) { deviceCatalog(projectId).models.map { it.id } }

test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import picocli.CommandLine
1111
optionListHeading = "%n@|bold,underline Options:|@%n",
1212
header = ["Information about available locales on device"],
1313
description = ["Information about available locales on device. For example prints list of available locales to test against"],
14-
subcommands = [AndroidLocalesListCommand::class],
14+
subcommands = [AndroidLocalesListCommand::class, AndroidLocalesDescribeCommand::class],
1515
usageHelpAutoWidth = true
1616
)
1717
class AndroidLocalesCommand : Runnable {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ftl.cli.firebase.test.android.configuration
2+
3+
import ftl.android.AndroidCatalog.getLocaleDescription
4+
import ftl.args.AndroidArgs
5+
import ftl.config.FtlConstants
6+
import ftl.util.FlankConfigurationError
7+
import picocli.CommandLine
8+
import java.nio.file.Paths
9+
10+
@CommandLine.Command(
11+
name = "describe",
12+
headerHeading = "",
13+
synopsisHeading = "%n",
14+
descriptionHeading = "%n@|bold,underline Description:|@%n%n",
15+
parameterListHeading = "%n@|bold,underline Parameters:|@%n",
16+
optionListHeading = "%n@|bold,underline Options:|@%n",
17+
header = ["Describe a locales "],
18+
usageHelpAutoWidth = true
19+
)
20+
class AndroidLocalesDescribeCommand : Runnable {
21+
override fun run() {
22+
if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.")
23+
print(getLocaleDescription(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, locale))
24+
}
25+
26+
@CommandLine.Parameters(
27+
index = "0",
28+
arity = "1",
29+
paramLabel = "LOCALE",
30+
defaultValue = "",
31+
description = ["The locale to describe, found" +
32+
" using \$ gcloud firebase test android locales list\n."]
33+
)
34+
var locale: String = ""
35+
36+
@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"])
37+
var configPath: String = FtlConstants.defaultAndroidConfig
38+
}

test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import picocli.CommandLine
1111
optionListHeading = "%n@|bold,underline Options:|@%n",
1212
header = ["Information about available locales on device"],
1313
description = ["Information about available locales on device. For example prints list of available locales to test against"],
14-
subcommands = [IosLocalesListCommand::class],
14+
subcommands = [IosLocalesListCommand::class, IosLocalesDescribeCommand::class],
1515
usageHelpAutoWidth = true
1616
)
1717
class IosLocalesCommand : Runnable {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ftl.cli.firebase.test.ios.configuration
2+
3+
import ftl.args.IosArgs
4+
import ftl.config.FtlConstants
5+
import ftl.ios.IosCatalog.getLocaleDescription
6+
import ftl.util.FlankConfigurationError
7+
import picocli.CommandLine
8+
import java.nio.file.Paths
9+
10+
@CommandLine.Command(
11+
name = "describe",
12+
headerHeading = "",
13+
synopsisHeading = "%n",
14+
descriptionHeading = "%n@|bold,underline Description:|@%n%n",
15+
parameterListHeading = "%n@|bold,underline Parameters:|@%n",
16+
optionListHeading = "%n@|bold,underline Options:|@%n",
17+
header = ["Describe a locales "],
18+
usageHelpAutoWidth = true
19+
)
20+
class IosLocalesDescribeCommand : Runnable {
21+
override fun run() {
22+
if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.")
23+
print(getLocaleDescription(IosArgs.loadOrDefault(Paths.get(configPath)).project, locale))
24+
}
25+
26+
@CommandLine.Parameters(
27+
index = "0",
28+
arity = "1",
29+
paramLabel = "LOCALE",
30+
defaultValue = "",
31+
description = ["The locale to describe, found" +
32+
" using \$ gcloud firebase test ios locales list\n."]
33+
)
34+
var locale: String = ""
35+
36+
@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"])
37+
var configPath: String = FtlConstants.defaultIosConfig
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package ftl.environment
2+
3+
import com.google.api.services.testing.model.Locale
4+
import ftl.util.FlankGeneralError
5+
6+
fun List<Locale>.getLocaleDescription(localeId: String) = findLocales(localeId)?.prepareDescription().orErrorMessage(localeId).plus("\n")
7+
8+
private fun List<Locale>.findLocales(localeId: String) = find { it.id == localeId }
9+
10+
private fun Locale.prepareDescription() = """
11+
id: $id
12+
name: $name
13+
""".trimIndent().addRegionIfExist(region).addTagsIfExists(this)
14+
15+
private fun String.addRegionIfExist(region: String?) =
16+
if (!region.isNullOrEmpty()) StringBuilder(this).appendln("\nregion: $region").trim().toString()
17+
else this
18+
19+
private fun String.addTagsIfExists(locale: Locale) =
20+
if (!locale.tags.isNullOrEmpty()) StringBuilder(this).appendln("\ntags:").appendTagsToList(locale)
21+
else this
22+
23+
private fun StringBuilder.appendTagsToList(locale: Locale) = apply {
24+
locale.tags.filterNotNull().forEach { tag -> appendln("- $tag") }
25+
}.trim().toString()
26+
27+
private fun String?.orErrorMessage(locale: String) = this ?: throw FlankGeneralError("ERROR: '$locale' is not a valid locale")

test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package ftl.ios
22

33
import com.google.api.services.testing.model.IosDeviceCatalog
4-
import ftl.environment.android.asPrintableTable
54
import ftl.environment.asPrintableTable
65
import ftl.environment.common.asPrintableTable
76
import ftl.environment.ios.asPrintableTable
87
import ftl.environment.ios.getDescription
8+
import ftl.environment.getLocaleDescription
99
import ftl.gc.GcTesting
1010
import ftl.http.executeWithRetry
1111

@@ -28,6 +28,10 @@ object IosCatalog {
2828

2929
fun localesAsTable(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales.asPrintableTable()
3030

31+
fun getLocaleDescription(projectId: String, locale: String) = getLocales(projectId).getLocaleDescription(locale)
32+
33+
private fun getLocales(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.locales
34+
3135
fun supportedOrientationsAsTable(projectId: String) = iosDeviceCatalog(projectId).runtimeConfiguration.orientations.asPrintableTable()
3236

3337
fun supportedXcode(version: String, projectId: String) = xcodeVersions(projectId).contains(version)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package ftl.cli.firebase.test.android.configuration
2+
3+
import ftl.android.AndroidCatalog
4+
import ftl.test.util.TestHelper.getThrowable
5+
import ftl.util.FlankConfigurationError
6+
import io.mockk.mockkObject
7+
import io.mockk.verify
8+
import org.junit.Assert.assertEquals
9+
import org.junit.Rule
10+
import org.junit.Test
11+
import org.junit.contrib.java.lang.system.SystemOutRule
12+
import picocli.CommandLine
13+
14+
class AndroidLocalesDescribeCommandTest {
15+
@get:Rule
16+
val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests()
17+
18+
@Test
19+
fun `should execute AndroidCatalog getLocaleDescription when run AndroidLocalesDescribeCommand`() {
20+
mockkObject(AndroidCatalog) {
21+
CommandLine(AndroidLocalesDescribeCommand()).execute("pl")
22+
verify { AndroidCatalog.getLocaleDescription(any(), any()) }
23+
}
24+
}
25+
26+
@Test(expected = FlankConfigurationError::class)
27+
fun `should throw if locale not specified`() {
28+
CommandLine(AndroidLocalesDescribeCommand()).execute()
29+
}
30+
31+
@Test
32+
fun `should return error message if locale not exists`() {
33+
val exception = getThrowable { CommandLine(AndroidLocalesDescribeCommand()).execute("test") }
34+
assertEquals("ERROR: 'test' is not a valid locale", exception.message)
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package ftl.cli.firebase.test.ios.configuration
2+
3+
import ftl.ios.IosCatalog
4+
import ftl.test.util.TestHelper
5+
import ftl.test.util.TestHelper.getThrowable
6+
import ftl.util.FlankConfigurationError
7+
import io.mockk.mockkObject
8+
import io.mockk.verify
9+
import org.junit.Assert.assertEquals
10+
import org.junit.Rule
11+
import org.junit.Test
12+
import org.junit.contrib.java.lang.system.SystemOutRule
13+
import picocli.CommandLine
14+
15+
class IosLocalesDescribeCommandTest {
16+
@get:Rule
17+
val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests()
18+
19+
private val simpleFlankPath = TestHelper.getPath("src/test/kotlin/ftl/fixtures/simple-ios-flank.yml")
20+
21+
@Test
22+
fun `should execute IosCatalog getLocaleDescription when run IosLocalesDescribeCommand`() {
23+
mockkObject(IosCatalog) {
24+
CommandLine(IosLocalesDescribeCommand()).execute("pl", "--config=$simpleFlankPath")
25+
verify { IosCatalog.getLocaleDescription(any(), any()) }
26+
}
27+
}
28+
29+
@Test(expected = FlankConfigurationError::class)
30+
fun `should throw if locale not specified`() {
31+
CommandLine(IosLocalesDescribeCommand()).execute("--config=$simpleFlankPath")
32+
}
33+
34+
@Test
35+
fun `should return error message if locale not exists`() {
36+
val exception = getThrowable { CommandLine(IosLocalesDescribeCommand()).execute("test", "--config=$simpleFlankPath") }
37+
val result = exception.message
38+
assertEquals("ERROR: 'test' is not a valid locale", result)
39+
}
40+
}

0 commit comments

Comments
 (0)