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 Flank version info to requests #2073

Merged
merged 7 commits into from
Jul 8, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions test_runner/src/main/kotlin/ftl/client/google/run/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package ftl.client.google.run
import com.google.testing.model.ClientInfoDetail
import com.google.testing.model.FileReference
import com.google.testing.model.IosDeviceFile
import ftl.util.readRevision
import ftl.util.readVersion

internal fun List<String>.mapGcsPathsToFileReference(): List<FileReference> = map { it.toFileReference() }

fun String.toFileReference(): FileReference = FileReference().setGcsPath(this)

internal fun Map<String, String>.mapToIosDeviceFiles(): List<IosDeviceFile> = map { (testDevicePath, gcsFilePath) -> toIosDeviceFile(testDevicePath, gcsFilePath) }
internal fun Map<String, String>.mapToIosDeviceFiles(): List<IosDeviceFile> =
map { (testDevicePath, gcsFilePath) -> toIosDeviceFile(testDevicePath, gcsFilePath) }

internal fun toIosDeviceFile(testDevicePath: String, gcsFilePath: String = "") = IosDeviceFile().apply {
if (testDevicePath.contains(":")) {
Expand All @@ -21,8 +24,19 @@ internal fun toIosDeviceFile(testDevicePath: String, gcsFilePath: String = "") =
content = FileReference().setGcsPath(gcsFilePath)
}

internal fun Map<String, String>.toClientInfoDetailList() = map { (key, value) ->
internal fun Map<String, String>?.toClientInfoDetailList() =
(this ?: emptyMap()).map { (key, value) ->
ClientInfoDetail()
.setKey(key)
.setValue(value)
}.addFlankVersionInfo()

private fun List<ClientInfoDetail>.addFlankVersionInfo() = plus(
ClientInfoDetail()
.setKey(key)
.setValue(value)
}
.setKey("Flank Version")
.setValue(readVersion())
).plus(
ClientInfoDetail()
.setKey("Flank Revision")
.setValue(readRevision())
)
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private fun createAndroidTestMatrix(
private val TestMatrixAndroid.Config.clientInfo
get() = ClientInfo()
.setName("Flank")
.setClientInfoDetails(clientDetails?.toClientInfoDetailList())
.setClientInfoDetails(clientDetails.toClientInfoDetailList())

private val TestMatrixAndroid.Config.environmentMatrix
get() = EnvironmentMatrix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ private fun getIosTestSetup(
private fun List<String>.toIosDeviceFiles() = map { path -> toIosDeviceFile(path) }

private val TestMatrixIos.Config.clientInfo
get() = ClientInfo().setName("Flank").setClientInfoDetails(clientDetails?.toClientInfoDetailList())
get() = ClientInfo().setName("Flank").setClientInfoDetails(clientDetails.toClientInfoDetailList())
28 changes: 25 additions & 3 deletions test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1388,18 +1388,18 @@ AndroidArgs
matrixMap.map
.toList().apply {
// test the module which overrides and adds client details
first { it.second.clientDetails!!.size == 3 }
first { it.second.clientDetails!!.size == 5 }
.apply {
assertEquals("val1", second.clientDetails!!["key1"])
assertEquals("val2", second.clientDetails!!["key2"])
assertEquals("overwritten-top-val1", second.clientDetails!!["top-key1"])
}
// test all other modules got top level client details
first { it.second.clientDetails!!.size == 1 }
first { it.second.clientDetails!!.size == 3 }
.apply {
assertEquals("top-val1", second.clientDetails!!["top-key1"])
}
last { it.second.clientDetails!!.size == 1 }
last { it.second.clientDetails!!.size == 3 }
.apply {
assertEquals("top-val1", second.clientDetails!!["top-key1"])
}
Expand All @@ -1408,6 +1408,28 @@ AndroidArgs
assertEquals(3, chunks.size)
}

@Test
fun `should add flank version to client-details even if client-details is empty`() {
val yaml = """
gcloud:
app: $appApk
test: $testApk
flank:
additional-app-test-apks:
- test: $testErrorApk
- app: null
test: $testErrorApk
""".trimIndent()

val parsedYml = AndroidArgs.load(yaml).validate()

val (matrixMap) = runBlocking { parsedYml.runAndroidTests() }
assertTrue(
"Not all matrices have the `Flank Version` client-detail",
matrixMap.map.all { it.value.clientDetails!!.containsKey("Flank Version") && it.value.clientDetails!!.containsKey("Flank Revision") }
)
}

@Test
fun `cli keep-file-path`() {
val cli = AndroidRunCommand()
Expand Down
21 changes: 21 additions & 0 deletions test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ftl.config.defaultIosConfig
import ftl.ios.xctest.flattenShardChunks
import ftl.presentation.cli.firebase.test.ios.IosRunCommand
import ftl.run.exception.FlankConfigurationError
import ftl.run.platform.runIosTests
import ftl.run.status.OutputStyle
import ftl.test.util.FlankTestRunner
import ftl.test.util.TestHelper.absolutePath
Expand All @@ -18,6 +19,7 @@ import ftl.test.util.TestHelper.getPath
import ftl.test.util.assertThrowsWithMessage
import io.mockk.every
import io.mockk.mockkObject
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
Expand Down Expand Up @@ -1368,6 +1370,25 @@ IosArgs
""".trimIndent()
IosArgs.load(yaml).validate()
}

@Test
fun `should add flank version to client-details even if client-details is empty`() {
val yaml = """
gcloud:
test: $testPlansPath
xctestrun-file: $testPlansXctestrun
flank:
skip-test-configuration: pl
""".trimIndent()

val parsedYml = IosArgs.load(yaml).validate()

val (matrixMap) = runBlocking { parsedYml.runIosTests() }
assertTrue(
"Not all matrices have the `Flank Version` client-detail",
matrixMap.map.all { it.value.clientDetails!!.containsKey("Flank Version") && it.value.clientDetails!!.containsKey("Flank Revision") }
)
}
}

private fun IosArgs.Companion.load(yamlData: String, cli: IosRunCommand? = null): IosArgs =
Expand Down