-
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.
- Loading branch information
Piotr Adamczyk
committed
Jul 16, 2020
1 parent
ca1270a
commit c3d2423
Showing
11 changed files
with
164 additions
and
34 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
21 changes: 21 additions & 0 deletions
21
test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelsCommand.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.ios.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 = [IosModelsListCommand::class], | ||
usageHelpAutoWidth = true | ||
) | ||
class IosModelsCommand : Runnable { | ||
override fun run() { | ||
CommandLine.usage(IosModelsCommand(), System.out) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelsListCommand.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.cli.firebase.test.ios.models | ||
|
||
import ftl.args.IosArgs | ||
import ftl.config.FtlConstants | ||
import ftl.ios.IosCatalog.devicesCatalogAsTable | ||
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 iOS devices available to test against"], | ||
usageHelpAutoWidth = true | ||
) | ||
class IosModelsListCommand : Runnable { | ||
override fun run() { | ||
println(devicesCatalogAsTable(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 | ||
} |
29 changes: 29 additions & 0 deletions
29
test_runner/src/main/kotlin/ftl/environment/ListIOsDevices.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.environment | ||
|
||
import com.google.api.services.testing.model.IosModel | ||
import ftl.util.applyColorsUsing | ||
import ftl.util.buildTable | ||
|
||
fun List<IosModel>.asPrintableTable() = createTestEnvironmentInfo().createIoDevicesTable() | ||
|
||
fun List<IosModel>.createTestEnvironmentInfo() = | ||
fold(mutableMapOf<String, MutableList<String>>()) { deviceInfo, iOsDevice -> | ||
deviceInfo.apply { | ||
getOrCreateList(MODEL_ID).add(iOsDevice.id.orUnknown()) | ||
getOrCreateList(MODEL_NAME).add(iOsDevice.name.orUnknown()) | ||
getOrCreateList(RESOLUTION).add(iOsDevice.resolution) | ||
getOrCreateList(OS_VERSION_IDS).add(iOsDevice.supportedVersionIds?.joinToString().orEmpty()) | ||
getOrCreateList(TAGS).add(iOsDevice.tags?.joinToString().orEmpty()) | ||
} | ||
} | ||
|
||
private val IosModel.resolution | ||
get() = if (screenX == null || screenY == null) "UNKNOWN" else "$screenY x $screenX" | ||
|
||
private fun TestEnvironmentInfo.createIoDevicesTable() = buildTable( | ||
createTableColumnFor(MODEL_ID), | ||
createTableColumnFor(MODEL_NAME), | ||
createTableColumnFor(RESOLUTION), | ||
createTableColumnFor(OS_VERSION_IDS), | ||
createTableColumnFor(TAGS).applyColorsUsing(tagToSystemOutColorMapper) | ||
) |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package ftl.ios | ||
|
||
import com.google.api.services.testing.model.IosDeviceCatalog | ||
import ftl.environment.asPrintableTable | ||
import ftl.gc.GcTesting | ||
import ftl.http.executeWithRetry | ||
|
||
|
@@ -13,30 +14,33 @@ object IosCatalog { | |
private val catalogMap: MutableMap<String, IosDeviceCatalog> = mutableMapOf() | ||
private val xcodeMap: MutableMap<String, List<String>> = mutableMapOf() | ||
|
||
fun xcodeVersions(projectId: String): List<String> { | ||
val cached = xcodeMap[projectId] | ||
if (cached != null) return cached | ||
fun devicesCatalogAsTable(projectId: String) = iosDeviceCatalog(projectId).models.asPrintableTable() | ||
|
||
val newVersions = iosDeviceCatalog(projectId).xcodeVersions.map { it.version } | ||
xcodeMap[projectId] = newVersions | ||
return newVersions | ||
} | ||
fun supportedXcode(version: String, projectId: String) = xcodeVersions(projectId).contains(version) | ||
|
||
// Device catalogMap is different depending on the project id | ||
fun iosDeviceCatalog(projectId: String): IosDeviceCatalog { | ||
val cached = catalogMap[projectId] | ||
if (cached != null) return cached | ||
private fun xcodeVersions(projectId: String) = | ||
xcodeMap.getOrPut(projectId) { iosDeviceCatalog(projectId).xcodeVersions.map { it.version } } | ||
|
||
fun supportedDevice( | ||
modelId: String, | ||
versionId: String, | ||
projectId: String | ||
) = iosDeviceCatalog(projectId).models.find { it.id == modelId }?.supportedVersionIds?.contains(versionId) ?: false | ||
|
||
try { | ||
val newCatalog = GcTesting.get.testEnvironmentCatalog() | ||
// Device catalogMap is different depending on the project id | ||
private fun iosDeviceCatalog( | ||
projectId: String | ||
) = try { | ||
catalogMap.getOrPut(projectId) { | ||
GcTesting.get.testEnvironmentCatalog() | ||
.get("ios") | ||
.setProjectId(projectId) | ||
.executeWithRetry().iosDeviceCatalog | ||
catalogMap[projectId] = newCatalog | ||
return newCatalog | ||
} catch (e: java.lang.Exception) { | ||
throw java.lang.RuntimeException( | ||
""" | ||
.executeWithRetry() | ||
.iosDeviceCatalog | ||
} | ||
} catch (e: java.lang.Exception) { | ||
throw java.lang.RuntimeException( | ||
""" | ||
Unable to access the test environment catalogMap. Firebase Test Lab for iOS is currently in beta. | ||
Request access for your project via the following form: | ||
https://goo.gl/forms/wAxbiNEP2pxeIRG82 | ||
|
@@ -46,16 +50,6 @@ on the Blaze or Flame billing plans, and that you have run | |
gcloud config set billing/quota_project project | ||
If you are still having issues, please email [email protected] for support.""", e | ||
) | ||
} | ||
} | ||
|
||
fun supportedXcode(version: String, projectId: String): Boolean { | ||
return xcodeVersions(projectId).contains(version) | ||
} | ||
|
||
fun supportedDevice(modelId: String, versionId: String, projectId: String): Boolean { | ||
val model = iosDeviceCatalog(projectId).models.find { it.id == modelId } | ||
return model?.supportedVersionIds?.contains(versionId) ?: false | ||
) | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/models/IosModelsListCommandTest.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.ios.models | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import ftl.config.FtlConstants | ||
import org.junit.Test | ||
import picocli.CommandLine | ||
|
||
class IosModelsListCommandTest { | ||
|
||
@Test | ||
fun iosModelsListCommandOptions() { | ||
val cmd = IosModelsListCommand() | ||
assertThat(cmd.configPath).isEqualTo(FtlConstants.defaultIosConfig) | ||
cmd.configPath = "tmp" | ||
assertThat(cmd.configPath).isEqualTo("tmp") | ||
|
||
assertThat(cmd.usageHelpRequested).isFalse() | ||
cmd.usageHelpRequested = true | ||
assertThat(cmd.usageHelpRequested).isTrue() | ||
} | ||
|
||
@Test | ||
fun iosModelsListCommandShouldParseConfig() { | ||
val cmd = IosModelsListCommand() | ||
CommandLine(cmd).parseArgs("--config=a") | ||
|
||
assertThat(cmd.configPath).isEqualTo("a") | ||
} | ||
} |
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