Skip to content

Commit

Permalink
small code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfilipow92 committed Aug 6, 2020
1 parent 693b179 commit e7197a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
11 changes: 11 additions & 0 deletions test_runner/src/main/kotlin/ftl/reports/util/MatrixPath.kt
Original file line number Diff line number Diff line change
@@ -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()
22 changes: 6 additions & 16 deletions test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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("([^-]+-[^-]+-[^-]+-[^-]+).*")
Expand Down Expand Up @@ -214,5 +206,3 @@ object ReportManager {
GcStorage.uploadJunitXml(newTestResult, args)
}
}
@VisibleForTesting
internal fun File.getWeblinkFromFile() = Regex("/.*(shard_|matrix_)\\d+(-rerun_\\d+)?/").find(toString())
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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))
}
}

0 comments on commit e7197a0

Please sign in to comment.