-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add TestClientProtocol.ws * Use AHC for tests, live is currently causing the tests to hang * Use HummingbirdWSTesting in tests * Fix TLS test * Remove unused code * Use testing framework in extension tests
- Loading branch information
1 parent
f6f7357
commit 356b319
Showing
4 changed files
with
556 additions
and
500 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2023-2024 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import HummingbirdTesting | ||
import HummingbirdWSClient | ||
import Logging | ||
import NIOSSL | ||
|
||
extension TestClientProtocol { | ||
/// Test WebSocket endpoint | ||
/// - Parameters: | ||
/// - path: Endpoint path | ||
/// - configuration: WebSocket client configuration | ||
/// - logger: Logger | ||
/// - handler: WebSocket handler | ||
/// - Returns: WebSocket close frame | ||
@discardableResult public func ws( | ||
_ path: String, | ||
configuration: WebSocketClientConfiguration = .init(), | ||
logger: Logger = Logger(label: "TestClient"), | ||
handler: @escaping WebSocketDataHandler<WebSocketClient.Context> | ||
) async throws -> WebSocketCloseFrame? { | ||
guard let port else { | ||
preconditionFailure("Cannot test WebSockets without a live server. Use `.live` or `.ahc` to test WebSockets") | ||
} | ||
return try await WebSocketClient.connect( | ||
url: "ws://localhost:\(port)\(path)", | ||
configuration: configuration, | ||
logger: logger, | ||
handler: handler | ||
) | ||
} | ||
} |
Oops, something went wrong.