mirror of
https://github.com/appwrite/sdk-for-apple.git
synced 2026-11-18 20:53:33 +00:00
* chore: update Apple SDK to 21.1.0 * chore: update Apple SDK to 21.1.0 * chore: update Apple SDK to 21.1.0
44 lines
1.2 KiB
Swift
44 lines
1.2 KiB
Swift
import Foundation
|
|
import NIOCore
|
|
import NIOEmbedded
|
|
import NIOWebSocket
|
|
import Testing
|
|
|
|
@testable import Appwrite
|
|
|
|
final class MessageHandlerTests {
|
|
private final class Recorder: WebSocketClientDelegate {
|
|
var closes = 0
|
|
|
|
func onClose(channel: NIOCore.Channel, data: Data) {
|
|
closes += 1
|
|
}
|
|
}
|
|
|
|
private let recorder = Recorder()
|
|
|
|
private func connectedChannel() throws -> EmbeddedChannel {
|
|
let client = WebSocketClient("ws://localhost", tlsEnabled: false, delegate: recorder)!
|
|
let channel = EmbeddedChannel(handler: MessageHandler(client: client))
|
|
try channel.connect(to: SocketAddress(ipAddress: "127.0.0.1", port: 80)).wait()
|
|
return channel
|
|
}
|
|
|
|
@Test func closeWithoutCloseFrameDeliversOnClose() throws {
|
|
let channel = try connectedChannel()
|
|
|
|
try channel.close().wait()
|
|
|
|
#expect(recorder.closes == 1)
|
|
}
|
|
|
|
@Test func closeAfterCloseFrameDeliversOnCloseOnce() throws {
|
|
let channel = try connectedChannel()
|
|
|
|
try channel.writeInbound(WebSocketFrame(fin: true, opcode: .connectionClose, data: channel.allocator.buffer(capacity: 0)))
|
|
try channel.close().wait()
|
|
|
|
#expect(recorder.closes == 1)
|
|
}
|
|
}
|