Skip to content

Commit

Permalink
Print web link (#683)
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline authored Apr 1, 2020
1 parent e85b4bb commit aa6d9b8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private fun List<TestExecutionData>.reduceToPrimarySteps(): List<TestExecutionDa
}
}

private fun List<TestExecutionData>.reduceTestCases() = map(TestExecutionData::reduceTestCases)
private fun List<TestExecutionData>.reduceTestCases(): List<TestExecutionData> = map(TestExecutionData::reduceTestCases)

private fun TestExecutionData.reduceTestCases() = copy(
testCases = testCases.groupBy(TestCase::getTestCaseId).map { (_, testCases) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestMatrix>,
runGcsPath: String,
stopwatch: StopWatch,
Expand All @@ -27,6 +32,8 @@ internal fun afterRunTests(
config.resultsBucket + "/" + matrixMap.runPath
println(FtlConstants.indent + gcsBucket)
println()

matrixMap.printMatricesWebLinks(config.project)
}

private fun List<TestMatrix>.toSavedMatrixMap() = this
Expand All @@ -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)
21 changes: 20 additions & 1 deletion test_runner/src/test/kotlin/ftl/run/TestRunnerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,7 +31,10 @@ class TestRunnerTest {
private val iosArgs = mockk<IosArgs>()
private val androidArgs = mockk<AndroidArgs>()

@After
@get:Rule
val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests()

@After
fun tearDown() = unmockkAll()

@Test
Expand Down Expand Up @@ -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))
}
}

0 comments on commit aa6d9b8

Please sign in to comment.