46 lines
1.2 KiB
Kotlin

package net.sergeych.parsec3
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import kotlinx.coroutines.runBlocking
import kotlin.test.Test
import kotlin.test.assertEquals
internal class WsServerKtTest {
data class TestSession(var buzz: String = "BuZZ"): WithAdapter()
object TestApiServer: CommandHost<TestSession>() {
val foo by command<String,String>()
}
object TestApiClient: CommandHost<WithAdapter>() {
val bar by command<String,String>()
}
@Test
fun testWsServer() {
embeddedServer(Netty, port = 8080) {
parsec3TransportServer(
TestApiServer,
) {
newSession { TestSession() }
on(api.foo) {
it + buzz + "-foo"
}
}
}.start(wait = false)
val client = Parsec3WSClient("ws://localhost:8080/api/p3", TestApiClient) {
on(api.bar) {
"bar:$it"
}
}
runBlocking {
val x = TestApiServer.foo.invoke(client.adapter(), "*great*")
assertEquals("*great*BuZZ-foo", x)
client.close()
}
}
}