Skip to content

Commit

Permalink
fix IT and providing links to xml reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Adamczyk committed Apr 30, 2021
1 parent 44c98d4 commit 80c7ccc
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ private fun JUnitTestCase.toApiModel() = JUnitTest.Case(
time = time,
failures = failures,
errors = errors,
skipped = skipped
)
skipped = skipped,
flaky = flaky
).also {
it.webLink = webLink
}
8 changes: 4 additions & 4 deletions test_runner/src/main/kotlin/ftl/api/JUnitTestResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ object JUnitTest {
val errors: List<String>? = null,

@JsonInclude(JsonInclude.Include.CUSTOM, valueFilter = FilterNotNull::class)
val skipped: String? = "absent" // used by FilterNotNull to filter out absent `skipped` values
val skipped: String? = "absent", // used by FilterNotNull to filter out absent `skipped` values

@JacksonXmlProperty(isAttribute = true)
val flaky: Boolean? = null // use null instead of false
) {

// Consider to move all properties to constructor if will doesn't conflict with parser
@JsonInclude(JsonInclude.Include.NON_NULL)
var webLink: String? = null

@JacksonXmlProperty(isAttribute = true)
var flaky: Boolean? = null // use null instead of false
}

@Suppress("UnusedPrivateClass")
Expand Down
98 changes: 49 additions & 49 deletions test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,46 +42,6 @@ import kotlin.math.roundToInt

object ReportManager {

private fun Pair<IArgs, MatrixMap>.toApiIdentity(): JUnitTest.Result.ApiIdentity {
val (args, matrices) = this
return JUnitTest.Result.ApiIdentity(
projectId = args.project,
matrixIds = matrices.map.values.map { it.matrixId }
)
}

@VisibleForTesting
internal fun processXmlFromFile(
matrices: MatrixMap,
args: IArgs,
parsingFunction: (File) -> JUnitTest.Result
): JUnitTest.Result? = findXmlFiles(matrices, args)
.map { xmlFile -> parsingFunction(xmlFile).updateWebLink(getWebLink(matrices, xmlFile)) }
.reduceOrNull { acc, result -> result.merge(acc) }

private fun getWebLink(matrices: MatrixMap, xmlFile: File): String =
xmlFile.getMatrixPath(matrices.runPath)
?.findMatrixPath(matrices)
?: "".also { logLn("WARNING: Matrix path not found in JSON.") }

private fun findXmlFiles(
matrices: MatrixMap,
args: IArgs
) = File(resolveLocalRunPath(matrices, args))
.walk()
.filter { it.name.matches(Artifacts.testResultRgx) }
.fold(listOf<File>()) { xmlFiles, file -> xmlFiles + file }

private fun JUnitTest.Result.updateWebLink(
webLink: String
) = apply {
testsuites?.forEach { testSuite ->
testSuite.testcases?.forEach { testCase ->
testCase.webLink = webLink
}
}
}

/** Returns true if there were no test failures */
fun generate(
matrices: MatrixMap,
Expand Down Expand Up @@ -120,6 +80,55 @@ object ReportManager {
uploadMatricesId(args, matrices)
}

private fun Pair<IArgs, MatrixMap>.toApiIdentity(): JUnitTest.Result.ApiIdentity {
val (args, matrices) = this
return JUnitTest.Result.ApiIdentity(
projectId = args.project,
matrixIds = matrices.map.values.map { it.matrixId }
)
}

@VisibleForTesting
internal fun processXmlFromFile(
matrices: MatrixMap,
args: IArgs,
parsingFunction: (File) -> JUnitTest.Result
): JUnitTest.Result? = findXmlFiles(matrices, args)
.map { xmlFile -> parsingFunction(xmlFile).updateWebLink(getWebLink(matrices, xmlFile)) }
.reduceOrNull { acc, result -> result.merge(acc) }

private fun findXmlFiles(
matrices: MatrixMap,
args: IArgs
) = File(resolveLocalRunPath(matrices, args))
.walk()
.filter { it.name.matches(Artifacts.testResultRgx) }
.fold(listOf<File>()) { xmlFiles, file -> xmlFiles + file }

private fun getWebLink(matrices: MatrixMap, xmlFile: File): String =
xmlFile.getMatrixPath(matrices.runPath)
?.findMatrixPath(matrices)
?: "".also { logLn("WARNING: Matrix path not found in JSON.") }

private fun String.findMatrixPath(matrices: MatrixMap) = matrices.map.values
.firstOrNull { savedMatrix -> savedMatrix.gcsPath.endsWithTextWithOptionalSlashAtTheEnd(this) }
?.webLink
?: "".also { logLn("WARNING: Matrix path not found in JSON. $this") }

@VisibleForTesting
internal fun String.endsWithTextWithOptionalSlashAtTheEnd(text: String) =
"($text)/*$".toRegex().containsMatchIn(this)

private fun JUnitTest.Result.updateWebLink(
webLink: String
) = apply {
testsuites?.forEach { testSuite ->
testSuite.testcases?.forEach { testCase ->
testCase.webLink = webLink
}
}
}

private fun parseTestSuite(matrices: MatrixMap, args: IArgs): JUnitTest.Result? = when {
// ios supports only legacy parsing
args is IosArgs -> processXmlFromFile(matrices, args, parseJUnitTestResultFromFile)
Expand Down Expand Up @@ -273,13 +282,4 @@ object ReportManager {
RemoteStorage.Data(file, Files.readAllBytes(Paths.get(file)))
)
}

private fun String.findMatrixPath(matrices: MatrixMap) = matrices.map.values
.firstOrNull { savedMatrix -> savedMatrix.gcsPath.endsWithTextWithOptionalSlashAtTheEnd(this) }
?.webLink
?: "".also { logLn("WARNING: Matrix path not found in JSON. $this") }

@VisibleForTesting
internal fun String.endsWithTextWithOptionalSlashAtTheEnd(text: String) =
"($text)/*$".toRegex().containsMatchIn(this)
}
13 changes: 8 additions & 5 deletions test_runner/src/test/kotlin/ftl/reports/utils/JUnitDedupeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ class JUnitDedupeTest {
<testsuite name="" tests="3" failures="1" errors="0" skipped="0" time="1.100" timestamp="2019-03-14T19:21:26" hostname="localhost">
<testcase name="testFails" classname="com.example.app.ExampleUiTest" time="0.6">
<failure>junit.framework.AssertionFailedError</failure>
<webLink>matrices/7494574344413871385</webLink>
</testcase>
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.3">
<webLink>matrices/7494574344413871385</webLink>
</testcase>
<testcase name="testFlaky" classname="com.example.app.ExampleUiTest" time="0.2">
<webLink>matrices/7494574344413871385</webLink>
</testcase>
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.3"/>
<testcase name="testFlaky" classname="com.example.app.ExampleUiTest" time="0.2"/>
</testsuite>
</testsuites>
Expand All @@ -65,8 +70,6 @@ class JUnitDedupeTest {
).toApiModel()
JUnitDedupe.modify(suites)

val x = suites.toXmlString().normalizeLineEnding()
val y = expectedXml
assertThat(x).isEqualTo(y)
assertThat(suites.toXmlString().normalizeLineEnding()).isEqualTo(expectedXml)
}
}

0 comments on commit 80c7ccc

Please sign in to comment.