Skip to content

Commit

Permalink
Added validation of smart-flank-gcs-paht to not override full junit b…
Browse files Browse the repository at this point in the history
…y junit and back
  • Loading branch information
adamfilipow92 authored and mergify-bot committed Aug 26, 2020
1 parent b8b3d4a commit 2773219
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package ftl.args

import ftl.config.Device
import ftl.config.FtlConstants
import ftl.reports.FullJUnitReport
import ftl.reports.JUnitReport
import ftl.run.exception.FlankConfigurationError
import ftl.run.exception.FlankGeneralError

Expand All @@ -26,8 +28,8 @@ private fun List<Device>.throwIfAnyMisspelt() =
private fun CommonArgs.assertProjectId() {
if (project.isEmpty()) throw FlankConfigurationError(
"The project is not set. Define GOOGLE_CLOUD_PROJECT, set project in flank.yml\n" +
"or save service account credential to ${FtlConstants.defaultCredentialPath}\n" +
" See https://github.com/GoogleCloudPlatform/google-cloud-java#specifying-a-project-id"
"or save service account credential to ${FtlConstants.defaultCredentialPath}\n" +
" See https://github.com/GoogleCloudPlatform/google-cloud-java#specifying-a-project-id"
)
}

Expand All @@ -54,5 +56,13 @@ private fun CommonArgs.assertSmartFlankGcsPath() = with(smartFlankGcsPath) {
count { it == '/' } <= 2 || endsWith(".xml").not() -> throw FlankConfigurationError(
"smart-flank-gcs-path must be in the format gs://bucket/foo.xml"
)

contains("/${FullJUnitReport.fileName()}") && fullJUnitResult.not() -> throw FlankConfigurationError(
"smart-flank-gcs-path is set with ${FullJUnitReport.fileName()} but in this run --full-junit-result is disabled, please set --full-junit-result flag"
)

contains("/${JUnitReport.fileName()}") && fullJUnitResult -> throw FlankConfigurationError(
"smart-flank-gcs-path is set with ${JUnitReport.fileName()} but in this run --full-junit-result enabled, please turn off --full-junit-result flag"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.google.common.truth.Truth.assertThat
import ftl.args.yml.AppTestPair
import ftl.config.Device
import ftl.config.FtlConstants
import ftl.run.exception.FlankConfigurationError
import ftl.test.util.FlankTestRunner
import org.junit.Assert.assertEquals
import org.junit.Rule
Expand Down Expand Up @@ -483,4 +484,32 @@ class AndroidRunCommandTest {

assertThat(cmd.config.common.flank.useAverageTestTimeForNewTests).isTrue()
}

@Test(expected = FlankConfigurationError::class)
fun `should throw if --full-junit-result and JUnitResult xml used`() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parseArgs("--full-junit-result", "--smart-flank-gcs-path=gs://test-lab-v9cn46bb990nx-kz69ymd4nm9aq/2020-08-26_15-20-23.850738_rtGt/JUnitReport.xml")
cmd.run()
}

@Test(expected = FlankConfigurationError::class)
fun `should throw if FullJUnitResult xml used and --full-junit-result not set`() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parseArgs("--smart-flank-gcs-path=gs://test-lab-v9cn46bb990nx-kz69ymd4nm9aq/2020-08-26_15-20-23.850738_rtGt/FullJUnitReport.xml")
cmd.run()
}

@Test
fun `should not throw if --full-junit-result and smart flank path different than JUnitReport xml`() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parseArgs("--full-junit-result", "--smart-flank-gcs-path=gs://test-lab-v9cn46bb990nx-kz69ymd4nm9aq/2020-08-26_15-20-23.850738_rtGt/JUnitReportTest.xml")
cmd.run()
}

@Test
fun `should not throw if --full-junit-result not set and smart flank path different than JUnitReport xml`() {
val cmd = AndroidRunCommand()
CommandLine(cmd).parseArgs("--smart-flank-gcs-path=gs://test-lab-v9cn46bb990nx-kz69ymd4nm9aq/2020-08-26_15-20-23.850738_rtGt/JUnitReportTest.xml")
cmd.run()
}
}

0 comments on commit 2773219

Please sign in to comment.