Skip to content

Commit

Permalink
feat: Use Firebase Test Lab matrix details URL for test matrix webLink
Browse files Browse the repository at this point in the history
  • Loading branch information
tonybaroneee authored Apr 5, 2022
1 parent db2d92d commit cf7d734
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 46 deletions.
31 changes: 15 additions & 16 deletions docs/refactor/steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ ftl.domain
├── ListIosVersions.kt
├── RunIosDoctor.kt
├── RunIosTest.kt
├── DescribeIosTestEnvironment.kt
├── ListIPBlocks.kt
├── DescribeNetworkProfiles.kt
├── ListNetworkProfiles.kt
├── ListProvidedSoftware.kt
├── CancelLastRun.kt
└── RefreshLastRun.kt
├── DescribeIosTestEnvironment.kt
├── ListIPBlocks.kt
├── DescribeNetworkProfiles.kt
├── ListNetworkProfiles.kt
├── ListProvidedSoftware.kt
├── CancelLastRun.kt
└── RefreshLastRun.kt
```

## Use FileReference abstraction where possible
Expand Down Expand Up @@ -223,7 +223,7 @@ data class NetworkProfile(

```kotlin
val networkProfileDescription: suspend NetworkProfile.() -> String = TODO()
val networkProfileList: suspend List<NetworkProfile>.() -> String = TODO()
val networkProfileList: suspend List<NetworkProfile>.() -> String = TODO()
```

### Locales
Expand Down Expand Up @@ -457,7 +457,7 @@ object RemoteStorage {

class Data(
val path: String,
val bytes: ByteArray? = null // Use, when file under the given path doesn't exist.
val bytes: ByteArray? = null // Use, when file under the given path doesn't exist.
)

interface Exist : (Dir) -> Boolean
Expand Down Expand Up @@ -492,12 +492,12 @@ object RemoteStorage {

```kotlin
object TestMatrix {

data class Result(
val runPath: String,
val map: Map<String, Data>,
)

data class Data(
val matrixId: String = "",
val state: String = "",
Expand All @@ -508,7 +508,6 @@ object TestMatrix {
val clientDetails: Map<String, String>? = null,
val gcsPathWithoutRootBucket: String = "",
val gcsRootBucket: String = "",
val webLinkWithoutExecutionDetails: String? = "",
val axes: List<Outcome> = emptyList()
)

Expand Down Expand Up @@ -930,21 +929,21 @@ object PerfMetrics {
package ftl.data

object Artifacts {

data class Identity(
val gcsPathWithoutRootBucket: String,
val gcsRootBucket: String,
val regex: List<Regex>,
val blobPath: String,
val downloadPath: DownloadPath,
)

data class DownloadPath(
val localResultDir: String,
val useLocalResultDir: Boolean,
val keepFilePath: Boolean,
)
interface Fetch: (Identity) -> List<String>

interface Fetch: (Identity) -> List<String>
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import ftl.util.getGcsPathWithoutRootBucket
import ftl.util.getGcsRootBucket
import ftl.util.timeoutToSeconds
import ftl.util.webLink
import ftl.util.webLinkWithoutExecutionDetails

fun TestMatrix.toApiModel(identity: ftl.api.TestMatrix.Identity? = null) = Data(
projectId = projectId.orEmpty(),
Expand All @@ -28,7 +27,6 @@ fun TestMatrix.toApiModel(identity: ftl.api.TestMatrix.Identity? = null) = Data(
clientDetails = getClientDetails(),
gcsPathWithoutRootBucket = getGcsPathWithoutRootBucket(),
gcsRootBucket = getGcsRootBucket(),
webLinkWithoutExecutionDetails = webLinkWithoutExecutionDetails(),
appFileName = extractAppFileName() ?: fallbackAppName,
testFileName = extractTestFileName() ?: fallbackAppName,
isCompleted = MatrixState.completed(state) &&
Expand Down
1 change: 0 additions & 1 deletion test_runner/src/main/kotlin/ftl/api/TestMatrix.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ object TestMatrix {
val clientDetails: Map<String, String>? = null,
val gcsPathWithoutRootBucket: String = "",
val gcsRootBucket: String = "",
val webLinkWithoutExecutionDetails: String? = "",
val axes: List<Outcome> = emptyList(),
val appFileName: String = fallbackAppName,
val testFileName: String = fallbackTestFileName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ private fun TestMatrix.Data.updateProperties(newMatrix: TestMatrix.Data) = copy(
clientDetails = newMatrix.clientDetails,
gcsPathWithoutRootBucket = newMatrix.gcsPathWithoutRootBucket,
gcsRootBucket = newMatrix.gcsRootBucket,
webLinkWithoutExecutionDetails = newMatrix.webLinkWithoutExecutionDetails,
appFileName = newMatrix.appFileName,
testFileName = newMatrix.testFileName,
isCompleted = MatrixState.completed(state) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object MatrixResultsReport : IReport {
.takeIf { it.isNotEmpty() }
?.run {
writer.println("More details are available at:")
forEach { writer.println(it.webLinkWithoutExecutionDetails.orEmpty()) }
forEach { writer.println(it.webLink.orEmpty()) }
writer.println()
}
}
25 changes: 3 additions & 22 deletions test_runner/src/main/kotlin/ftl/util/TestMatrixExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,15 @@ fun TestMatrix.firstToolResults(): ToolResultsStep? {
}

fun TestMatrix.webLink(): String {
val numDevices = testExecutions?.size ?: 0
val firstStep: ToolResultsStep = firstToolResults() ?: return ""

val baseUrl =
"https://console.firebase.google.com/project/${this.projectId}/" +
"testlab/histories/${firstStep.historyId}/" +
"matrices/${firstStep.executionId}"
return if (numDevices == 1) {
"$baseUrl/executions/${firstStep.stepId}"
} else {
baseUrl
}
return "https://console.firebase.google.com/project/${this.projectId}/" +
"testlab/histories/${firstStep.historyId}/" +
"matrices/${firstStep.executionId}/details"
}

fun TestMatrix.getClientDetails(): Map<String, String>? =
this.clientInfo?.clientInfoDetails?.associate { it.key to it.value }

fun TestMatrix.webLinkWithoutExecutionDetails(): String {
val webLink = webLink()
return if (webLink.isBlank()) {
webLink
} else {
val executionsRegex = "/executions/.+".toRegex()
val foundValue = executionsRegex.find(webLink)?.value.orEmpty()
webLink.removeSuffix(foundValue)
}
}

fun TestMatrix.getGcsPath() = this.resultStorage?.googleCloudStorage?.gcsPath ?: ""
fun TestMatrix.getGcsPathWithoutRootBucket() = this.getGcsPath().substringAfter('/')
fun TestMatrix.getGcsRootBucket() = this.getGcsPath().substringBefore('/')
4 changes: 2 additions & 2 deletions test_runner/src/test/kotlin/ftl/api/TestMatrixTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class TestMatrixTest {
assertThat(testMatrixData.matrixId).isEqualTo(matrixId)
assertThat(testMatrixData.state).isEqualTo(matrixState)
assertThat(testMatrixData.gcsPath).isEqualTo(mockGcsPath)
assertThat(testMatrixData.webLink).isEqualTo("https://console.firebase.google.com/project/1/testlab/histories/2/matrices/-1")
assertThat(testMatrixData.webLink).isEqualTo("https://console.firebase.google.com/project/1/testlab/histories/2/matrices/-1/details")
assertThat(testMatrixData.downloaded).isFalse()
assertThat(testMatrixData.billableMinutes.virtual).isEqualTo(1)
assertThat(testMatrixData.billableMinutes.physical).isEqualTo(1)
Expand Down Expand Up @@ -134,7 +134,7 @@ class TestMatrixTest {
assertThat(testMatrix.matrixId).isEqualTo(matrixId)
assertThat(testMatrix.state).isEqualTo(matrixState)
assertThat(testMatrix.gcsPath).isEqualTo(mockGcsPath)
assertThat(testMatrix.webLink).isEqualTo("https://console.firebase.google.com/project/1/testlab/histories/2/matrices/-3/executions/-3")
assertThat(testMatrix.webLink).isEqualTo("https://console.firebase.google.com/project/1/testlab/histories/2/matrices/-3/details")
assertThat(testMatrix.downloaded).isFalse()
assertThat(testMatrix.billableMinutes.virtual).isEqualTo(1)
assertThat(testMatrix.billableMinutes.physical).isEqualTo(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RefreshCommandTest {
"matrixId": "matrix-1",
"state": "FINISHED",
"gcsPath": "1",
"webLink": "https://console.firebase.google.com/project/mock-project-id/testlab/histories/1/matrices/1/executions/1",
"webLink": "https://console.firebase.google.com/project/mock-project-id/testlab/histories/1/matrices/1/details",
"downloaded": false,
"billableVirtualMinutes": 1,
"billablePhysicalMinutes": 0,
Expand Down

0 comments on commit cf7d734

Please sign in to comment.