Files
Jake Barnby 69af566260 feat: SDK update for version 21.1.0 (#133)
* chore: update Apple SDK to 21.1.0

* chore: update Apple SDK to 21.1.0

* chore: update Apple SDK to 21.1.0
2026-10-21 12:46:18 +13:00

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)
}
}