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: firebase refresh fails when test zip file doesn't exist (#1052) #1054

Merged
merged 8 commits into from
Sep 1, 2020
Merged
Prev Previous commit
Next Next commit
Added new validations methods to ValidateAndoirdArgs
zuziaka authored and mergify-bot committed Sep 1, 2020

Unverified

The email in this signature doesn’t match the committer email.
commit 77b297a7c25e14e4fe5d9bb9d85f0d75f836b655
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt
Original file line number Diff line number Diff line change
@@ -245,7 +245,7 @@ object ArgsHelper {
}
}

fun String.normalizeFilePath(name: String): String =
fun String.normalizeFilePath(name: String = ""): String =
if (startsWith(GCS_PREFIX)) this
else try {
ArgsHelper.evaluateFilePath(this)
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/CreateIosArgs.kt
Original file line number Diff line number Diff line change
@@ -18,8 +18,8 @@ private fun createIosArgs(
commonArgs: CommonArgs
) = IosArgs(
commonArgs = commonArgs.copy(maxTestShards = convertToShardCount(commonArgs.maxTestShards)),
xctestrunZip = gcloud.test?.normalizeFilePath("from test").orEmpty(),
xctestrunFile = gcloud.xctestrunFile?.normalizeFilePath("from xctestrun-file").orEmpty(),
xctestrunZip = gcloud.test?.normalizeFilePath().orEmpty(),
xctestrunFile = gcloud.xctestrunFile?.normalizeFilePath().orEmpty(),
xcodeVersion = gcloud.xcodeVersion,
testTargets = flank.testTargets?.filterNotNull().orEmpty()
)
63 changes: 53 additions & 10 deletions test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import ftl.android.IncompatibleModelVersion
import ftl.android.SupportedDeviceConfig
import ftl.android.UnsupportedModelId
import ftl.android.UnsupportedVersionId
import ftl.args.yml.AppTestPair
import ftl.config.containsPhysicalDevices
import ftl.config.containsVirtualDevices
import ftl.run.exception.FlankConfigurationError
@@ -16,10 +17,14 @@ fun AndroidArgs.validate() {
assertDevicesSupported()
assertShards()
assertTestTypes()
assertRoboTest()
assertDirectoriesToPull()
assertMaxTestShardsByDeviceType()
assertParametersConflict()
assertAndroidTest()
}

fun AndroidArgs.validateRefresh() {

}

private fun AndroidArgs.assertAdditionalAppTestApks() {
@@ -57,13 +62,6 @@ private fun AndroidArgs.assertTestTypes() {
)
}

private fun AndroidArgs.assertRoboTest() {
// Using both roboDirectives and roboScript may hang test execution on FTL
if (roboDirectives.isNotEmpty() && roboScript != null) throw FlankConfigurationError(
"Options robo-directives and robo-script are mutually exclusive, use only one of them."
)
}

// Validation is done according to https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run#--directories-to-pull
private fun AndroidArgs.assertDirectoriesToPull() {
val correctNameRegex = "(/[a-zA-Z0-9_\\-.+]+)+/?".toRegex()
@@ -73,8 +71,8 @@ private fun AndroidArgs.assertDirectoriesToPull() {
?.also {
throw FlankConfigurationError(
"Invalid value for [directories-to-pull]: Invalid path $it.\n" +
"Path must be absolute paths under /sdcard or /data/local/tmp (for example, --directories-to-pull /sdcard/tempDir1,/data/local/tmp/tempDir2).\n" +
"Path names are restricted to the characters [a-zA-Z0-9_-./+]. "
"Path must be absolute paths under /sdcard or /data/local/tmp (for example, --directories-to-pull /sdcard/tempDir1,/data/local/tmp/tempDir2).\n" +
"Path names are restricted to the characters [a-zA-Z0-9_-./+]. "
)
}
}
@@ -105,3 +103,48 @@ private fun AndroidArgs.assertParametersConflict() {
if (useLegacyJUnitResult && fullJUnitResult)
throw FlankConfigurationError("Parameters conflict, you cannot set: `--legacy-junit-result` and `--full-junit-result` at the same time.")
}

private fun AndroidArgs.assertAndroidTest() {
if (isInstrumentationTest) assertInstrumentationTest()
if (isRoboTest) assertRoboTest()
}

private fun AndroidArgs.assertInstrumentationTest() {
assertAppPairs()
assertAppApkFilePaths()
}

private fun AndroidArgs.assertRoboTest() {
// Using both roboDirectives and roboScript may hang test execution on FTL
if (roboDirectives.isNotEmpty() && roboScript != null) throw FlankConfigurationError(
"Options robo-directives and robo-script are mutually exclusive, use only one of them."
)
ArgsHelper.assertFileExists(roboScript.toString(), "from roboScript")
ArgsHelper.assertFileExists(appApk.toString(), "from app")
}

private fun AndroidArgs.assertAppApkFilePaths() {
appApkPath().forEach { (file, comment) ->
ArgsHelper.assertFileExists(file, comment)
}
}

private fun AndroidArgs.assertAppPairs() = appPairs().any { (app, test) ->
app == null && test != null || app != null && test == null
}

private fun AndroidArgs.appPairs(): List<Pair<String?, String?>> =
listOf(appApk to testApk) + additionalAppTestApks.map { (app, test) -> app to test }

private fun AndroidArgs.appApkPath(): Map<String, String> =
mapOf(
appApk to "from app",
testApk to "from test"
).filterNotNull() + additionalAppTestApks.fold(emptyMap<String, String>()) { acc, pair ->
acc + mapOf(
pair.app to "from additional-app-test-apks.app",
pair.test to "from additional-app-test-apks.test"
).filterNotNull()
}

private fun Map<String?, String>.filterNotNull() = filter { it.key != null }.mapKeys { it.key!! }
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/ValidateIosArgs.kt
Original file line number Diff line number Diff line change
@@ -43,4 +43,4 @@ private fun IosArgs.assertDevicesSupported() = devices.forEach { device ->
private fun IosArgs.assertTestFiles() {
ArgsHelper.assertFileExists(xctestrunFile, "from test")
ArgsHelper.assertFileExists(xctestrunZip, "from xctestrun-file")
}
}