Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add test file column to result table #1970

Merged
merged 3 commits into from May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -23,7 +23,10 @@ data class OutputReport(

data class Matrix(
val app: String = "",
@JsonProperty("test-axises") val testAxises: List<Outcome> = emptyList()
@JsonProperty("test-file")
val testFile: String = "",
@JsonProperty("test-axises")
val testAxises: List<Outcome> = emptyList()
)

data class Outcome(
Expand Down
Expand Up @@ -30,6 +30,7 @@ fun TestMatrix.toApiModel(identity: ftl.api.TestMatrix.Identity? = null) = Data(
gcsRootBucket = getGcsRootBucket(),
webLinkWithoutExecutionDetails = webLinkWithoutExecutionDetails(),
appFileName = extractAppFileName() ?: fallbackAppName,
testFileName = extractTestFileName() ?: fallbackAppName,
isCompleted = MatrixState.completed(state) &&
testExecutions?.all { MatrixState.completed(it.state.orEmpty()) } ?: true,
testExecutions = testExecutions?.toApiModel().orEmpty(),
Expand Down Expand Up @@ -81,7 +82,11 @@ fun TestExecution.toApiModel() = ftl.api.TestMatrix.TestExecution(
toolResultsStep = toolResultsStep
)

private fun TestMatrix.extractAppFileName() = testSpecification?.run {
private fun TestMatrix.extractAppFileName() = extractFileName { gcsPath }

private fun TestMatrix.extractTestFileName() = extractFileName { testFile }

private fun TestMatrix.extractFileName(fileName: TestFilesPathWrapper.() -> String?) = testSpecification?.run {
listOf(
androidInstrumentationTest,
androidTestLoop,
Expand All @@ -91,15 +96,21 @@ private fun TestMatrix.extractAppFileName() = testSpecification?.run {
)
.firstOrNull { it != null }
?.toJSONObject()
?.let { prettyPrint.fromJson(it.toString(), AppPath::class.java).gcsPath }
?.let { prettyPrint.fromJson(it.toString(), TestFilesPathWrapper::class.java).fileName() }
?.substringAfterLast('/')
}

private data class AppPath(
private data class TestFilesPathWrapper(
private val appApk: FileReference?,
private val testsZip: FileReference?,
private val appIpa: FileReference?
private val appIpa: FileReference?,
private val xctestrun: FileReference?,
private val testApk: FileReference?,
private val roboScript: FileReference?
) {
val gcsPath: String?
get() = (appApk ?: testsZip ?: appIpa)?.gcsPath

val testFile: String?
get() = (testApk ?: xctestrun ?: roboScript)?.gcsPath
}
2 changes: 2 additions & 0 deletions test_runner/src/main/kotlin/ftl/api/TestMatrix.kt
Expand Up @@ -11,6 +11,7 @@ val cancelTestMatrix: TestMatrix.Cancel get() = TestMatrixCancel
val fetchTestSummary: TestMatrix.Summary.Fetch get() = TestMatrixFetch

private const val fallbackAppName = "N/A"
private const val fallbackTestFileName = "---"

object TestMatrix {

Expand All @@ -33,6 +34,7 @@ object TestMatrix {
val webLinkWithoutExecutionDetails: String? = "",
val axes: List<Outcome> = emptyList(),
val appFileName: String = fallbackAppName,
val testFileName: String = fallbackTestFileName,
val isCompleted: Boolean = false,
val testExecutions: List<TestExecution> = emptyList(),
val testTimeout: Long = 0,
Expand Down
Expand Up @@ -43,6 +43,7 @@ private fun TestMatrix.Data.updateProperties(newMatrix: TestMatrix.Data) = copy(
gcsRootBucket = newMatrix.gcsRootBucket,
webLinkWithoutExecutionDetails = newMatrix.webLinkWithoutExecutionDetails,
appFileName = newMatrix.appFileName,
testFileName = newMatrix.testFileName,
isCompleted = MatrixState.completed(state) &&
newMatrix.testExecutions.all { MatrixState.completed(it.state) },
testExecutions = newMatrix.testExecutions
Expand Down
5 changes: 5 additions & 0 deletions test_runner/src/main/kotlin/ftl/json/SavedMatrixTableUtil.kt
Expand Up @@ -24,6 +24,10 @@ fun List<TestMatrix.Data>.asPrintableTable(): String = buildTable(
header = APP_NAME_COLUMN_HEADER,
data = flatMapTestAxis { matrix -> matrix.appFileName }
),
TableColumn(
header = TEST_APP_NAME_COLUMN_HEADER,
data = flatMapTestAxis { matrix -> matrix.testFileName }
),
TableColumn(
header = TEST_AXIS_VALUE_HEADER,
data = flatMapTestAxis { device }
Expand All @@ -48,5 +52,6 @@ private val TestMatrix.Outcome.outcomeColor
private const val OUTCOME_COLUMN_HEADER = "OUTCOME"
private const val MATRIX_ID_COLUMN_HEADER = "MATRIX ID"
private const val APP_NAME_COLUMN_HEADER = "APP NAME"
private const val TEST_APP_NAME_COLUMN_HEADER = "TEST FILE NAME"
private const val TEST_AXIS_VALUE_HEADER = "TEST AXIS VALUE"
private const val OUTCOME_DETAILS_COLUMN_HEADER = "TEST DETAILS"
Expand Up @@ -24,6 +24,7 @@ internal fun OutputReport.log(matrices: Collection<TestMatrix.Data>) {
matrices.map {
it.matrixId to mapOf(
"app" to it.appFileName,
"test-file" to it.testFileName,
"test-axises" to it.axes
)
}.toMap()
Expand Down
Expand Up @@ -47,12 +47,14 @@ class OutputReportLoggersTest {
matrixId = "1",
axes = listOf(TestMatrix.Outcome("device1")),
appFileName = "any.apk",
testFileName = "test-debug.apk",
historyId = historyId
)
)
val testResults = matrices.map {
it.matrixId to mapOf(
"app" to it.appFileName,
"test-file" to it.testFileName,
"test-axises" to it.axes
)
}.toMap()
Expand Down