From e7197a0205f447a2e89ec59cdf8bf91b36483ae6 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 6 Aug 2020 17:49:47 +0200 Subject: [PATCH] small code changes --- .../kotlin/ftl/reports/util/MatrixPath.kt | 11 ++++++++++ .../kotlin/ftl/reports/util/ReportManager.kt | 22 +++++-------------- .../ftl/reports/utils/ReportManagerTest.kt | 8 +++---- 3 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 test_runner/src/main/kotlin/ftl/reports/util/MatrixPath.kt diff --git a/test_runner/src/main/kotlin/ftl/reports/util/MatrixPath.kt b/test_runner/src/main/kotlin/ftl/reports/util/MatrixPath.kt new file mode 100644 index 0000000000..fb1898f69c --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/reports/util/MatrixPath.kt @@ -0,0 +1,11 @@ +package ftl.reports.util + +import java.io.File +import java.nio.file.Paths + +fun File.getMatrixPath(objectName: String) = getShardName()?.asObjectPath(objectName) + +private fun File.getShardName() = shardNameRegex.find(toString())?.value?.removePrefix("/")?.removeSuffix("/") +private val shardNameRegex = "/.*(shard_|matrix_)\\d+(-rerun_\\d+)?/".toRegex() + +private fun String.asObjectPath(objectName: String) = Paths.get(objectName, this).toString() diff --git a/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt b/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt index e02ed7330b..0c8489feb4 100644 --- a/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt +++ b/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt @@ -22,7 +22,6 @@ import ftl.shard.createTestMethodDurationMap import ftl.util.Artifacts import ftl.util.resolveLocalRunPath import java.io.File -import java.nio.file.Paths import kotlin.math.roundToInt object ReportManager { @@ -43,20 +42,13 @@ object ReportManager { private fun getWebLink(matrices: MatrixMap, xmlFile: File): String { // 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 = 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 - - var webLink = "" - val savedMatrix = matrices.map.values.firstOrNull { it.gcsPath.endsWith(matrixPath) } - if (savedMatrix != null) { - webLink = savedMatrix.webLink - } else { - println("WARNING: Matrix path not found in JSON. $matrixPath") + val matrixPath = xmlFile.getMatrixPath(matrices.runPath) + return matrixPath?.let { path -> + matrices.map.values.firstOrNull { it.gcsPath.endsWith(path) } + }.let { savedMatrix -> + if (savedMatrix == null) println("WARNING: Matrix path not found in JSON. $matrixPath") + savedMatrix?.webLink.orEmpty() } - return webLink } private val deviceStringRgx = Regex("([^-]+-[^-]+-[^-]+-[^-]+).*") @@ -214,5 +206,3 @@ object ReportManager { GcStorage.uploadJunitXml(newTestResult, args) } } -@VisibleForTesting -internal fun File.getWeblinkFromFile() = Regex("/.*(shard_|matrix_)\\d+(-rerun_\\d+)?/").find(toString()) diff --git a/test_runner/src/test/kotlin/ftl/reports/utils/ReportManagerTest.kt b/test_runner/src/test/kotlin/ftl/reports/utils/ReportManagerTest.kt index afdf7fb40c..97d6983a9e 100644 --- a/test_runner/src/test/kotlin/ftl/reports/utils/ReportManagerTest.kt +++ b/test_runner/src/test/kotlin/ftl/reports/utils/ReportManagerTest.kt @@ -8,7 +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.util.getMatrixPath import ftl.reports.xml.model.JUnitTestCase import ftl.reports.xml.model.JUnitTestResult import ftl.reports.xml.model.JUnitTestSuite @@ -29,7 +29,6 @@ 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 { @@ -205,7 +204,8 @@ class ReportManagerTest { 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) + val objectName = "object_name" + assertEquals("object_name/2020-08-06_12-08-55.641213_jGpY/matrix_0", legacyPath.getMatrixPath(objectName)) + assertEquals("object_name/test_dir/shard_0", iosPath.getMatrixPath(objectName)) } }