-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor data scratch-Junit test result (#1884)
- Loading branch information
1 parent
fa6d6a2
commit 82a0817
Showing
66 changed files
with
899 additions
and
654 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test_runner/src/main/kotlin/ftl/adapter/GoogleJUnitTestFetch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ftl.adapter | ||
|
||
import ftl.adapter.google.toApiModel | ||
import ftl.api.JUnitTest | ||
import ftl.client.google.fetchMatrices | ||
import ftl.client.junit.createJUnitTestResult | ||
|
||
object GoogleJUnitTestFetch : | ||
JUnitTest.Result.GenerateFromApi, | ||
(JUnitTest.Result.ApiIdentity) -> JUnitTest.Result by { (projectId, matrixIds) -> | ||
fetchMatrices(matrixIds, projectId) | ||
.createJUnitTestResult() | ||
.toApiModel() | ||
} |
19 changes: 19 additions & 0 deletions
19
test_runner/src/main/kotlin/ftl/adapter/GoogleJUnitTestParse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ftl.adapter | ||
|
||
import ftl.adapter.google.toApiModel | ||
import ftl.api.JUnitTest | ||
import ftl.client.junit.parseJUnit | ||
import ftl.client.junit.parseLegacyJUnit | ||
import java.io.File | ||
|
||
object GoogleJUnitTestParse : | ||
JUnitTest.Result.ParseFromFiles, | ||
(File) -> JUnitTest.Result by { | ||
it.parseJUnit().toApiModel() | ||
} | ||
|
||
object GoogleLegacyJunitTestParse : | ||
JUnitTest.Result.ParseFromFiles, | ||
(File) -> JUnitTest.Result by { | ||
it.parseLegacyJUnit().toApiModel() | ||
} |
3 changes: 0 additions & 3 deletions
3
test_runner/src/main/kotlin/ftl/adapter/google/FileReferenceAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
package ftl.adapter.google | ||
|
||
import ftl.api.FileReference | ||
import ftl.reports.xml.model.JUnitTestResult | ||
|
||
internal fun String.toApiModel(fileReference: FileReference) = fileReference.copy(local = this) | ||
|
||
internal fun JUnitTestResult?.toApiModel() = JUnitTestResult(testsuites = this?.testsuites) |
45 changes: 45 additions & 0 deletions
45
test_runner/src/main/kotlin/ftl/adapter/google/JUnitTestResultAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ftl.adapter.google | ||
|
||
import ftl.api.JUnitTest | ||
import ftl.client.junit.JUnitTestCase | ||
import ftl.client.junit.JUnitTestResult | ||
import ftl.client.junit.JUnitTestSuite | ||
|
||
fun JUnitTestResult?.toApiModel(): JUnitTest.Result = JUnitTest.Result( | ||
this?.testsuites?.map { it.toApiModel() }.orEmpty().toMutableList() | ||
) | ||
|
||
private fun JUnitTestSuite.toApiModel(): JUnitTest.Suite { | ||
return JUnitTest.Suite( | ||
name = name, | ||
tests = tests, | ||
failures = failures, | ||
flakes = flakes, | ||
errors = errors, | ||
skipped = skipped, | ||
time = time, | ||
timestamp = timestamp, | ||
hostname = hostname, | ||
testLabExecutionId = testLabExecutionId, | ||
testcases = testcases?.toApiModel(), | ||
properties = properties, | ||
systemOut = systemOut, | ||
systemErr = systemErr | ||
) | ||
} | ||
|
||
private fun MutableCollection<JUnitTestCase>.toApiModel(): MutableCollection<JUnitTest.Case> { | ||
return map(JUnitTestCase::toApiModel).toMutableList() | ||
} | ||
|
||
private fun JUnitTestCase.toApiModel() = JUnitTest.Case( | ||
name = name, | ||
classname = classname, | ||
time = time, | ||
failures = failures, | ||
errors = errors, | ||
skipped = skipped, | ||
flaky = flaky | ||
).also { | ||
it.webLink = webLink | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package ftl.api | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement | ||
import ftl.adapter.GoogleJUnitTestFetch | ||
import ftl.adapter.GoogleJUnitTestParse | ||
import ftl.adapter.GoogleLegacyJunitTestParse | ||
import java.io.File | ||
|
||
val generateJUnitTestResultFromApi: JUnitTest.Result.GenerateFromApi get() = GoogleJUnitTestFetch | ||
val parseJUnitTestResultFromFile: JUnitTest.Result.ParseFromFiles get() = GoogleJUnitTestParse | ||
val parseJUnitLegacyTestResultFromFile: JUnitTest.Result.ParseFromFiles get() = GoogleLegacyJunitTestParse | ||
|
||
object JUnitTest { | ||
|
||
@JacksonXmlRootElement(localName = "testsuites") | ||
data class Result( | ||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
@JacksonXmlProperty(localName = "testsuite") | ||
var testsuites: MutableList<Suite>? = null | ||
) { | ||
data class ApiIdentity( | ||
val projectId: String, | ||
val matrixIds: List<String> | ||
) | ||
|
||
interface GenerateFromApi : (ApiIdentity) -> Result | ||
|
||
interface ParseFromFiles : (File) -> Result | ||
} | ||
|
||
data class Suite( | ||
@JacksonXmlProperty(isAttribute = true) | ||
var name: String, | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
var tests: String, // Int | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
var failures: String, // Int | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
var flakes: Int? = null, | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
var errors: String, // Int | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JacksonXmlProperty(isAttribute = true) | ||
var skipped: String?, // Int. Android only | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
var time: String, // Double | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JacksonXmlProperty(isAttribute = true) | ||
val timestamp: String?, // String. Android only | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
val hostname: String? = "localhost", // String. | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JacksonXmlProperty(isAttribute = true) | ||
val testLabExecutionId: String? = null, // String. | ||
|
||
@JacksonXmlProperty(localName = "testcase") | ||
var testcases: MutableCollection<Case>?, | ||
|
||
// not used | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
val properties: Any? = null, // <properties /> | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JacksonXmlProperty(localName = "system-out") | ||
val systemOut: Any? = null, // <system-out /> | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JacksonXmlProperty(localName = "system-err") | ||
val systemErr: Any? = null // <system-err /> | ||
) | ||
|
||
data class Case( | ||
// name, classname, and time are always present except for empty test cases <testcase/> | ||
@JacksonXmlProperty(isAttribute = true) | ||
val name: String?, | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
val classname: String?, | ||
|
||
@JacksonXmlProperty(isAttribute = true) | ||
val time: String?, | ||
|
||
// iOS contains multiple failures for a single test. | ||
// JUnit XML allows arbitrary amounts of failure/error tags | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JacksonXmlProperty(localName = "failure") | ||
val failures: List<String>? = null, | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JacksonXmlProperty(localName = "error") | ||
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 | ||
|
||
@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 | ||
} | ||
|
||
@Suppress("UnusedPrivateClass") | ||
private class FilterNotNull { | ||
override fun equals(other: Any?): Boolean { | ||
// other is null = present | ||
// other is not null = absent (default value) | ||
return other != null | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return javaClass.hashCode() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test_runner/src/main/kotlin/ftl/client/google/FileReference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...er/src/main/kotlin/ftl/gc/GcTestMatrix.kt → .../kotlin/ftl/client/google/GcTestMatrix.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...in/ftl/reports/api/CreateJUnitTestCase.kt → ...n/ftl/client/junit/CreateJUnitTestCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
test_runner/src/main/kotlin/ftl/client/junit/CreateJUnitTestResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ftl.client.junit | ||
|
||
import com.google.testing.model.TestExecution | ||
|
||
internal fun List<TestExecution>.createJUnitTestResult() = JUnitTestResult( | ||
testsuites = filterNullToolResultsStep() | ||
.createTestExecutionDataListAsync() | ||
.prepareForJUnitResult() | ||
.createJUnitTestSuites() | ||
.toMutableList() | ||
) | ||
|
||
private fun List<TestExecution>.filterNullToolResultsStep() = filter { it.toolResultsStep != null } |
5 changes: 2 additions & 3 deletions
5
...n/ftl/reports/api/CreateJUnitTestSuite.kt → .../ftl/client/junit/CreateJUnitTestSuite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.