diff --git a/release_notes.md b/release_notes.md index fc4a99d66f..334fccfb9d 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,4 +1,5 @@ ## next (unreleased) +- [#683](https://github.com/Flank/flank/pull/683) Print web link. ([pawelpasterz](https://github.com/pawelpasterz)) - [#692](https://github.com/Flank/flank/pull/692) Add support for network-profiles list command & --network-profile option. ([jan-gogo](https://github.com/jan-gogo)) - [#689](https://github.com/Flank/flank/pull/689) Add support for client-details option. ([jan-gogo](https://github.com/jan-gogo)) - [#687](https://github.com/Flank/flank/pull/687) Debug message printed after every command. ([pawelpasterz](https://github.com/pawelpasterz)) diff --git a/test_runner/src/main/kotlin/ftl/reports/api/PrepareForJUnitResult.kt b/test_runner/src/main/kotlin/ftl/reports/api/PrepareForJUnitResult.kt index 5e8f75ca7f..6bc43a11f7 100644 --- a/test_runner/src/main/kotlin/ftl/reports/api/PrepareForJUnitResult.kt +++ b/test_runner/src/main/kotlin/ftl/reports/api/PrepareForJUnitResult.kt @@ -21,7 +21,7 @@ private fun List.reduceToPrimarySteps(): List.reduceTestCases() = map(TestExecutionData::reduceTestCases) +private fun List.reduceTestCases(): List = map(TestExecutionData::reduceTestCases) private fun TestExecutionData.reduceTestCases() = copy( testCases = testCases.groupBy(TestCase::getTestCaseId).map { (_, testCases) -> diff --git a/test_runner/src/main/kotlin/ftl/run/platform/common/AfterRunTests.kt b/test_runner/src/main/kotlin/ftl/run/platform/common/AfterRunTests.kt index 3c7a682843..6db5063e27 100644 --- a/test_runner/src/main/kotlin/ftl/run/platform/common/AfterRunTests.kt +++ b/test_runner/src/main/kotlin/ftl/run/platform/common/AfterRunTests.kt @@ -3,14 +3,19 @@ package ftl.run.platform.common import com.google.api.services.testing.model.TestMatrix import ftl.args.IArgs import ftl.config.FtlConstants +import ftl.gc.GcTestMatrix import ftl.json.MatrixMap import ftl.json.SavedMatrix import ftl.run.common.updateMatrixFile import ftl.util.StopWatch +import ftl.util.webLink +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.joinAll +import kotlinx.coroutines.launch import java.nio.file.Files import java.nio.file.Paths -internal fun afterRunTests( +internal suspend fun afterRunTests( testMatrices: List, runGcsPath: String, stopwatch: StopWatch, @@ -27,6 +32,8 @@ internal fun afterRunTests( config.resultsBucket + "/" + matrixMap.runPath println(FtlConstants.indent + gcsBucket) println() + + matrixMap.printMatricesWebLinks(config.project) } private fun List.toSavedMatrixMap() = this @@ -41,3 +48,16 @@ private fun saveConfigFile(matrixMap: MatrixMap, args: IArgs) { configFilePath.parent.toFile().mkdirs() Files.write(configFilePath, args.data.toByteArray()) } + +private suspend inline fun MatrixMap.printMatricesWebLinks(project: String) = coroutineScope { + println("Matrices webLink") + map.values.map { launch { it.printWebLink(project) } }.joinAll() + println() +} + +private suspend inline fun SavedMatrix.printWebLink(project: String) = + println("${FtlConstants.indent}$matrixId: ${getOrUpdateWebLink(webLink, project, matrixId)}") + +private tailrec suspend fun getOrUpdateWebLink(link: String, project: String, matrixId: String): String = + if (link.isNotBlank()) link + else getOrUpdateWebLink(GcTestMatrix.refresh(matrixId, project).webLink(), project, matrixId) diff --git a/test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt b/test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt index 57d3ac50a0..27b80a98ec 100644 --- a/test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt +++ b/test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt @@ -13,8 +13,11 @@ import io.mockk.unmockkAll import java.nio.file.Paths import kotlinx.coroutines.runBlocking import org.junit.After +import org.junit.Assert.assertTrue import org.junit.Assume.assumeFalse +import org.junit.Rule import org.junit.Test +import org.junit.contrib.java.lang.system.SystemOutRule import org.junit.runner.RunWith @RunWith(FlankTestRunner::class) @@ -28,7 +31,10 @@ class TestRunnerTest { private val iosArgs = mockk() private val androidArgs = mockk() - @After + @get:Rule + val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests() + + @After fun tearDown() = unmockkAll() @Test @@ -144,4 +150,17 @@ class TestRunnerTest { newTestRun(config) } } + + @Test + fun `matrix webLink should be printed before polling matrices`() { + val localConfig = AndroidArgs.load(Paths.get("src/test/kotlin/ftl/fixtures/flank.local.yml")) + runBlocking { + newTestRun(localConfig) + } + val matrixWebLinkHeader = "Matrices webLink" + val matrixLink = Regex("(matrix-\\d+: https://console\\.firebase\\.google\\.com/project/.*/testlab/histories/.*/matrices/.*)(/executions/.*)?") + val output = systemOutRule.log + assertTrue(output.contains(matrixWebLinkHeader)) + assertTrue(output.contains(matrixLink)) + } }