Skip to content

Commit

Permalink
Fix doctor YAML parsing (#311)
Browse files Browse the repository at this point in the history
* Fix doctor YAML parsing

* Fix empty Flank parsing
  • Loading branch information
bootstraponline authored Sep 12, 2018
1 parent 98176c9 commit b2e7ef6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 9 deletions.
6 changes: 5 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/yml/FlankYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ class FlankYmlParams(

@JsonIgnoreProperties(ignoreUnknown = true)
class FlankYml(
val flank: FlankYmlParams = FlankYmlParams()
// when an empty 'flank:' is present in a yaml then parsedFlank will be parsed as null.
@field:JsonProperty("flank")
private val parsedFlank: FlankYmlParams? = FlankYmlParams()
) {
val flank = parsedFlank ?: FlankYmlParams()

companion object : IYmlMap {
override val map = mapOf("flank" to FlankYmlParams.keys)
}
Expand Down
5 changes: 4 additions & 1 deletion test_runner/src/main/kotlin/ftl/args/yml/IosFlankYml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class IosFlankYmlParams(

@JsonIgnoreProperties(ignoreUnknown = true)
class IosFlankYml(
val flank: IosFlankYmlParams = IosFlankYmlParams()
// when an empty 'flank:' is present in a yaml then parsedFlank will be parsed as null.
@field:JsonProperty("flank")
private val parsedFlank: IosFlankYmlParams? = IosFlankYmlParams()
) {
val flank = parsedFlank ?: IosFlankYmlParams()
companion object : IYmlMap {
override val map = mapOf("flank" to IosFlankYmlParams.keys)
}
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/doctor/Doctor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Doctor {

validArgs.forEach { (topLevelKey, keyList) ->
val parsedKeys = mutableListOf<String>()
parsed[topLevelKey].fields().forEach { parsedKeys.add(it.key) }
parsed[topLevelKey]?.fields()?.forEach { parsedKeys.add(it.key) }
val unknownKeys = parsedKeys - keyList
if (unknownKeys.isNotEmpty()) result += "Unknown keys in $topLevelKey -> $unknownKeys\n"
}
Expand Down
29 changes: 23 additions & 6 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ftl.args

import com.google.common.truth.Truth.assertThat
import ftl.config.Device
import ftl.test.util.FlankTestRunner
import ftl.test.util.TestHelper.assert
Expand Down Expand Up @@ -56,7 +57,7 @@ class AndroidArgsTest {
expectedException.expect(RuntimeException::class.java)
expectedException.expectMessage("Unsupported model id")
AndroidArgs.load(
"""
"""
gcloud:
app: $appApk
test: $testApk
Expand All @@ -72,7 +73,7 @@ class AndroidArgsTest {
expectedException.expect(RuntimeException::class.java)
expectedException.expectMessage("Unsupported version id")
AndroidArgs.load(
"""
"""
gcloud:
app: $appApk
test: $testApk
Expand All @@ -88,7 +89,7 @@ class AndroidArgsTest {
expectedException.expect(RuntimeException::class.java)
expectedException.expectMessage("Incompatible model")
AndroidArgs.load(
"""
"""
gcloud:
app: $appApk
test: $testApk
Expand Down Expand Up @@ -133,7 +134,7 @@ class AndroidArgsTest {
fun androidArgsToString() {
val androidArgs = AndroidArgs.load(androidNonDefault)
assert(
androidArgs.toString(), """
androidArgs.toString(), """
AndroidArgs
gcloud:
resultsBucket: mockBucket
Expand Down Expand Up @@ -163,7 +164,7 @@ AndroidArgs
@Test
fun androidArgsDefault() {
val androidArgs = AndroidArgs.load(
"""
"""
gcloud:
app: $appApk
test: $testApk
Expand Down Expand Up @@ -199,7 +200,7 @@ AndroidArgs
@Test
fun negativeOneTestShards() {
val androidArgs = AndroidArgs.load(
"""
"""
gcloud:
app: $appApk
test: $testErrorApk
Expand All @@ -215,4 +216,20 @@ AndroidArgs
testShardChunks.forEach { chunk -> assert(chunk.size, 1) }
}
}

@Test
fun androidArgs_emptyFlank() {
val androidArgs = AndroidArgs.load(
"""
gcloud:
app: $appApk
test: $testApk
flank:
"""
)

assertThat(androidArgs.appApk).isEqualTo(appApk)
assertThat(androidArgs.testApk).isEqualTo(testApk)
}
}
19 changes: 19 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ftl.args

import com.google.common.truth.Truth.assertThat
import ftl.args.yml.FlankYml
import ftl.args.yml.GcloudYml
import ftl.args.yml.IosFlankYml
Expand Down Expand Up @@ -171,4 +172,22 @@ IosArgs
testShardChunks.forEach { chunk -> assert(chunk.size, 1) }
}
}

@Test
fun iosArgs_emptyFlank() {
val iosArgs = IosArgs.load(
"""
gcloud:
test: $testPath
xctestrun-file: $xctestrunFile
flank:
"""
)

with(iosArgs) {
assertThat(xctestrunZip).isEqualTo(testPath)
assertThat(xctestrunFile).isEqualTo(xctestrunFile)
}
}
}
26 changes: 26 additions & 0 deletions test_runner/src/test/kotlin/ftl/doctor/DoctorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ Unknown keys in flank -> [three]
)
}

@Test
fun androidDoctorTest3() {
val lint = Doctor.validateYaml(
AndroidArgs, """
gcloud:
app: .
test: .
project: .
""".trimIndent()
)
assertThat(lint).isEqualTo("")
}

@Test
fun iosDoctorTest() {
Doctor.checkIosCatalog()
Expand Down Expand Up @@ -115,4 +128,17 @@ Unknown keys in flank -> [three]
""".trimIndent()
)
}

@Test
fun iosDoctorTest3() {
val lint = Doctor.validateYaml(
IosArgs, """
gcloud:
project: .
test: .
xctestrun-file: .
""".trimIndent()
)
assertThat(lint).isEqualTo("")
}
}

0 comments on commit b2e7ef6

Please sign in to comment.