-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9113bd2
commit ca1270a
Showing
16 changed files
with
231 additions
and
76 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
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
21 changes: 21 additions & 0 deletions
21
test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsCommand.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,21 @@ | ||
package ftl.cli.firebase.test.android.models | ||
|
||
import picocli.CommandLine | ||
|
||
@CommandLine.Command( | ||
name = "models", | ||
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 models"], | ||
description = ["Information about available models. For example prints list of available models to test against"], | ||
subcommands = [AndroidModelsListCommand::class], | ||
usageHelpAutoWidth = true | ||
) | ||
class AndroidModelsCommand : Runnable { | ||
override fun run() { | ||
CommandLine.usage(AndroidModelsCommand(), System.out) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommand.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,31 @@ | ||
package ftl.cli.firebase.test.android.models | ||
|
||
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 devices available to test against"], | ||
description = ["Print current list of Android devices available to test against"], | ||
usageHelpAutoWidth = true | ||
) | ||
class AndroidModelsListCommand : Runnable { | ||
override fun run() { | ||
val config = AndroidArgs.load(Paths.get(configPath)) | ||
println(AndroidCatalog.devicesCatalogAsTable(config.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 | ||
} |
38 changes: 38 additions & 0 deletions
38
test_runner/src/main/kotlin/ftl/environment/ListAndroidDevices.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,38 @@ | ||
package ftl.environment | ||
|
||
import com.google.api.services.testing.model.AndroidModel | ||
import ftl.util.SystemOutColor | ||
import ftl.util.applyColorsUsing | ||
import ftl.util.buildTable | ||
|
||
fun List<AndroidModel>.asPrintableTable() = createTestEnvironmentInfo().createAndroidDevicesTable() | ||
|
||
private fun List<AndroidModel>.createTestEnvironmentInfo() = | ||
fold(mutableMapOf<String, MutableList<String>>()) { devicesInfo, androidDevice -> | ||
devicesInfo.apply { | ||
getOrCreateList(MODEL_ID).add(androidDevice.codename.orUnknown()) | ||
getOrCreateList(MAKE).add(androidDevice.manufacturer.orUnknown()) | ||
getOrCreateList(MODEL_NAME).add(androidDevice.name.orUnknown()) | ||
getOrCreateList(FORM).add(androidDevice.form.orUnknown()) | ||
getOrCreateList(RESOLUTION).add(androidDevice.resolution) | ||
getOrCreateList(OS_VERSION_IDS).add(androidDevice.supportedVersionIds?.joinToString().orEmpty()) | ||
getOrCreateList(TAGS).add(androidDevice.tags?.joinToString().orEmpty()) | ||
} | ||
} | ||
|
||
private fun TestEnvironmentInfo.createAndroidDevicesTable() = buildTable( | ||
createTableColumnFor(MODEL_ID), | ||
createTableColumnFor(MAKE), | ||
createTableColumnFor(MODEL_NAME), | ||
createTableColumnFor(FORM).applyColorsUsing(formToSystemOutColorMapper), | ||
createTableColumnFor(RESOLUTION), | ||
createTableColumnFor(OS_VERSION_IDS), | ||
createTableColumnFor(TAGS).applyColorsUsing(tagToSystemOutColorMapper) | ||
) | ||
|
||
private val AndroidModel.resolution | ||
get() = if (screenX == null || screenY == null) "UNKNOWN" else "$screenY x $screenX" | ||
|
||
private val formToSystemOutColorMapper: (String) -> SystemOutColor = { | ||
if (it == PHYSICAL_DEVICE) SystemOutColor.YELLOW else SystemOutColor.BLUE | ||
} |
30 changes: 30 additions & 0 deletions
30
test_runner/src/main/kotlin/ftl/environment/TestEnvironmentInfo.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,30 @@ | ||
package ftl.environment | ||
|
||
import ftl.util.SystemOutColor | ||
import ftl.util.TableColumn | ||
|
||
typealias TestEnvironmentInfo = MutableMap<String, MutableList<String>> | ||
|
||
internal fun TestEnvironmentInfo.getOrCreateList(key: String) = getOrPut(key) { mutableListOf() } | ||
|
||
internal fun TestEnvironmentInfo.createTableColumnFor(key: String) = TableColumn(key, getValue(key)) | ||
|
||
internal val tagToSystemOutColorMapper: (String) -> SystemOutColor = { | ||
when { | ||
it.contains("deprecated=") -> SystemOutColor.RED | ||
it == "default" -> SystemOutColor.GREEN | ||
it == "beta" -> SystemOutColor.YELLOW | ||
else -> SystemOutColor.DEFAULT | ||
} | ||
} | ||
|
||
internal fun String?.orUnknown() = this ?: "UNKNOWN" | ||
|
||
const val MODEL_ID = "MODEL_ID" | ||
const val MAKE = "MAKE" | ||
const val MODEL_NAME = "MODEL_NAME" | ||
const val FORM = "FORM" | ||
const val RESOLUTION = "RESOLUTION" | ||
const val OS_VERSION_IDS = "OS_VERSION_IDS" | ||
const val TAGS = "TAGS" | ||
const val PHYSICAL_DEVICE = "PHYSICAL" |
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
28 changes: 0 additions & 28 deletions
28
test_runner/src/test/kotlin/ftl/cli/firebase/test/AndroidCommandTest.kt
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
...nner/src/test/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommandTest.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,29 @@ | ||
package ftl.cli.firebase.test.android.models | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import ftl.config.FtlConstants | ||
import org.junit.Test | ||
import picocli.CommandLine | ||
|
||
class AndroidModelsListCommandTest { | ||
|
||
@Test | ||
fun androidModelsListCommandOptions() { | ||
val cmd = AndroidModelsListCommand() | ||
assertThat(cmd.configPath).isEqualTo(FtlConstants.defaultAndroidConfig) | ||
cmd.configPath = "tmp" | ||
assertThat(cmd.configPath).isEqualTo("tmp") | ||
|
||
assertThat(cmd.usageHelpRequested).isFalse() | ||
cmd.usageHelpRequested = true | ||
assertThat(cmd.usageHelpRequested).isTrue() | ||
} | ||
|
||
@Test | ||
fun androidModelsListCommandShouldParseConfig() { | ||
val cmd = AndroidModelsListCommand() | ||
CommandLine(cmd).parseArgs("--config=a") | ||
|
||
assertThat(cmd.configPath).isEqualTo("a") | ||
} | ||
} |
Oops, something went wrong.