Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix printing supported versions id #1338

Merged
merged 4 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ftl.android

import com.google.api.services.testing.model.AndroidDevice
import com.google.api.services.testing.model.AndroidDeviceCatalog
import ftl.config.Device
import ftl.environment.android.asPrintableTable
import ftl.environment.android.getDescription
import ftl.environment.asPrintableTable
Expand Down Expand Up @@ -33,6 +34,9 @@ object AndroidCatalog {

private fun getModels(projectId: String) = deviceCatalog(projectId).models

fun Device.getSupportedVersionId(projectId: String): List<String> = getModels(projectId).find { it.id == model }?.supportedVersionIds
?: emptyList()

fun supportedVersionsAsTable(projectId: String) = getVersionsList(projectId).asPrintableTable()

fun describeSoftwareVersion(projectId: String, versionId: String) = getVersionsList(projectId).getDescription(versionId)
Expand Down
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftl.args

import ftl.android.AndroidCatalog
import ftl.android.AndroidCatalog.getSupportedVersionId
import ftl.android.IncompatibleModelVersion
import ftl.android.SupportedDeviceConfig
import ftl.android.UnsupportedModelId
Expand Down Expand Up @@ -108,7 +109,7 @@ private fun AndroidArgs.assertDevicesSupported() = devices
AndroidCatalog.androidVersionIds(project)
}"
)
IncompatibleModelVersion -> throw IncompatibleTestDimensionError("Incompatible model, '${device.model}', and version, '${device.version}'\nSupported version ids for '${device.model}': $check")
IncompatibleModelVersion -> throw IncompatibleTestDimensionError("Incompatible model, '${device.model}', and version, '${device.version}'\nSupported version ids for '${device.model}': ${device.getSupportedVersionId(project).joinToString { it }}")
}
}

Expand Down
3 changes: 2 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/ValidateIosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ftl.args

import ftl.args.yml.Type
import ftl.ios.IosCatalog
import ftl.ios.IosCatalog.getSupportedVersionId
import ftl.run.exception.FlankConfigurationError
import ftl.run.exception.IncompatibleTestDimensionError

Expand Down Expand Up @@ -66,7 +67,7 @@ private fun IosArgs.assertXcodeSupported() = when {

private fun IosArgs.assertDevicesSupported() = devices.forEach { device ->
if (!IosCatalog.supportedDevice(device.model, device.version, this.project))
throw IncompatibleTestDimensionError("iOS ${device.version} on ${device.model} is not a supported device")
throw IncompatibleTestDimensionError("iOS ${device.version} on ${device.model} is not a supported\nSupported version ids for '${device.model}': ${device.getSupportedVersionId(project).joinToString()}")
}

private fun IosArgs.assertTestFiles() {
Expand Down
4 changes: 4 additions & 0 deletions test_runner/src/main/kotlin/ftl/ios/IosCatalog.kt
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.config.Device
import ftl.environment.asPrintableTable
import ftl.environment.common.asPrintableTable
import ftl.environment.getLocaleDescription
Expand Down Expand Up @@ -51,6 +52,9 @@ object IosCatalog {
projectId: String
) = iosDeviceCatalog(projectId).models.find { it.id == modelId }?.supportedVersionIds?.contains(versionId) ?: false

fun Device.getSupportedVersionId(projectId: String): List<String> = iosDeviceCatalog(projectId).models.find { it.id == model }?.supportedVersionIds
?: emptyList()

// Device catalogMap is different depending on the project id
private fun iosDeviceCatalog(
projectId: String
Expand Down
19 changes: 19 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import ftl.run.exception.IncompatibleTestDimensionError
import ftl.run.model.GameLoopContext
import ftl.shard.Chunk
import ftl.shard.TestMethod
import ftl.test.util.TestHelper.getThrowable
import ftl.util.asFileReference
import io.mockk.every
import io.mockk.mockkObject
Expand Down Expand Up @@ -2357,6 +2358,24 @@ AndroidArgs
""".trimIndent()
AndroidArgs.load(yaml).validate()
}

@Test
fun `should return correct message if version is not supported for device`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
device:
- model: Nexus7
version: 28
""".trimIndent()
val errorMessage = getThrowable { AndroidArgs.load(yaml).validate() }.message ?: ""
val expectedMessage = """
Incompatible model, 'Nexus7', and version, '28'
Supported version ids for 'Nexus7': 19, 21, 22
""".trimIndent()
assertEquals(expectedMessage, errorMessage)
}
}

private fun AndroidArgs.Companion.load(yamlData: String, cli: AndroidRunCommand? = null): AndroidArgs =
Expand Down
4 changes: 2 additions & 2 deletions test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ flank:

@Test
fun `args invalidDeviceExits`() {
assertThrowsWithMessage(Throwable::class, "iOS 99.9 on iphoneZ is not a supported device") {
val invalidDevice = mutableListOf(Device("iphoneZ", "99.9"))
assertThrowsWithMessage(Throwable::class, "iOS 11.2 on iphonexsmax is not a supported\nSupported version ids for 'iphonexsmax': 12.0, 12.1") {
val invalidDevice = mutableListOf(Device("iphonexsmax", "11.2"))
createIosArgs(
config = defaultIosConfig().apply {
common.gcloud.devices = invalidDevice
Expand Down