maestro.orchestra.yaml.YamlConfig.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maestro-orchestra Show documentation
Show all versions of maestro-orchestra Show documentation
Maestro is a server-driven platform-agnostic library that allows to drive tests for both iOS and Android using the same implementation through an intuitive API.
package maestro.orchestra.yaml
import com.fasterxml.jackson.annotation.JsonAnySetter
import maestro.orchestra.ApplyConfigurationCommand
import maestro.orchestra.MaestroCommand
import maestro.orchestra.MaestroConfig
import maestro.orchestra.MaestroOnFlowComplete
import maestro.orchestra.MaestroOnFlowStart
import java.nio.file.Path
data class YamlConfig(
val name: String?,
val appId: String,
val tags: List? = emptyList(),
val env: Map = emptyMap(),
val onFlowStart: YamlOnFlowStart?,
val onFlowComplete: YamlOnFlowComplete?,
) {
private val ext = mutableMapOf()
@JsonAnySetter
fun setOtherField(key: String, other: Any?) {
ext[key] = other
}
fun toCommand(flowPath: Path): MaestroCommand {
val config = MaestroConfig(
appId = appId,
name = name,
tags = tags,
ext = ext.toMap(),
onFlowStart = onFlowStart(flowPath),
onFlowComplete = onFlowComplete(flowPath)
)
return MaestroCommand(ApplyConfigurationCommand(config))
}
private fun onFlowComplete(flowPath: Path): MaestroOnFlowComplete? {
if (onFlowComplete == null) return null
return MaestroOnFlowComplete(onFlowComplete.commands.flatMap { it.toCommands(flowPath, appId) })
}
private fun onFlowStart(flowPath: Path): MaestroOnFlowStart? {
if (onFlowStart == null) return null
return MaestroOnFlowStart(onFlowStart.commands.flatMap { it.toCommands(flowPath, appId) })
}
}