Skip to content

Commit

Permalink
Add fix for crash on --legacy-junit-result
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfilipow92 committed Aug 6, 2020
1 parent e1637b7 commit 693b179
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ object ReportManager {
// xmlFile path changes based on if local-result-dir is used. may or may not contain objName
// 2019-03-22_17-20-53.594000_ftrh/shard_0/test_result_1.xml or shard_0/test_result_1.xml
val objName = matrices.runPath // 2019-03-22_17-20-53.594000_ftrh

// shard location in path changes based on iOS or Android.
val matchResult = Regex("/.*(shard_\\d+)(-rerun_\\d+)?/").find(xmlFile.toString())
val matchResult = xmlFile.getWeblinkFromFile()
val shardName = matchResult?.value?.removePrefix("/")?.removeSuffix("/") // shard_0 || shard_0-rerun_1
val matrixPath = Paths.get(objName, shardName).toString() // 2019-03-22_17-20-53.594000_ftrh/shard_0

Expand Down Expand Up @@ -215,3 +214,5 @@ object ReportManager {
GcStorage.uploadJunitXml(newTestResult, args)
}
}
@VisibleForTesting
internal fun File.getWeblinkFromFile() = Regex("/.*(shard_|matrix_)\\d+(-rerun_\\d+)?/").find(toString())
7 changes: 4 additions & 3 deletions test_runner/src/test/kotlin/Debug.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ fun main() {
val projectId = System.getenv("GOOGLE_CLOUD_PROJECT")
?: "YOUR PROJECT ID"

val quantity = "single"
val type = "error"
val quantity = "multiple"
val type = "success"
// Bugsnag keeps the process alive so we must call exitProcess
// https://github.com/bugsnag/bugsnag-java/issues/151
withGlobalExceptionHandling {
Expand All @@ -23,7 +23,8 @@ fun main() {
// "--dry",
// "--dump-shards",
// "--output-style=single",
"--full-junit-result",
// "--full-junit-result",
// "--legacy-junit-result",
"-c=src/test/kotlin/ftl/fixtures/test_app_cases/flank-$quantity-$type.yml",
"--project=$projectId"
// "--client-details=key1=value1,key2=value2"
Expand Down
12 changes: 12 additions & 0 deletions test_runner/src/test/kotlin/ftl/reports/utils/ReportManagerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ftl.reports.FullJUnitReport
import ftl.reports.JUnitReport
import ftl.reports.MatrixResultsReport
import ftl.reports.util.ReportManager
import ftl.reports.util.getWeblinkFromFile
import ftl.reports.xml.model.JUnitTestCase
import ftl.reports.xml.model.JUnitTestResult
import ftl.reports.xml.model.JUnitTestSuite
Expand All @@ -21,11 +22,14 @@ import io.mockk.mockkObject
import io.mockk.unmockkAll
import io.mockk.verify
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Rule
import org.junit.Test
import org.junit.contrib.java.lang.system.SystemErrRule
import org.junit.contrib.java.lang.system.SystemOutRule
import org.junit.runner.RunWith
import java.io.File
import java.nio.file.Files

@RunWith(FlankTestRunner::class)
class ReportManagerTest {
Expand Down Expand Up @@ -196,4 +200,12 @@ class ReportManagerTest {
assertThat(ReportManager.getDeviceString(""))
.isEqualTo("")
}

@Test
fun `should get weblink from legacy path and ios path`() {
val legacyPath = File("results/2020-08-06_12-08-55.641213_jGpY/matrix_0/NexusLowRes-28-en-portrait/test_result_1.xml")
val iosPath = File("results/test_dir/shard_0/iphone8-12.0-en-portrait/test_result_0.xml")
assertEquals("/2020-08-06_12-08-55.641213_jGpY/matrix_0/", legacyPath.getWeblinkFromFile()?.value)
assertEquals("/test_dir/shard_0/", iosPath.getWeblinkFromFile()?.value)
}
}

0 comments on commit 693b179

Please sign in to comment.