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: Validate orientation and fail fast #991

Merged
merged 8 commits into from
Aug 14, 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
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## next (unreleased)
- [#991](https://github.com/Flank/flank/pull/991) Fail fast on orientation mispell ([sloox](https://github.com/Sloox))
- [#992](https://github.com/Flank/flank/pull/992) Update google api. ([jan-gogo](https://github.com/jan-gogo))
- [#987](https://github.com/Flank/flank/pull/987) Flank Error Monitoring readme addition ([sloox](https://github.com/Sloox))
- [#990](https://github.com/Flank/flank/pull/990) Fix: exclusion of @Suppress test. ([piotradamczyk5](https://github.com/piotradamczyk5))
Expand Down
13 changes: 13 additions & 0 deletions test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package ftl.args

import ftl.config.Device
import ftl.config.FtlConstants
import ftl.util.FlankConfigurationError
import ftl.util.FlankGeneralError

fun CommonArgs.validate() {
assertProjectId()
assertShardTime()
assertRepeatTests()
assertSmartFlankGcsPath()
assertOrientationCorrectness()
}

private fun List<Device>.devicesWithMispeltOrientations(availableOrientations: List<String>) =
filter { it.orientation !in availableOrientations }

private fun CommonArgs.assertOrientationCorrectness() =
devices.devicesWithMispeltOrientations(listOf("portrait", "landscape", "default")).throwIfAnyMisspelt()

private fun List<Device>.throwIfAnyMisspelt() =
if (isNotEmpty()) throw FlankGeneralError("Orientation misspelled or incorrect, found\n${joinToString(separator = "\n")} \nAborting.")
else Unit

private fun CommonArgs.assertProjectId() {
if (project.isEmpty()) throw FlankConfigurationError(
"The project is not set. Define GOOGLE_CLOUD_PROJECT, set project in flank.yml\n" +
Expand Down
42 changes: 42 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,48 @@ AndroidArgs
""".trimIndent()
AndroidArgs.load(yaml)
}

@Test
fun `proceed on correct orientation`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
device:
- model: Nexus6
version: 25
locale: en
orientation: portrait
- model: Nexus6
version: 25
locale: en
orientation: default
- model: Nexus6
version: 25
locale: en
orientation: landscape
flank:
max-test-shards: -1
""".trimIndent()
AndroidArgs.load(yaml)
}

@Test(expected = FlankGeneralError::class)
fun `fail fast on orientation misspell`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
device:
- model: blueline
version: 28
locale: en
orientation: poortrait
flank:
max-test-shards: -1
""".trimIndent()
AndroidArgs.load(yaml)
}
}

private fun AndroidArgs.Companion.load(yamlData: String, cli: AndroidRunCommand? = null): AndroidArgs =
Expand Down
10 changes: 5 additions & 5 deletions test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class IosArgsTest {
- model: iphone8
version: 11.2
locale: c
orientation: d
orientation: default
- model: iphone8
version: 11.2
locale: c
orientation: d
orientation: default
num-flaky-test-attempts: 4

flank:
Expand Down Expand Up @@ -159,7 +159,7 @@ flank:
// IosGcloudYml
assert(xctestrunZip, testAbsolutePath)
assert(xctestrunFile, xctestrunFileAbsolutePath)
val device = Device("iphone8", "11.2", "c", "d")
val device = Device("iphone8", "11.2", "c", "default")
assert(xcodeVersion ?: "", "9.2")
assert(devices, listOf(device, device))

Expand Down Expand Up @@ -206,11 +206,11 @@ IosArgs
- model: iphone8
version: 11.2
locale: c
orientation: d
orientation: default
- model: iphone8
version: 11.2
locale: c
orientation: d
orientation: default
num-flaky-test-attempts: 4

flank:
Expand Down