Initial commit
This commit is contained in:
parent
71ae106311
commit
7b32c3e3da
1 changed files with 7267 additions and 5 deletions
49
src/test/kotlin/client/WebSocketTransportTest.kt
Normal file
49
src/test/kotlin/client/WebSocketTransportTest.kt
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package client
|
||||
|
||||
import io.ktor.server.testing.*
|
||||
import io.ktor.server.websocket.*
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import org.jetbrains.kotlinx.mcp.client.mcpWebSocketTransport
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.jetbrains.kotlinx.mcp.server.mcpWebSocket
|
||||
import org.jetbrains.kotlinx.mcp.server.mcpWebSocketTransport
|
||||
|
||||
class WebSocketTransportTest : BaseTransportTest() {
|
||||
@Test
|
||||
fun `should start then close cleanly`() = testApplication {
|
||||
install(WebSockets)
|
||||
routing {
|
||||
mcpWebSocket()
|
||||
}
|
||||
|
||||
val client = createClient {
|
||||
install(io.ktor.client.plugins.websocket.WebSockets)
|
||||
}.mcpWebSocketTransport()
|
||||
|
||||
testClientOpenClose(client)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should read messages`() = testApplication {
|
||||
val clientFinished = CompletableDeferred<Unit>()
|
||||
|
||||
install(WebSockets)
|
||||
routing {
|
||||
mcpWebSocketTransport {
|
||||
onMessage = {
|
||||
send(it)
|
||||
}
|
||||
|
||||
clientFinished.await()
|
||||
}
|
||||
}
|
||||
|
||||
val client = createClient {
|
||||
install(io.ktor.client.plugins.websocket.WebSockets)
|
||||
}.mcpWebSocketTransport()
|
||||
|
||||
testClientRead(client)
|
||||
|
||||
clientFinished.complete(Unit)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue