Skip to content

Commit

Permalink
Remove throws from WebSocketClient.init
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Apr 5, 2024
1 parent 2fdb032 commit 288282b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Sources/HummingbirdWebSocket/Client/WebSocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public struct WebSocketClient {
eventLoopGroup: EventLoopGroup = MultiThreadedEventLoopGroup.singleton,
logger: Logger,
handler: @escaping WebSocketDataHandler<BasicWebSocketContext>
) throws {
) {
self.url = url
self.handler = handler
self.configuration = configuration
Expand All @@ -103,7 +103,7 @@ public struct WebSocketClient {
eventLoopGroup: NIOTSEventLoopGroup = NIOTSEventLoopGroup.singleton,
logger: Logger,
handler: @escaping WebSocketDataHandler<BasicWebSocketContext>
) throws {
) {
self.url = url
self.handler = handler
self.configuration = configuration
Expand Down Expand Up @@ -196,7 +196,7 @@ extension WebSocketClient {
logger: Logger,
handler: @escaping WebSocketDataHandler<BasicWebSocketContext>
) async throws {
let ws = try self.init(
let ws = self.init(
url: url,
configuration: configuration,
tlsConfiguration: tlsConfiguration,
Expand Down Expand Up @@ -225,7 +225,7 @@ extension WebSocketClient {
logger: Logger,
handler: @escaping WebSocketDataHandler<BasicWebSocketContext>
) async throws {
let ws = try self.init(
let ws = self.init(
url: url,
configuration: configuration,
transportServicesTLSOptions: transportServicesTLSOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class HummingbirdWebSocketExtensionTests: XCTestCase {
}
group.addTask {
let port = await promise.wait()
let client = try WebSocketClient(
let client = WebSocketClient(
url: .init("ws://localhost:\(port)/test"),
configuration: .init(extensions: clientExtensions),
logger: clientLogger,
Expand Down
26 changes: 13 additions & 13 deletions Tests/HummingbirdWebSocketTests/WebSocketTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
server: serverHandler,
shouldUpgrade: shouldUpgrade,
getClient: { port, logger in
try WebSocketClient(
WebSocketClient(
url: .init("ws://localhost:\(port)"),
logger: logger,
handler: clientHandler
Expand Down Expand Up @@ -243,7 +243,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
}

func testNoConnection() async throws {
let client = try WebSocketClient(
let client = WebSocketClient(
url: .init("ws://localhost:10245"),
logger: Logger(label: "TestNoConnection")
) { _, _, _ in
Expand All @@ -260,7 +260,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
} getClient: { port, logger in
var clientTLSConfiguration = try getClientTLSConfiguration()
clientTLSConfiguration.certificateVerification = .none
return try WebSocketClient(
return WebSocketClient(
url: .init("wss://localhost:\(port)"),
tlsConfiguration: clientTLSConfiguration,
logger: logger
Expand All @@ -279,7 +279,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
XCTAssertEqual(head.path, "/ws")
return [:]
} getClient: { port, logger in
try WebSocketClient(
WebSocketClient(
url: .init("ws://localhost:\(port)/ws"),
logger: logger
) { _, _, _ in
Expand All @@ -295,7 +295,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
XCTAssertEqual(request.uri.query, "query=parameters&test=true")
return [:]
} getClient: { port, logger in
try WebSocketClient(
WebSocketClient(
url: .init("ws://localhost:\(port)/ws?query=parameters&test=true"),
logger: logger
) { _, _, _ in
Expand All @@ -311,7 +311,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
XCTAssertEqual(request.headers[.secWebSocketExtensions], "hb")
return [:]
} getClient: { port, logger in
try WebSocketClient(
WebSocketClient(
url: .init("ws://localhost:\(port)/ws?query=parameters&test=true"),
configuration: .init(additionalHeaders: [.secWebSocketExtensions: "hb"]),
logger: logger
Expand Down Expand Up @@ -377,14 +377,14 @@ final class HummingbirdWebSocketTests: XCTestCase {
try await outbound.write(.text("Two"))
}
try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in
try WebSocketClient(url: .init("ws://localhost:\(port)/ws1"), logger: logger) { inbound, _, _ in
WebSocketClient(url: .init("ws://localhost:\(port)/ws1"), logger: logger) { inbound, _, _ in
var inboundIterator = inbound.makeAsyncIterator()
let msg = try await inboundIterator.next()
XCTAssertEqual(msg, .text("One"))
}
}
try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in
try WebSocketClient(url: .init("ws://localhost:\(port)/ws2"), logger: logger) { inbound, _, _ in
WebSocketClient(url: .init("ws://localhost:\(port)/ws2"), logger: logger) { inbound, _, _ in
var inboundIterator = inbound.makeAsyncIterator()
let msg = try await inboundIterator.next()
XCTAssertEqual(msg, .text("Two"))
Expand All @@ -402,7 +402,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
try await outbound.write(.text(String(test)))
}
try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in
try WebSocketClient(url: .init("ws://localhost:\(port)/ws?test=123"), logger: logger) { inbound, _, _ in
WebSocketClient(url: .init("ws://localhost:\(port)/ws?test=123"), logger: logger) { inbound, _, _ in
var inboundIterator = inbound.makeAsyncIterator()
let msg = try await inboundIterator.next()
XCTAssertEqual(msg, .text("123"))
Expand All @@ -421,7 +421,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
.get { _, _ -> Response in return .init(status: .ok) }
do {
try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in
try WebSocketClient(url: .init("ws://localhost:\(port)/ws"), logger: logger) { _, _, _ in }
WebSocketClient(url: .init("ws://localhost:\(port)/ws"), logger: logger) { _, _, _ in }
}
}
}
Expand All @@ -435,7 +435,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
}
do {
try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in
try WebSocketClient(url: .init("ws://localhost:\(port)/not-ws"), logger: logger) { _, _, _ in }
WebSocketClient(url: .init("ws://localhost:\(port)/not-ws"), logger: logger) { _, _, _ in }
}
} catch let error as WebSocketClientError where error == .webSocketUpgradeFailed {}
}
Expand Down Expand Up @@ -469,7 +469,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
}
do {
try await self.testClientAndServerWithRouter(webSocketRouter: router) { port, logger in
try WebSocketClient(url: .init("ws://localhost:\(port)/ws"), logger: logger) { inbound, _, _ in
WebSocketClient(url: .init("ws://localhost:\(port)/ws"), logger: logger) { inbound, _, _ in
let text = try await inbound.first { _ in true }
XCTAssertEqual(text, .text("Roger Moore"))
}
Expand Down Expand Up @@ -510,7 +510,7 @@ final class HummingbirdWebSocketTests: XCTestCase {
configuration: .init(autoPing: .enabled(timePeriod: .milliseconds(50)))
)
try await self.testClientAndServer(serverChannel: webSocketUpgrade) { port, logger in
try WebSocketClient(
WebSocketClient(
url: .init("ws://localhost:\(port)/ws"),
configuration: .init(additionalHeaders: [.secWebSocketExtensions: "hb"]),
logger: logger
Expand Down

0 comments on commit 288282b

Please sign in to comment.