-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add versions description command for ios and android (#988)
- Loading branch information
1 parent
f6007e5
commit 654421f
Showing
13 changed files
with
372 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
.../src/main/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsDescribeCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ftl.cli.firebase.test.android.versions | ||
|
||
import ftl.android.AndroidCatalog | ||
import ftl.args.AndroidArgs | ||
import ftl.config.FtlConstants | ||
import ftl.util.FlankConfigurationError | ||
import picocli.CommandLine | ||
import java.nio.file.Paths | ||
|
||
@CommandLine.Command( | ||
name = "describe", | ||
headerHeading = "", | ||
synopsisHeading = "%n", | ||
descriptionHeading = "%n@|bold,underline Description:|@%n%n", | ||
parameterListHeading = "%n@|bold,underline Parameters:|@%n", | ||
optionListHeading = "%n@|bold,underline Options:|@%n", | ||
header = ["List of OS versions available to test against"], | ||
description = ["Print current list of android versions available to test against"], | ||
usageHelpAutoWidth = true | ||
) | ||
class AndroidVersionsDescribeCommand : Runnable { | ||
override fun run() { | ||
if (versionId.isBlank()) throw FlankConfigurationError("Argument VERSION_ID must be specified.") | ||
println(AndroidCatalog.describeSoftwareVersion(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, versionId)) | ||
} | ||
|
||
@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) | ||
var configPath: String = FtlConstants.defaultAndroidConfig | ||
|
||
@CommandLine.Parameters( | ||
index = "0", | ||
arity = "1", | ||
paramLabel = "VERSION_ID", | ||
defaultValue = "", | ||
description = ["The version to describe, found" + | ||
" using \$ gcloud firebase test android versions list."] | ||
) | ||
var versionId: String = "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ftl.cli.firebase.test.ios.versions | ||
|
||
import ftl.args.IosArgs | ||
import ftl.config.FtlConstants | ||
import ftl.ios.IosCatalog | ||
import ftl.util.FlankConfigurationError | ||
import picocli.CommandLine | ||
import java.nio.file.Paths | ||
|
||
@CommandLine.Command( | ||
name = "describe", | ||
headerHeading = "", | ||
synopsisHeading = "%n", | ||
descriptionHeading = "%n@|bold,underline Description:|@%n%n", | ||
parameterListHeading = "%n@|bold,underline Parameters:|@%n", | ||
optionListHeading = "%n@|bold,underline Options:|@%n", | ||
header = ["List of OS versions available to test against"], | ||
description = ["Print current list of iOS versions available to test against"], | ||
usageHelpAutoWidth = true | ||
) | ||
class IosVersionsDescribeCommand : Runnable { | ||
override fun run() { | ||
if (versionId.isBlank()) throw FlankConfigurationError("Argument VERSION_ID must be specified.") | ||
println(IosCatalog.describeSoftwareVersion(IosArgs.loadOrDefault(Paths.get(configPath)).project, versionId)) | ||
} | ||
|
||
@CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) | ||
var configPath: String = FtlConstants.defaultIosConfig | ||
|
||
@CommandLine.Parameters( | ||
index = "0", | ||
arity = "1", | ||
paramLabel = "VERSION_ID", | ||
defaultValue = "", | ||
description = ["The version to describe, found" + | ||
" using \$ gcloud firebase test ios versions list."] | ||
) | ||
var versionId: String = "" | ||
} |
32 changes: 32 additions & 0 deletions
32
test_runner/src/main/kotlin/ftl/environment/android/AndroidSoftwareVersionDescription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ftl.environment.android | ||
|
||
import com.google.api.services.testing.model.AndroidVersion | ||
import ftl.util.FlankGeneralError | ||
|
||
fun List<AndroidVersion>.getDescription(versionId: String) = findVersion(versionId)?.prepareDescription().orErrorMessage(versionId) | ||
|
||
private fun List<AndroidVersion>.findVersion(versionId: String) = firstOrNull { it.id == versionId } | ||
|
||
private fun AndroidVersion.prepareDescription() = """ | ||
apiLevel: $apiLevel | ||
codeName: $codeName | ||
id: '$id' | ||
releaseDate: | ||
day: ${releaseDate.day} | ||
month: ${releaseDate.month} | ||
year: ${releaseDate.year} | ||
""".trimIndent().addDataIfExists(tags).addVersion(versionString).trim() | ||
|
||
private fun String.addVersion(versionString: String) = StringBuilder(this).appendln("\nversionString: $versionString").toString() | ||
|
||
private fun String.addDataIfExists(data: List<String?>?) = | ||
if (!data.isNullOrEmpty()) StringBuilder(this).appendln("\n$TAGS_HEADER:").appendDataToList(data) | ||
else this | ||
|
||
private fun StringBuilder.appendDataToList(data: List<String?>) = apply { | ||
data.filterNotNull().forEach { item -> appendln("- $item") } | ||
}.toString().trim() | ||
|
||
private fun String?.orErrorMessage(versionId: String) = this ?: throw FlankGeneralError("ERROR: '$versionId' is not a valid OS version") | ||
|
||
private const val TAGS_HEADER = "tags" |
27 changes: 27 additions & 0 deletions
27
test_runner/src/main/kotlin/ftl/environment/ios/IosSoftwareVersionDescription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ftl.environment.ios | ||
|
||
import com.google.api.services.testing.model.IosVersion | ||
import ftl.util.FlankGeneralError | ||
|
||
fun List<IosVersion>.getDescription(versionId: String) = findVersion(versionId)?.prepareDescription().orErrorMessage(versionId) | ||
|
||
private fun List<IosVersion>.findVersion(versionId: String) = firstOrNull { it.id == versionId } | ||
|
||
private fun IosVersion.prepareDescription() = """ | ||
id: '$id' | ||
majorVersion: $majorVersion | ||
minorVersion: $minorVersion | ||
""".trimIndent().addDataIfExists(SUPPORTED_VERSIONS_HEADER, supportedXcodeVersionIds).addDataIfExists(TAGS_HEADER, tags) | ||
|
||
private fun String.addDataIfExists(header: String, data: List<String?>?) = | ||
if (!data.isNullOrEmpty()) StringBuilder(this).appendln("\n$header:").appendDataToList(data) | ||
else this | ||
|
||
private fun StringBuilder.appendDataToList(data: List<String?>) = apply { | ||
data.filterNotNull().forEach { item -> appendln("- $item") } | ||
}.toString().trim() | ||
|
||
private fun String?.orErrorMessage(versionId: String) = this ?: throw FlankGeneralError("ERROR: '$versionId' is not a valid OS version") | ||
|
||
private const val TAGS_HEADER = "tags" | ||
private const val SUPPORTED_VERSIONS_HEADER = "supportedXcodeVersionIds" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../test/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsDescribeCommandTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ftl.cli.firebase.test.android.versions | ||
|
||
import ftl.android.AndroidCatalog | ||
import ftl.cli.firebase.test.ios.versions.IosVersionsDescribeCommand | ||
import ftl.test.util.TestHelper | ||
import ftl.util.FlankConfigurationError | ||
import io.mockk.mockkObject | ||
import io.mockk.verify | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import picocli.CommandLine | ||
|
||
class AndroidVersionsDescribeCommandTest { | ||
|
||
@Test | ||
fun `should execute AndroidCatalog describeSoftwareVersion when run AndroidVersionsDescribeCommand`() { | ||
mockkObject(AndroidCatalog) { | ||
CommandLine(AndroidVersionsDescribeCommand()).execute("21") | ||
verify { AndroidCatalog.describeSoftwareVersion(any(), any()) } | ||
} | ||
} | ||
|
||
@Test(expected = FlankConfigurationError::class) | ||
fun `should throw if version not specified`() { | ||
CommandLine(AndroidVersionsDescribeCommand()).execute() | ||
} | ||
|
||
@Test | ||
fun `should return error message if version not exists`() { | ||
val exception = TestHelper.getThrowable { CommandLine(IosVersionsDescribeCommand()).execute("test") } | ||
assertEquals("ERROR: 'test' is not a valid OS version", exception.message) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...nner/src/test/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommandTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ftl.cli.firebase.test.ios.versions | ||
|
||
import ftl.ios.IosCatalog | ||
import ftl.test.util.TestHelper.getThrowable | ||
import ftl.util.FlankConfigurationError | ||
import io.mockk.mockkObject | ||
import io.mockk.verify | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.contrib.java.lang.system.SystemOutRule | ||
import picocli.CommandLine | ||
|
||
class IosVersionsDescribeCommandTest { | ||
@get:Rule | ||
val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests() | ||
|
||
@Test | ||
fun `should execute IosCatalog describeSoftwareVersion when run IosVersionsDescribeCommand`() { | ||
mockkObject(IosCatalog) { | ||
CommandLine(IosVersionsDescribeCommand()).execute("10.3") | ||
verify { IosCatalog.describeSoftwareVersion(any(), any()) } | ||
} | ||
} | ||
|
||
@Test(expected = FlankConfigurationError::class) | ||
fun `should throw if version not specified`() { | ||
CommandLine(IosVersionsDescribeCommand()).execute() | ||
} | ||
|
||
@Test | ||
fun `should return error message if version not exists`() { | ||
val exception = getThrowable { CommandLine(IosVersionsDescribeCommand()).execute("test") } | ||
assertEquals("ERROR: 'test' is not a valid OS version", exception.message) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
test_runner/src/test/kotlin/ftl/environment/android/AndroidSoftwareVersionDescriptionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package ftl.environment.android | ||
|
||
import com.google.api.services.testing.model.AndroidVersion | ||
import com.google.api.services.testing.model.Date | ||
import ftl.test.util.TestHelper.getThrowable | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class AndroidSoftwareVersionDescriptionTest { | ||
@Test | ||
fun `should return software version with tag if any tag exists`() { | ||
val versions = listOf(AndroidVersion().apply { | ||
id = "26" | ||
apiLevel = 26 | ||
codeName = "Oreo" | ||
versionString = "8.0.x" | ||
releaseDate = Date().apply { | ||
day = 21 | ||
month = 8 | ||
year = 2017 | ||
} | ||
tags = listOf("default") | ||
}) | ||
|
||
val localesDescription = versions.getDescription("26") | ||
val expected = """ | ||
apiLevel: 26 | ||
codeName: Oreo | ||
id: '26' | ||
releaseDate: | ||
day: 21 | ||
month: 8 | ||
year: 2017 | ||
tags: | ||
- default | ||
versionString: 8.0.x | ||
""".trimIndent() | ||
Assert.assertEquals(expected, localesDescription) | ||
} | ||
|
||
@Test | ||
fun `should return software version without tag if no tags`() { | ||
val versions = listOf(AndroidVersion().apply { | ||
id = "23" | ||
apiLevel = 23 | ||
codeName = "Marshmallow" | ||
versionString = "6.0.x" | ||
releaseDate = Date().apply { | ||
day = 5 | ||
month = 10 | ||
year = 2015 | ||
} | ||
}) | ||
|
||
val localesDescription = versions.getDescription("23") | ||
val expected = """ | ||
apiLevel: 23 | ||
codeName: Marshmallow | ||
id: '23' | ||
releaseDate: | ||
day: 5 | ||
month: 10 | ||
year: 2015 | ||
versionString: 6.0.x | ||
""".trimIndent() | ||
Assert.assertEquals(expected, localesDescription) | ||
} | ||
|
||
@Test | ||
fun `should return error message if version not found`() { | ||
val versions = listOf<AndroidVersion>() | ||
val versionName = "test" | ||
val localesDescription = getThrowable { versions.getDescription(versionName) } | ||
val expected = "ERROR: '$versionName' is not a valid OS version" | ||
Assert.assertEquals(expected, localesDescription.message) | ||
} | ||
} |
Oops, something went wrong.