-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...tp/src/test/kotlin/net/mamoe/mirai/api/http/adapter/ws/extension/FrameLogExtensionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* | ||
* * Copyright 2023 Mamoe Technologies and contributors. | ||
* * | ||
* * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. | ||
* * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. | ||
* * | ||
* * https://github.com/mamoe/mirai/blob/master/LICENSE | ||
* | ||
*/ | ||
|
||
package net.mamoe.mirai.api.http.adapter.ws.extension | ||
|
||
import io.ktor.client.plugins.websocket.* | ||
import io.ktor.server.testing.* | ||
import io.ktor.server.websocket.* | ||
import io.ktor.server.websocket.WebSockets | ||
import io.ktor.websocket.* | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
|
||
class FrameLogExtensionTest { | ||
|
||
@Test | ||
fun testFrameLogExtension() = testApplication { | ||
install(WebSockets) { | ||
extensions { | ||
install(FrameLogExtension) | ||
} | ||
} | ||
|
||
routing { | ||
webSocket("/echo") { | ||
assertNotNull(extensionOrNull(FrameLogExtension)) | ||
for (frame in incoming) { | ||
send(frame) | ||
} | ||
} | ||
} | ||
|
||
val wsClient = createClient { install(io.ktor.client.plugins.websocket.WebSockets) } | ||
wsClient.ws("/echo") { | ||
outgoing.send(Frame.Text("Hello")) | ||
|
||
val receive = incoming.receive() | ||
assertEquals(FrameType.TEXT, receive.frameType) | ||
assertEquals("Hello", (receive as Frame.Text).readText()) | ||
} | ||
} | ||
} |