-
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.
#835 Added printing Android devices list
- Loading branch information
Piotr Adamczyk
committed
Jul 14, 2020
1 parent
38e965e
commit 95298a2
Showing
17 changed files
with
295 additions
and
48 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
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: 28 additions & 0 deletions
28
test_runner/src/test/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsCommandTest.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,28 @@ | ||
package ftl.cli.firebase.test.android.models | ||
|
||
import com.google.common.truth.Truth | ||
import ftl.test.util.TestHelper.normalizeLineEnding | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.contrib.java.lang.system.SystemOutRule | ||
|
||
class AndroidModelsCommandTest { | ||
@Rule | ||
@JvmField | ||
val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests() | ||
|
||
@Test | ||
fun androidModelsCommandPrintsHelp() { | ||
AndroidModelsCommand().run() | ||
val output = systemOutRule.log.normalizeLineEnding() | ||
Truth.assertThat(output).startsWith( | ||
"Information about available models\n\n" + | ||
"models [COMMAND]\n\n" + | ||
"Description:\n\n" + | ||
"Information about available models. For example prints list of available models\n" + | ||
"to test against\n" + | ||
"Commands:\n" + | ||
" list Print current list of devices available to test against" | ||
) | ||
} | ||
} |
Oops, something went wrong.