Repository: runningcode/fladle
Pull request #130 (2020-05-21 20:26:35)

Fix instrumentation apk not being set.


Patch:
diff --git a/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt b/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt
index 304729d..0ff7edb 100644
--- a/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt
+++ b/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt
@@ -18,13 +18,17 @@ internal class YamlWriter {
     val deviceString = createDeviceString(config.devices)
     val additionalProperties = writeAdditionalProperties(config)
     val flankProperties = writeFlankProperties(config)
-    return """gcloud:
-      |  app: ${base.debugApk.get()}
-      |  test: ${base.instrumentationApk.get()}
-      |$deviceString
-      |$additionalProperties
-      |$flankProperties
-    """.trimMargin()
+
+    return buildString {
+      appendln("gcloud:")
+      appendln("  app: ${base.debugApk.get()}")
+      if (base.instrumentationApk.isPresent) {
+        appendln("  test: ${base.instrumentationApk.get()}")
+      }
+      appendln(deviceString)
+      appendln(additionalProperties)
+      append(flankProperties)
+    }
   }
 
   internal fun writeFlankProperties(config: FladleConfig): String = buildString {


Test patch:
diff --git a/buildSrc/src/test/java/com/osacky/flank/gradle/YamlWriterTest.kt b/buildSrc/src/test/java/com/osacky/flank/gradle/YamlWriterTest.kt
index 41deec0..82807a2 100644
--- a/buildSrc/src/test/java/com/osacky/flank/gradle/YamlWriterTest.kt
+++ b/buildSrc/src/test/java/com/osacky/flank/gradle/YamlWriterTest.kt
@@ -140,26 +140,28 @@ class YamlWriterTest {
       instrumentationApk.set("instrument")
     }
     val yaml = yamlWriter.createConfigProps(extension, extension)
-    assertEquals("gcloud:\n" +
-            "  app: path\n" +
-            "  test: instrument\n" +
-            "  device:\n" +
-            "  - model: NexusLowRes\n" +
-            "    version: 28\n" +
-            "\n" +
-            "  use-orchestrator: false\n" +
-            "  auto-google-login: false\n" +
-            "  record-video: true\n" +
-            "  performance-metrics: true\n" +
-            "  timeout: 15m\n" +
-            "  num-flaky-test-attempts: 0\n" +
-            "\n" +
-            "flank:\n" +
-            "  project: set\n" +
-            "  keep-file-path: false\n" +
-            "  ignore-failed-tests: false\n" +
-            "  disable-sharding: false\n" +
-            "  smart-flank-disable-upload: false\n", yaml
+    assertThat(yaml).isEqualTo("""
+             gcloud:
+               app: path
+               test: instrument
+               device:
+               - model: NexusLowRes
+                 version: 28
+             
+               use-orchestrator: false
+               auto-google-login: false
+               record-video: true
+               performance-metrics: true
+               timeout: 15m
+               num-flaky-test-attempts: 0
+             
+             flank:
+               project: set
+               keep-file-path: false
+               ignore-failed-tests: false
+               disable-sharding: false
+               smart-flank-disable-upload: false
+             """.trimIndent() + '\n' // Dunno why this needs to be here to make the tests pass.
     )
   }
 
@@ -214,6 +216,37 @@ class YamlWriterTest {
     }
   }
 
+  @Test
+  fun verifyOnlyWithRoboscriptWorks() {
+    val extension = emptyExtension {
+      serviceAccountCredentials.set(project.layout.projectDirectory.file("fake.json"))
+      debugApk.set("path")
+      roboScript = "foo"
+    }
+    val configProps = yamlWriter.createConfigProps(extension, extension)
+    assertThat(configProps).isEqualTo("""
+    gcloud:
+      app: path
+      device:
+      - model: NexusLowRes
+        version: 28
+    
+      use-orchestrator: false
+      auto-google-login: false
+      record-video: true
+      performance-metrics: true
+      timeout: 15m
+      num-flaky-test-attempts: 0
+      robo-script: foo
+    
+    flank:
+      keep-file-path: false
+      ignore-failed-tests: false
+      disable-sharding: false
+      smart-flank-disable-upload: false
+    """.trimIndent() + '\n')
+  }
+
   @Test
   fun writeNoTestShards() {
     val extension = emptyExtension {