Skip to content

Commit

Permalink
CR fixes
Browse files Browse the repository at this point in the history
* Fix typo
* Fix double negation
* Remove unused `notErrors`

TODO
* map BadMatrixError error to proper error code
  • Loading branch information
jan-goral committed Aug 18, 2020
1 parent 3a62226 commit 3fedcd3
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ftl.reports.api.data.TestSuiteOverviewData
import ftl.reports.xml.model.JUnitTestSuite

internal fun List<TestExecutionData>.createJUnitTestSuites() = mapNotNull { data: TestExecutionData ->
data.createTestSuitOverviewData()?.let { overviewData ->
data.createTestSuiteOverviewData()?.let { overviewData ->
createJUnitTestSuite(
data = data,
overview = overviewData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.google.api.services.toolresults.model.TestSuiteOverview
import ftl.reports.api.data.TestExecutionData
import ftl.reports.api.data.TestSuiteOverviewData

internal fun TestExecutionData.createTestSuitOverviewData(): TestSuiteOverviewData? = step
internal fun TestExecutionData.createTestSuiteOverviewData(): TestSuiteOverviewData? = step
.testExecutionStep
.testSuiteOverviews
?.firstOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import com.google.api.services.toolresults.model.Environment

fun TestOutcomeContext.createMatrixOutcomeSummary(): Pair<BillableMinutes, TestOutcome> =
steps.calculateAndroidBillableMinutes(projectId, testTimeout) to
if (environments.isNotEmpty() && environments.hasNoOutcome().not())
if (environments.hasOutcome())
environments.createMatrixOutcomeSummaryUsingEnvironments(matrixId)
else {
if (steps.isEmpty()) println("No test results found, something went wrong. Try re-running the tests.")
steps.createMatrixOutcomeSummaryUsingSteps(matrixId)
}

private fun List<Environment>.hasNoOutcome() = any { env ->
private fun List<Environment>.hasOutcome() = isNotEmpty() && any { env ->
env.environmentResult?.outcome?.summary == null
}
}.not()
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.google.api.services.toolresults.model.Step
import ftl.reports.api.data.TestSuiteOverviewData
import ftl.reports.api.millis

internal fun Environment.createTestSuitOverviewData(): TestSuiteOverviewData =
internal fun Environment.createTestSuiteOverviewData(): TestSuiteOverviewData =
environmentResult?.testSuiteOverviews?.fold(TestSuiteOverviewData()) { acc, overview ->
acc.copy(
total = acc.total + (overview.totalCount ?: 0),
Expand All @@ -17,7 +17,7 @@ internal fun Environment.createTestSuitOverviewData(): TestSuiteOverviewData =
)
} ?: TestSuiteOverviewData()

internal fun List<Step>.createTestSuitOverviewData(): TestSuiteOverviewData = this
internal fun List<Step>.createTestSuiteOverviewData(): TestSuiteOverviewData = this
.also { require(isNotEmpty()) }
.filter(Step::isPrimaryStep)
.groupBy(Step::deviceModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class TestOutcome(
fun List<Environment>.createMatrixOutcomeSummaryUsingEnvironments(
testMatrixId: String,
outcome: Outcome? = getOutcomeFromEnvironments(),
testDetails: String? = outcome?.getDetails(map { it.createTestSuitOverviewData() }.foldTestSuiteOverviewData())
testDetails: String? = outcome?.getDetails(map { it.createTestSuiteOverviewData() }.foldTestSuiteOverviewData())
) = TestOutcome(
outcome = outcome?.summary ?: "Unknown",
matrixId = testMatrixId,
Expand All @@ -29,7 +29,7 @@ private fun List<Environment>.getOutcomeFromEnvironments(): Outcome? = maxBy {
fun List<Step>.createMatrixOutcomeSummaryUsingSteps(
testMatrixId: String,
outcome: Outcome? = getOutcomeFromSteps(),
testDetails: String? = outcome?.getDetails(createTestSuitOverviewData())
testDetails: String? = outcome?.getDetails(createTestSuiteOverviewData())
) = TestOutcome(
outcome = outcome?.summary ?: "Unknown",
matrixId = testMatrixId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ private fun TestMatrix.getToolResultsIds(): ToolResultsExecution = ToolResultsEx
class BadMatrixError : Exception()

private fun TestMatrix.testTimeout() = timeoutToSeconds(
testExecutions.firstOrNull {
it?.testSpecification?.testTimeout != null
testExecutions
.firstOrNull { it?.testSpecification?.testTimeout != null }
?.testSpecification
?.testTimeout
?.testTimeout
?: "0s"
)
4 changes: 2 additions & 2 deletions test_runner/src/main/kotlin/ftl/reports/outcome/Util.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ftl.reports.outcome

import com.google.api.services.toolresults.model.Step
import ftl.environment.orUnknown

internal fun Step.deviceModel() = dimensionValue["Model"]
?.value
?: "unknown"
?.value.orUnknown()
2 changes: 0 additions & 2 deletions test_runner/src/main/kotlin/ftl/util/StepOutcome.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ object StepOutcome {
const val success = "success"
const val unset = "unset"

val notErrors = listOf(failure, flaky, skipped, success)

val order = linkedSetOf(
failure,
flaky,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CreateJUnitTestSuiteKtTest {
@Before
fun setUp() {
mockkStatic(
"ftl.reports.api.CreateTestSuitOverviewDataKt",
"ftl.reports.api.CreateTestSuiteOverviewDataKt",
"ftl.reports.api.CreateJUnitTestCaseKt"
)
}
Expand All @@ -38,7 +38,7 @@ class CreateJUnitTestSuiteKtTest {
fun createJUnitTestSuites() {
// given
every {
any<TestExecutionData>().createTestSuitOverviewData()
any<TestExecutionData>().createTestSuiteOverviewData()
} returns TestSuiteOverviewData(1, 1, 1, 1, 1, 1.1, 1.1)

val jUnitTestCase = JUnitTestCase(null, null, "1.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import ftl.reports.api.data.TestSuiteOverviewData
import org.junit.Assert.assertEquals
import org.junit.Test

class CreateTestSuitOverviewDataKtTest {
class CreateTestSuiteOverviewDataKtTest {

@Test
fun createTestSuitOverviewData() {
fun createTestSuiteOverviewData() {
// given
val testExecutionData = TestExecutionData(
testExecution = TestExecution(),
Expand Down Expand Up @@ -56,7 +56,7 @@ class CreateTestSuitOverviewDataKtTest {
elapsedTime = 8.0,
overheadTime = 1.0
)
val actual = testExecutionData.createTestSuitOverviewData()
val actual = testExecutionData.createTestSuiteOverviewData()

// then
assertEquals(expected, actual)
Expand Down

0 comments on commit 3fedcd3

Please sign in to comment.