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

feat: Add Type to iOS #1284

Merged
merged 3 commits into from
Oct 29, 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
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ gcloud:
# - gs://bucket/additional.ipa
# - path/to/local/ipa/file.ipa

## The type of iOS test to run. TYPE must be one of: xctest, game-loop. Default: xctest
# type: xctest

flank:
# -- FlankYml --

Expand Down
3 changes: 3 additions & 0 deletions test_runner/flank.ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ gcloud:
# - gs://bucket/additional.ipa
# - path/to/local/ipa/file.ipa

## The type of iOS test to run. TYPE must be one of: xctest, game-loop. Default: xctest
# type: xctest

flank:
# -- FlankYml --

Expand Down
1 change: 0 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ data class AndroidArgs(
val environmentVariables: Map<String, String>, // should not be printed, becuase could contains sensitive informations
val directoriesToPull: List<String>,
val grantPermissions: String?,
val type: Type?,
val scenarioNumbers: List<String>,
val scenarioLabels: List<String>,
val obbFiles: List<String>,
Expand Down
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/CommonArgs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ftl.args

import ftl.args.yml.Type
import ftl.config.Device
import ftl.run.status.OutputStyle

Expand All @@ -18,6 +19,7 @@ data class CommonArgs(
override val clientDetails: Map<String, String>?,
override val networkProfile: String?,
override val otherFiles: Map<String, String>,
override val type: Type?,

// flank
override val project: String,
Expand Down
4 changes: 1 addition & 3 deletions test_runner/src/main/kotlin/ftl/args/CreateAndroidArgs.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ftl.args

import ftl.args.yml.AppTestPair
import ftl.args.yml.Type
import ftl.config.AndroidConfig
import ftl.config.android.AndroidFlankConfig
import ftl.config.android.AndroidGcloudConfig
Expand Down Expand Up @@ -43,6 +42,5 @@ fun createAndroidArgs(
obbFiles = gcloud.obbfiles!!,
obbNames = gcloud.obbnames!!,
scenarioNumbers = gcloud.scenarioNumbers!!,
grantPermissions = gcloud.grantPermissions,
type = gcloud.type?.let { Type.fromString(it) }
grantPermissions = gcloud.grantPermissions
)
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/CreateCommonArgs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ftl.args

import ftl.args.yml.toType
import ftl.config.CommonConfig
import ftl.run.status.OutputStyle
import ftl.run.status.asOutputStyle
Expand All @@ -25,6 +26,7 @@ fun CommonConfig.createCommonArgs(
networkProfile = gcloud.networkProfile,
clientDetails = gcloud.clientDetails,
otherFiles = gcloud.otherFiles!!.mapValues { (_, path) -> path.normalizeFilePath() },
type = gcloud.type?.toType(),

// flank
maxTestShards = flank.maxTestShards!!,
Expand Down
6 changes: 5 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/CreateIosArgs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ftl.args

import ftl.args.yml.Type
import ftl.config.IosConfig
import ftl.config.ios.IosFlankConfig
import ftl.config.ios.IosGcloudConfig
Expand All @@ -20,7 +21,10 @@ private fun createIosArgs(
commonArgs: CommonArgs,
obfuscate: Boolean = false
) = IosArgs(
commonArgs = commonArgs.copy(maxTestShards = convertToShardCount(commonArgs.maxTestShards)),
commonArgs = commonArgs.copy(
maxTestShards = convertToShardCount(commonArgs.maxTestShards),
type = commonArgs.type ?: Type.XCTEST
),
xctestrunZip = gcloud.test?.normalizeFilePath().orEmpty(),
xctestrunFile = gcloud.xctestrunFile?.normalizeFilePath().orEmpty(),
xcodeVersion = gcloud.xcodeVersion,
Expand Down
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/IArgs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ftl.args

import ftl.args.yml.Type
import ftl.config.Device
import ftl.config.common.CommonFlankConfig.Companion.defaultLocalResultsDir
import ftl.run.status.OutputStyle
Expand All @@ -23,6 +24,7 @@ interface IArgs {
val resultsHistoryName: String?
val flakyTestAttempts: Int
val otherFiles: Map<String, String>
val type: Type? get() = null

// FlankYml
val maxTestShards: Int
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/IosArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ftl.ios.XctestrunMethods
import ftl.run.exception.FlankConfigurationError
import ftl.shard.Chunk
import ftl.util.FlankTestMethod
import java.lang.Exception

data class IosArgs(
val commonArgs: CommonArgs,
Expand Down Expand Up @@ -43,6 +42,7 @@ IosArgs
num-flaky-test-attempts: $flakyTestAttempts
other-files: ${ArgsToString.mapToString(otherFiles)}
additional-ipas: ${ArgsToString.listToString(additionalIpas)}
type: ${type?.ymlName}

flank:
max-test-shards: $maxTestShards
Expand Down
8 changes: 8 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/ValidateIosArgs.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ftl.args

import ftl.args.yml.Type
import ftl.ios.IosCatalog
import ftl.run.exception.FlankConfigurationError
import ftl.run.exception.IncompatibleTestDimensionError
Expand All @@ -13,6 +14,7 @@ fun IosArgs.validate() = apply {
assertTestFiles()
checkResultsDirUnique()
assertAdditionalIpas()
validType()
}

fun IosArgs.validateRefresh() = apply {
Expand Down Expand Up @@ -54,3 +56,9 @@ private fun IosArgs.assertTestFiles() {
private fun IosArgs.assertAdditionalIpas() {
if (additionalIpas.size > 100) throw FlankConfigurationError("Maximum 100 additional ipas are supported")
}

private fun IosArgs.validType() {
val validIosTypes = arrayOf(Type.GAMELOOP, Type.XCTEST)
if (commonArgs.type !in validIosTypes)
throw FlankConfigurationError("Type should be one of ${validIosTypes.joinToString(",")}")
}
19 changes: 9 additions & 10 deletions test_runner/src/main/kotlin/ftl/args/yml/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package ftl.args.yml
import ftl.run.exception.FlankGeneralError

enum class Type(val ymlName: String) {
INSTRUMENTATION("instrumentation"), ROBO("robo"), GAMELOOP("game-loop");
INSTRUMENTATION("instrumentation"),
ROBO("robo"),
XCTEST("xctest"),
GAMELOOP("game-loop");
}

fun String.toType() = Type.values().find { it.ymlName == this } ?: throwUnsuportedType()

companion object {
fun fromString(stringVal: String): Type {
val filtered = values().filter { it.ymlName == stringVal }
if (filtered.isEmpty()) {
throw FlankGeneralError("Unsupported Type given `$stringVal` only [${values().joinToString(","){it.ymlName}}] supported.")
}
return filtered.first()
}
}
private fun String.throwUnsuportedType(): Nothing {
throw FlankGeneralError("Unsupported Type given `$this` only [${Type.values().joinToString(",") { it.ymlName }}] supported.")
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ data class AndroidGcloudConfig @JsonIgnore constructor(
@set:JsonProperty("grant-permissions")
var grantPermissions: String? by data

@set:CommandLine.Option(
names = ["--type"],
description = ["The type of test to run. TYPE must be one of: instrumentation, robo, game-loop."]
)
@set:JsonProperty("type")
var type: String? by data

@set:CommandLine.Option(
names = ["--directories-to-pull"],
split = ",",
Expand Down Expand Up @@ -267,7 +260,6 @@ data class AndroidGcloudConfig @JsonIgnore constructor(
testTargets = emptyList()
roboDirectives = emptyMap()
roboScript = null
type = null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ data class CommonGcloudConfig @JsonIgnore constructor(
@set:JsonProperty("other-files")
var otherFiles: Map<String, String>? by data

@set:CommandLine.Option(
names = ["--type"],
description = ["The type of test to run. TYPE must be one of: instrumentation, robo, xctest, game-loop."]
)
@set:JsonProperty("type")
var type: String? by data

constructor() : this(mutableMapOf<String, Any?>().withDefault { null })

companion object : IYmlKeys {
Expand All @@ -154,6 +161,7 @@ data class CommonGcloudConfig @JsonIgnore constructor(
networkProfile = null
devices = listOf(defaultDevice(android))
otherFiles = emptyMap()
type = null
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test_runner/src/test/kotlin/Debug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fun main() {
val quantity = "multiple"
val type = "gameloop"
val extra = "obb"

// Bugsnag keeps the process alive so we must call exitProcess
// https://github.com/bugsnag/bugsnag-java/issues/151
withGlobalExceptionHandling {
Expand Down
3 changes: 3 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class IosArgsTest {
locale: c
orientation: default
num-flaky-test-attempts: 4
type: xctest

flank:
max-test-shards: 7
Expand Down Expand Up @@ -240,6 +241,7 @@ IosArgs
additional-ipas:
- $testIpa1
- $testIpa2
type: xctest

flank:
max-test-shards: 7
Expand Down Expand Up @@ -299,6 +301,7 @@ IosArgs
num-flaky-test-attempts: 0
other-files:
additional-ipas:
type: xctest

flank:
max-test-shards: 1
Expand Down
32 changes: 32 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/yml/TypeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ftl.args.yml

import com.google.common.truth.Truth.assertThat
import ftl.run.exception.FlankGeneralError
import org.junit.Test

internal class TypeTest {

@Test(expected = FlankGeneralError::class)
fun `Should throw exception when unknow type parse`() {
"unknown test type".toType()
}

@Test
fun `Should properly parse know type`() {
// given
val correctTypes = mapOf(
"instrumentation" to Type.INSTRUMENTATION,
"robo" to Type.ROBO,
"xctest" to Type.XCTEST,
"game-loop" to Type.GAMELOOP
)

// when
val actual = correctTypes.keys.map { it.toType() }

// then
correctTypes.values.forEachIndexed { index, type ->
assertThat(type).isEqualTo(actual[index])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -565,4 +565,12 @@ class AndroidRunCommandTest {
coVerify(exactly = 1) { any<AndroidArgs>().createAndroidTestContexts() }
}
}

@Test
fun `should properly parse type`() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parseArgs("--type=a")

assertThat(cmd.config.common.gcloud.type).isEqualTo("a")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,12 @@ class IosRunCommandTest {
assertThat(cmd.config.platform.gcloud.additionalIpas).hasSize(2)
assertThat(cmd.config.platform.gcloud.additionalIpas).isEqualTo(listOf("a.ipa", "b.ipa"))
}

@Test
fun `should properly parse type`() {
val cmd = IosRunCommand()
CommandLine(cmd).parseArgs("--type=a")

assertThat(cmd.config.common.gcloud.type).isEqualTo("a")
}
}