You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4 KiB

package tv.anypoint.dsl
import tv.anypoint.dsl.handler.HttpHandler
import tv.anypoint.dsl.model.adb.ExtraKey
import tv.anypoint.dsl.model.adb.IntentAction
import tv.anypoint.dsl.model.Tc
import tv.anypoint.dsl.service.TestCase
import java.time.Duration
import java.time.LocalDateTime
import java.time.Period
import java.time.temporal.ChronoUnit
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
inline fun tc(
block: Tc.() -> Unit
) = Tc().also { block(it) }
inline fun <reified T>http(
block: HttpHandler<T>.() -> Unit
) = HttpHandler<T>().also { block(it) }
data class Adb(
val a: IntentAction,
val es: Map<ExtraKey, String>
)
inline fun adb(
a: IntentAction,
es: Map<ExtraKey, String>
) {
val adb = Adb(a, es)
val aStr = "-a $a"
val esStr: String = es.entries.joinToString(" ") { "--es ${it.key.string} ${it.value}" }
println("[ADB] adb shell am broadcast $aStr $esStr")
}
fun TestCase.expected(
expectedLog: String,
timeout: Long = 10_000L
) {
val startedAt = LocalDateTime.now()
while (true) {
val now = LocalDateTime.now()
if (ChronoUnit.MILLIS.between(startedAt, now) > timeout) {
throw TimeoutException("failed to find log. expectedLog: $expectedLog, absoluteFilePath: ${this.tc.logInfo.absoluteFilePath}")
}
// TODO: tc 로그에서 expectedLog 찾기 tc.logInfo.cursor ~ 마지막 라인까지의 로그 중에 찾으면 됨
}
}