Skip to content

Commit

Permalink
Fail fast when results-dir is incorrect (#772)
Browse files Browse the repository at this point in the history
* Fail fast when results-dir is incorrect
  • Loading branch information
jan-goral authored and adamfilipow92 committed May 8, 2020
1 parent 9a6f328 commit 2e9f925
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
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)
- [#772](https://github.com/Flank/flank/pull/772) Fail fast when results-dir is incorrect. ([jan-gogo](https://github.com/jan-gogo))
- [#757](https://github.com/Flank/flank/pull/767) Reduce memory usage by using Reader and Writer instead of ByteArrays. ([jan-gogo](https://github.com/jan-gogo))
- [#763](https://github.com/Flank/flank/pull/763) Use "localhost" as default for hostname to fix backward compatibility. ([jan-gogo](https://github.com/jan-gogo))
- [#757](https://github.com/Flank/flank/pull/757) Print version and revision before each command. ([jan-gogo](https://github.com/jan-gogo))
Expand Down
2 changes: 1 addition & 1 deletion test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AndroidArgs(
) : IArgs {
private val gcloud = gcloudYml.gcloud
override val resultsBucket: String
override val resultsDir = cli?.resultsDir ?: gcloud.resultsDir
override val resultsDir = (cli?.resultsDir ?: gcloud.resultsDir)?.also { assertFileExists(it, "from results-dir") }
override val recordVideo = cli?.recordVideo ?: cli?.noRecordVideo?.not() ?: gcloud.recordVideo
override val testTimeout = cli?.timeout ?: gcloud.timeout
override val async = cli?.async ?: gcloud.async
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal fun beforeRunTests(args: IArgs): Pair<StopWatch, String> {

// Avoid spamming the results/ dir with temporary files from running the test suite.
if (FtlConstants.useMock)
deleteMockResultDirOnShotDown(args, runGcsPath)
deleteMockResultDirOnShutDown(args, runGcsPath)

if (args.useLocalResultDir()) {
// Only one result is stored when using --local-result-dir
Expand All @@ -36,7 +36,7 @@ private fun assertMockUrl() {
if (!GcToolResults.service.rootUrl.contains(FtlConstants.localhost)) throw RuntimeException("expected localhost in GcToolResults")
}

private fun deleteMockResultDirOnShotDown(args: IArgs, runGcsPath: String) {
private fun deleteMockResultDirOnShutDown(args: IArgs, runGcsPath: String) {
Runtime.getRuntime().addShutdownHook(Thread {
File(args.localResultDir, runGcsPath).deleteRecursively()
})
Expand Down
18 changes: 14 additions & 4 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -969,20 +969,30 @@ AndroidArgs
assertThat(AndroidArgs.load(yaml, cli).testTargetsAlwaysRun).isEqualTo(arrayListOf("com.A", "com.B"))
}

@Test(expected = FlankFatalError::class)
fun `cli resultsDir fail if not exist`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
results-dir: not_exist
"""
AndroidArgs.load(yaml)
}
@Test
fun `cli resultsDir`() {
val cli = AndroidRunCommand()
CommandLine(cli).parseArgs("--results-dir=b")
CommandLine(cli).parseArgs("--results-dir=build")

val yaml = """
gcloud:
app: $appApk
test: $testApk
results-dir: a
results-dir: results
"""

assertThat(AndroidArgs.load(yaml).resultsDir).isEqualTo("a")
assertThat(AndroidArgs.load(yaml, cli).resultsDir).isEqualTo("b")
assertThat(AndroidArgs.load(yaml).resultsDir).isEqualTo("results")
assertThat(AndroidArgs.load(yaml, cli).resultsDir).isEqualTo("build")
}

@Test
Expand Down

0 comments on commit 2e9f925

Please sign in to comment.