diff --git a/Benchmarks/Benchmarks/Router/RouterBenchmarks.swift b/Benchmarks/Benchmarks/Router/RouterBenchmarks.swift index dd0a4b046..92910f8f2 100644 --- a/Benchmarks/Benchmarks/Router/RouterBenchmarks.swift +++ b/Benchmarks/Benchmarks/Router/RouterBenchmarks.swift @@ -16,7 +16,7 @@ import Benchmark import HTTPTypes import Hummingbird import NIOHTTPTypes -@_spi(HBXCT) import HummingbirdCore +@_spi(HBInternal) import HummingbirdCore import Logging import NIOCore import NIOPosix diff --git a/Package.swift b/Package.swift index 3acca322d..1c74174d0 100644 --- a/Package.swift +++ b/Package.swift @@ -15,7 +15,7 @@ let package = Package( .library(name: "HummingbirdTLS", targets: ["HummingbirdTLS"]), .library(name: "HummingbirdJobs", targets: ["HummingbirdJobs"]), .library(name: "HummingbirdRouter", targets: ["HummingbirdRouter"]), - .library(name: "HummingbirdXCT", targets: ["HummingbirdXCT"]), + .library(name: "HummingbirdTesting", targets: ["HummingbirdTesting"]), .executable(name: "PerformanceTest", targets: ["PerformanceTest"]), ], dependencies: [ @@ -89,7 +89,7 @@ let package = Package( swiftSettings: swiftSettings ), .target( - name: "HummingbirdXCT", + name: "HummingbirdTesting", dependencies: [ .byName(name: "Hummingbird"), .product(name: "AsyncHTTPClient", package: "async-http-client"), @@ -138,16 +138,16 @@ let package = Package( .byName(name: "Hummingbird"), .byName(name: "HummingbirdTLS"), .byName(name: "HummingbirdHTTP2"), - .byName(name: "HummingbirdXCT"), + .byName(name: "HummingbirdTesting"), ]), .testTarget(name: "HummingbirdJobsTests", dependencies: [ .byName(name: "HummingbirdJobs"), - .byName(name: "HummingbirdXCT"), + .byName(name: "HummingbirdTesting"), .product(name: "Atomics", package: "swift-atomics"), ]), .testTarget(name: "HummingbirdRouterTests", dependencies: [ .byName(name: "HummingbirdRouter"), - .byName(name: "HummingbirdXCT"), + .byName(name: "HummingbirdTesting"), ]), .testTarget( name: "HummingbirdCoreTests", @@ -156,7 +156,7 @@ let package = Package( .byName(name: "HummingbirdCore"), .byName(name: "HummingbirdHTTP2"), .byName(name: "HummingbirdTLS"), - .byName(name: "HummingbirdXCT"), + .byName(name: "HummingbirdTesting"), .product(name: "AsyncHTTPClient", package: "async-http-client"), ], resources: [.process("Certificates")] diff --git a/README.md b/README.md index d38d92121..6b82efb10 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Hummingbird is designed to require the least number of dependencies possible, bu - `HummingbirdRouter`: an alternative router that uses a resultbuilder. - `HummingbirdTLS`: TLS support. - `HummingbirdHTTP2`: Support for HTTP2 upgrades. -- `HummingbirdXCT`: helper functions to aid testing Hummingbird projects. +- `HummingbirdTesting`: helper functions to aid testing Hummingbird projects. And also the following are available in other repositories in this organisation diff --git a/Sources/HummingbirdXCT/Application+XCT.swift b/Sources/HummingbirdTesting/Application+Test.swift similarity index 72% rename from Sources/HummingbirdXCT/Application+XCT.swift rename to Sources/HummingbirdTesting/Application+Test.swift index a985f8025..f39e4cc09 100644 --- a/Sources/HummingbirdXCT/Application+XCT.swift +++ b/Sources/HummingbirdTesting/Application+Test.swift @@ -17,27 +17,27 @@ import HummingbirdCore import NIOCore /// HTTP Scheme to use with AsyncHTTPClient test framework -public enum XCTScheme: String { +public enum HBTestHTTPScheme: String { case http case https } /// Type of test framework -public struct XCTTestingSetup { +public struct HBTestingSetup { enum Internal { case router case live - case ahc(XCTScheme) + case ahc(HBTestHTTPScheme) } let value: Internal /// Test writing requests directly to router. - public static var router: XCTTestingSetup { .init(value: .router) } + public static var router: HBTestingSetup { .init(value: .router) } /// Sets up a live server and execute tests using a HTTP client. Only supports HTTP1 - public static var live: XCTTestingSetup { .init(value: .live) } + public static var live: HBTestingSetup { .init(value: .live) } /// Sets up a live server and execute tests using a HTTP client. Does not support trailer headers - public static func ahc(_ scheme: XCTScheme) -> XCTTestingSetup { .init(value: .ahc(scheme)) } + public static func ahc(_ scheme: HBTestHTTPScheme) -> HBTestingSetup { .init(value: .ahc(scheme)) } } /// Extends `HBApplicationProtocol` to support testing of applications @@ -46,7 +46,7 @@ extension HBApplicationProtocol where Responder.Context: HBRequestContext { /// Test `HBApplication` /// - /// You use `test` and `XCTExecute` to test applications. You can either test using + /// You use `test` and `execute` to test applications. You can either test using /// the `.router` test framework which sends requests directly to the router for testing your code or /// the `.live` or `.ahc` frameworks which both run live servers to pass requests to, but provide /// a single connection HTTP client or AsyncHTTPClient as a client respectively . The `.router` test @@ -62,7 +62,7 @@ extension HBApplicationProtocol where Responder.Context: HBRequestContext { /// let app = HBApplication(router: router) /// app.test(.router) { client in /// // does my app return "hello" in the body for this route - /// client.XCTExecute(uri: "/hello", method: .GET) { response in + /// client.execute(uri: "/hello", method: .GET) { response in /// XCTAssertEqual(String(buffer: response.body), "hello") /// } /// } @@ -72,13 +72,13 @@ extension HBApplicationProtocol where Responder.Context: HBRequestContext { /// - testing: indicates which type of testing framework we want /// - configuration: configuration of application public func test( - _ testingSetup: XCTTestingSetup, - _ test: @escaping @Sendable (any HBXCTClientProtocol) async throws -> Value + _ testingSetup: HBTestingSetup, + _ test: @escaping @Sendable (any HBTestClientProtocol) async throws -> Value ) async throws -> Value { - let app: any HBXCTApplication = switch testingSetup.value { - case .router: try await HBXCTRouter(app: self) - case .live: HBXCTLive(app: self) - case .ahc(let scheme): HBXCTAsyncHTTPClient(app: self, scheme: scheme) + let app: any HBApplicationTestFramework = switch testingSetup.value { + case .router: try await HBRouterTestFramework(app: self) + case .live: HBLiveTestFramework(app: self) + case .ahc(let scheme): HBAsyncHTTPClientTestFramework(app: self, scheme: scheme) } return try await app.run(test) } diff --git a/Sources/HummingbirdXCT/HBXCTApplication.swift b/Sources/HummingbirdTesting/ApplicationTester.swift similarity index 70% rename from Sources/HummingbirdXCT/HBXCTApplication.swift rename to Sources/HummingbirdTesting/ApplicationTester.swift index 14f6a8983..becf94890 100644 --- a/Sources/HummingbirdXCT/HBXCTApplication.swift +++ b/Sources/HummingbirdTesting/ApplicationTester.swift @@ -17,8 +17,8 @@ import Hummingbird import NIOCore import ServiceLifecycle -/// Response structure returned by XCT testing framework -public struct HBXCTResponse: Sendable { +/// Response structure returned by testing framework +public struct HBTestResponse: Sendable { public let head: HTTPResponse /// response status public var status: HTTPResponse.Status { self.head.status } @@ -30,8 +30,8 @@ public struct HBXCTResponse: Sendable { public let trailerHeaders: HTTPFields? } -/// Errors thrown by XCT framework. -struct HBXCTError: Error, Equatable { +/// Errors thrown by testing framework. +struct HBTestError: Error, Equatable { private enum _Internal { case notStarted case noHead @@ -52,18 +52,18 @@ struct HBXCTError: Error, Equatable { static var timeout: Self { .init(.timeout) } } -/// Protocol for client used by HummingbirdXCT -public protocol HBXCTClientProtocol: Sendable { +/// Protocol for client used by HummingbirdTesting +public protocol HBTestClientProtocol: Sendable { /// Execute URL request and provide response - func execute( + func executeRequest( uri: String, method: HTTPRequest.Method, headers: HTTPFields, body: ByteBuffer? - ) async throws -> HBXCTResponse + ) async throws -> HBTestResponse } -extension HBXCTClientProtocol { +extension HBTestClientProtocol { /// Send request to associated test framework and call test callback on the response returned /// /// - Parameters: @@ -73,23 +73,23 @@ extension HBXCTClientProtocol { /// - body: Request body /// - testCallback: closure to call on response returned by test framework /// - Returns: Return value of test closure - @discardableResult public func XCTExecute( + @discardableResult public func execute( uri: String, method: HTTPRequest.Method, headers: HTTPFields = [:], body: ByteBuffer? = nil, - testCallback: @escaping (HBXCTResponse) async throws -> Return = { $0 } + testCallback: @escaping (HBTestResponse) async throws -> Return = { $0 } ) async throws -> Return { - let response = try await execute(uri: uri, method: method, headers: headers, body: body) + let response = try await executeRequest(uri: uri, method: method, headers: headers, body: body) return try await testCallback(response) } } -/// Protocol for Test application. -protocol HBXCTApplication { - /// Associated client with XCT server type - associatedtype Client: HBXCTClientProtocol +/// Protocol for application test framework +protocol HBApplicationTestFramework { + /// Associated client for application test + associatedtype Client: HBTestClientProtocol - /// Run XCT server - func run(_ test: @escaping @Sendable (any HBXCTClientProtocol) async throws -> Value) async throws -> Value + /// Run test server + func run(_ test: @escaping @Sendable (any HBTestClientProtocol) async throws -> Value) async throws -> Value } diff --git a/Sources/HummingbirdXCT/HBXCTAsyncHTTPClient.swift b/Sources/HummingbirdTesting/AsyncHTTPClientTestFramework.swift similarity index 95% rename from Sources/HummingbirdXCT/HBXCTAsyncHTTPClient.swift rename to Sources/HummingbirdTesting/AsyncHTTPClientTestFramework.swift index cab936632..6c92aefda 100644 --- a/Sources/HummingbirdXCT/HBXCTAsyncHTTPClient.swift +++ b/Sources/HummingbirdTesting/AsyncHTTPClientTestFramework.swift @@ -25,19 +25,19 @@ import ServiceLifecycle import XCTest /// Test using a live server and AsyncHTTPClient as a client -final class HBXCTAsyncHTTPClient: HBXCTApplication { - struct Client: HBXCTClientProtocol { +final class HBAsyncHTTPClientTestFramework: HBApplicationTestFramework { + struct Client: HBTestClientProtocol { let client: HTTPClient let urlPrefix: String let timeout: TimeAmount /// Send request and call test callback on the response returned - func execute( + func executeRequest( uri: String, method: HTTPRequest.Method, headers: HTTPFields = [:], body: ByteBuffer? = nil - ) async throws -> HBXCTResponse { + ) async throws -> HBTestResponse { let url = "\(self.urlPrefix)\(uri.first == "/" ? "" : "/")\(uri)" var request = HTTPClientRequest(url: url) request.method = .init(method) @@ -49,14 +49,14 @@ final class HBXCTAsyncHTTPClient: HBXCTApplication { } } - init(app: App, scheme: XCTScheme) { + init(app: App, scheme: HBTestHTTPScheme) { self.timeout = .seconds(15) self.application = TestApplication(base: app) self.scheme = scheme } /// Start tests - func run(_ test: @escaping @Sendable (HBXCTClientProtocol) async throws -> Value) async throws -> Value { + func run(_ test: @escaping @Sendable (HBTestClientProtocol) async throws -> Value) async throws -> Value { try await withThrowingTaskGroup(of: Void.self) { group in let serviceGroup = ServiceGroup( configuration: .init( @@ -90,7 +90,7 @@ final class HBXCTAsyncHTTPClient: HBXCTApplication { } let application: TestApplication - let scheme: XCTScheme + let scheme: HBTestHTTPScheme let timeout: TimeAmount } diff --git a/Sources/HummingbirdXCT/HBXCTLive.swift b/Sources/HummingbirdTesting/LiveTestFramework.swift similarity index 83% rename from Sources/HummingbirdXCT/HBXCTLive.swift rename to Sources/HummingbirdTesting/LiveTestFramework.swift index ac7db79f0..22e87768a 100644 --- a/Sources/HummingbirdXCT/HBXCTLive.swift +++ b/Sources/HummingbirdTesting/LiveTestFramework.swift @@ -23,20 +23,20 @@ import ServiceLifecycle import XCTest /// Test using a live server -final class HBXCTLive: HBXCTApplication { - struct Client: HBXCTClientProtocol { - let client: HBXCTClient +final class HBLiveTestFramework: HBApplicationTestFramework { + struct Client: HBTestClientProtocol { + let client: HBTestClient /// Send request and call test callback on the response returned - func execute( + func executeRequest( uri: String, method: HTTPRequest.Method, headers: HTTPFields = [:], body: ByteBuffer? = nil - ) async throws -> HBXCTResponse { + ) async throws -> HBTestResponse { var headers = headers headers[.connection] = "keep-alive" - let request = HBXCTClient.Request(uri, method: method, authority: "localhost", headers: headers, body: body) + let request = HBTestClient.Request(uri, method: method, authority: "localhost", headers: headers, body: body) let response = try await client.execute(request) return .init(head: response.head, body: response.body ?? ByteBuffer(), trailerHeaders: response.trailerHeaders) } @@ -48,7 +48,7 @@ final class HBXCTLive: HBXCTApplication { } /// Start tests - func run(_ test: @escaping @Sendable (HBXCTClientProtocol) async throws -> Value) async throws -> Value { + func run(_ test: @escaping @Sendable (HBTestClientProtocol) async throws -> Value) async throws -> Value { try await withThrowingTaskGroup(of: Void.self) { group in let serviceGroup = ServiceGroup( configuration: .init( @@ -61,7 +61,7 @@ final class HBXCTLive: HBXCTApplication { try await serviceGroup.run() } let port = await self.application.portPromise.wait() - let client = HBXCTClient( + let client = HBTestClient( host: "localhost", port: port, configuration: .init(timeout: self.timeout), diff --git a/Sources/HummingbirdXCT/HBXCTRouter.swift b/Sources/HummingbirdTesting/RouterTestFramework.swift similarity index 86% rename from Sources/HummingbirdXCT/HBXCTRouter.swift rename to Sources/HummingbirdTesting/RouterTestFramework.swift index 9c727234a..64add338b 100644 --- a/Sources/HummingbirdXCT/HBXCTRouter.swift +++ b/Sources/HummingbirdTesting/RouterTestFramework.swift @@ -15,8 +15,8 @@ import Atomics import HTTPTypes import NIOEmbedded -@_spi(HBXCT) import Hummingbird -@_spi(HBXCT) import HummingbirdCore +@_spi(HBInternal) import Hummingbird +@_spi(HBInternal) import HummingbirdCore import Logging import NIOConcurrencyHelpers import NIOCore @@ -25,7 +25,7 @@ import NIOPosix import ServiceLifecycle /// Test sending requests directly to router. This does not setup a live server -struct HBXCTRouter: HBXCTApplication where Responder.Context: HBBaseRequestContext { +struct HBRouterTestFramework: HBApplicationTestFramework where Responder.Context: HBBaseRequestContext { let responder: Responder let makeContext: @Sendable (Logger) -> Responder.Context let services: [any Service] @@ -46,7 +46,7 @@ struct HBXCTRouter: HBXCTApplication where Responder.Con } /// Run test - func run(_ test: @escaping @Sendable (HBXCTClientProtocol) async throws -> Value) async throws -> Value { + func run(_ test: @escaping @Sendable (HBTestClientProtocol) async throws -> Value) async throws -> Value { let client = Client( responder: self.responder, logger: self.logger, @@ -88,15 +88,15 @@ struct HBXCTRouter: HBXCTApplication where Responder.Con } } - /// HBXCTRouter client. Constructs an `HBRequest` sends it to the router and then converts - /// resulting response back to XCT response type - struct Client: HBXCTClientProtocol { + /// HBRouterTestFramework client. Constructs an `HBRequest` sends it to the router and then converts + /// resulting response back to test response type + struct Client: HBTestClientProtocol { let responder: Responder let logger: Logger let makeContext: @Sendable (Logger) -> Responder.Context - func execute(uri: String, method: HTTPRequest.Method, headers: HTTPFields, body: ByteBuffer?) async throws -> HBXCTResponse { - return try await withThrowingTaskGroup(of: HBXCTResponse.self) { group in + func executeRequest(uri: String, method: HTTPRequest.Method, headers: HTTPFields, body: ByteBuffer?) async throws -> HBTestResponse { + return try await withThrowingTaskGroup(of: HBTestResponse.self) { group in let (stream, source) = HBRequestBody.makeStream() let request = HBRequest( head: .init(method: method, scheme: "http", authority: "localhost", path: uri, headerFields: headers), @@ -118,7 +118,7 @@ struct HBXCTRouter: HBXCTApplication where Responder.Con let responseWriter = RouterResponseWriter() let trailerHeaders = try await response.body.write(responseWriter) return responseWriter.collated.withLockedValue { collated in - HBXCTResponse(head: response.head, body: collated, trailerHeaders: trailerHeaders) + HBTestResponse(head: response.head, body: collated, trailerHeaders: trailerHeaders) } } diff --git a/Sources/HummingbirdXCT/TestApplication.swift b/Sources/HummingbirdTesting/TestApplication.swift similarity index 96% rename from Sources/HummingbirdXCT/TestApplication.swift rename to Sources/HummingbirdTesting/TestApplication.swift index 663264ef4..eecccde65 100644 --- a/Sources/HummingbirdXCT/TestApplication.swift +++ b/Sources/HummingbirdTesting/TestApplication.swift @@ -21,7 +21,7 @@ import ServiceLifecycle /// TestApplication used to wrap HBApplication being tested. /// /// This is needed to override the `onServerRunning` function -struct TestApplication: HBApplicationProtocol, Service { +internal struct TestApplication: HBApplicationProtocol, Service { typealias Responder = BaseApp.Responder typealias ChildChannel = BaseApp.ChildChannel diff --git a/Sources/HummingbirdXCT/XCTClient+types.swift b/Sources/HummingbirdTesting/TestClient+types.swift similarity index 98% rename from Sources/HummingbirdXCT/XCTClient+types.swift rename to Sources/HummingbirdTesting/TestClient+types.swift index db6909d85..968ff0fc0 100644 --- a/Sources/HummingbirdXCT/XCTClient+types.swift +++ b/Sources/HummingbirdTesting/TestClient+types.swift @@ -17,7 +17,7 @@ import HTTPTypes import NIOCore /// HTTP client types -extension HBXCTClient { +extension HBTestClient { public enum Error: Swift.Error { case invalidURL case malformedResponse diff --git a/Sources/HummingbirdXCT/XCTClient.swift b/Sources/HummingbirdTesting/TestClient.swift similarity index 85% rename from Sources/HummingbirdXCT/XCTClient.swift rename to Sources/HummingbirdTesting/TestClient.swift index 4f9c71b9e..1ac6ca630 100644 --- a/Sources/HummingbirdXCT/XCTClient.swift +++ b/Sources/HummingbirdTesting/TestClient.swift @@ -23,7 +23,7 @@ import NIOSSL /// /// This HTTP client is used for internal testing of Hummingbird and is also /// the client used by `.live` testing framework. -public struct HBXCTClient: Sendable { +public struct HBTestClient: Sendable { public let channelPromise: EventLoopPromise let eventLoopGroup: EventLoopGroup let eventLoopGroupProvider: NIOEventLoopGroupProvider @@ -31,7 +31,7 @@ public struct HBXCTClient: Sendable { let port: Int let configuration: Configuration - /// HBXCT configuration + /// HBTestClient configuration public struct Configuration: Sendable { public init( tlsConfiguration: TLSConfiguration? = nil, @@ -51,7 +51,7 @@ public struct HBXCTClient: Sendable { public let serverName: String? } - /// Initialize HBXCTClient + /// Initialize HBTestClient /// - Parameters: /// - host: host to connect /// - port: port to connect to @@ -97,7 +97,7 @@ public struct HBXCTClient: Sendable { .connect(host: self.host, port: self.port) .cascade(to: self.channelPromise) } catch { - self.channelPromise.fail(HBXCTClient.Error.tlsSetupFailed) + self.channelPromise.fail(HBTestClient.Error.tlsSetupFailed) } } @@ -105,7 +105,7 @@ public struct HBXCTClient: Sendable { public func shutdown() async throws { do { try await self.close() - } catch HBXCTClient.Error.connectionNotOpen { + } catch HBTestClient.Error.connectionNotOpen { } catch ChannelError.alreadyClosed {} if case .createNew = self.eventLoopGroupProvider { try await self.eventLoopGroup.shutdownGracefully() @@ -113,45 +113,45 @@ public struct HBXCTClient: Sendable { } /// GET request - public func get(_ uri: String, headers: HTTPFields = [:]) async throws -> HBXCTClient.Response { - let request = HBXCTClient.Request(uri, method: .get, headers: headers) + public func get(_ uri: String, headers: HTTPFields = [:]) async throws -> HBTestClient.Response { + let request = HBTestClient.Request(uri, method: .get, headers: headers) return try await self.execute(request) } /// HEAD request - public func head(_ uri: String, headers: HTTPFields = [:]) async throws -> HBXCTClient.Response { - let request = HBXCTClient.Request(uri, method: .head, headers: headers) + public func head(_ uri: String, headers: HTTPFields = [:]) async throws -> HBTestClient.Response { + let request = HBTestClient.Request(uri, method: .head, headers: headers) return try await self.execute(request) } /// PUT request - public func put(_ uri: String, headers: HTTPFields = [:], body: ByteBuffer) async throws -> HBXCTClient.Response { - let request = HBXCTClient.Request(uri, method: .put, headers: headers, body: body) + public func put(_ uri: String, headers: HTTPFields = [:], body: ByteBuffer) async throws -> HBTestClient.Response { + let request = HBTestClient.Request(uri, method: .put, headers: headers, body: body) return try await self.execute(request) } /// POST request - public func post(_ uri: String, headers: HTTPFields = [:], body: ByteBuffer) async throws -> HBXCTClient.Response { - let request = HBXCTClient.Request(uri, method: .post, headers: headers, body: body) + public func post(_ uri: String, headers: HTTPFields = [:], body: ByteBuffer) async throws -> HBTestClient.Response { + let request = HBTestClient.Request(uri, method: .post, headers: headers, body: body) return try await self.execute(request) } /// DELETE request - public func delete(_ uri: String, headers: HTTPFields = [:], body: ByteBuffer) async throws -> HBXCTClient.Response { - let request = HBXCTClient.Request(uri, method: .delete, headers: headers, body: body) + public func delete(_ uri: String, headers: HTTPFields = [:], body: ByteBuffer) async throws -> HBTestClient.Response { + let request = HBTestClient.Request(uri, method: .delete, headers: headers, body: body) return try await self.execute(request) } /// Execute request to server. Return `EventLoopFuture` that will be fulfilled with HTTP response - public func execute(_ request: HBXCTClient.Request) async throws -> HBXCTClient.Response { + public func execute(_ request: HBTestClient.Request) async throws -> HBTestClient.Response { let channel = try await getChannel() - let response = try await withThrowingTaskGroup(of: HBXCTClient.Response.self) { group in + let response = try await withThrowingTaskGroup(of: HBTestClient.Response.self) { group in group.addTask { try await Task.sleep(for: self.configuration.timeout) throw Error.readTimeout } group.addTask { - let promise = self.eventLoopGroup.any().makePromise(of: HBXCTClient.Response.self) + let promise = self.eventLoopGroup.any().makePromise(of: HBTestClient.Response.self) let task = HTTPTask(request: self.cleanupRequest(request), responsePromise: promise) channel.writeAndFlush(task, promise: nil) return try await promise.futureResult.get() @@ -164,7 +164,7 @@ public struct HBXCTClient: Sendable { } public func close() async throws { - self.channelPromise.completeWith(.failure(HBXCTClient.Error.connectionNotOpen)) + self.channelPromise.completeWith(.failure(HBTestClient.Error.connectionNotOpen)) let channel = try await getChannel() return try await channel.close() } @@ -173,7 +173,7 @@ public struct HBXCTClient: Sendable { try await self.channelPromise.futureResult.get() } - private func cleanupRequest(_ request: HBXCTClient.Request) -> HBXCTClient.Request { + private func cleanupRequest(_ request: HBTestClient.Request) -> HBTestClient.Request { var request = request if let contentLength = request.body.map(\.readableBytes) { request.headers[.contentLength] = String(describing: contentLength) @@ -195,7 +195,7 @@ public struct HBXCTClient: Sendable { /// Channel Handler for serializing request header and data private class HTTPClientRequestSerializer: ChannelOutboundHandler { - typealias OutboundIn = HBXCTClient.Request + typealias OutboundIn = HBTestClient.Request typealias OutboundOut = HTTPRequestPart func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise?) { @@ -212,7 +212,7 @@ public struct HBXCTClient: Sendable { /// Channel Handler for parsing response from server private class HTTPClientResponseHandler: ChannelInboundHandler { typealias InboundIn = HTTPResponsePart - typealias InboundOut = HBXCTClient.Response + typealias InboundOut = HBTestClient.Response private enum ResponseState { /// Waiting to parse the next response. @@ -236,7 +236,7 @@ public struct HBXCTClient: Sendable { body.writeBuffer(&part) self.state = .body(head, body) case (.end(let trailerHeaders), .body(let head, let body)): - let response = HBXCTClient.Response( + let response = HBTestClient.Response( head: head, body: body, trailerHeaders: trailerHeaders @@ -246,7 +246,7 @@ public struct HBXCTClient: Sendable { } self.state = .idle case (.end(let trailerHeaders), .head(let head)): - let response = HBXCTClient.Response( + let response = HBTestClient.Response( head: head, body: nil, trailerHeaders: trailerHeaders @@ -256,22 +256,22 @@ public struct HBXCTClient: Sendable { } self.state = .idle default: - context.fireErrorCaught(HBXCTClient.Error.malformedResponse) + context.fireErrorCaught(HBTestClient.Error.malformedResponse) } } } /// HTTP Task structure private struct HTTPTask { - let request: HBXCTClient.Request - let responsePromise: EventLoopPromise + let request: HBTestClient.Request + let responsePromise: EventLoopPromise } /// HTTP Task handler. Kicks off HTTP Request and fulfills Response promise when response is returned private class HTTPTaskHandler: ChannelDuplexHandler { - typealias InboundIn = HBXCTClient.Response + typealias InboundIn = HBTestClient.Response typealias OutboundIn = HTTPTask - typealias OutboundOut = HBXCTClient.Request + typealias OutboundOut = HBTestClient.Request var queue: CircularBuffer @@ -311,7 +311,7 @@ public struct HBXCTClient: Sendable { switch event { case let evt as IdleStateHandler.IdleStateEvent where evt == .read: while let task = self.queue.popFirst() { - task.responsePromise.fail(HBXCTClient.Error.readTimeout) + task.responsePromise.fail(HBTestClient.Error.readTimeout) } default: diff --git a/Tests/HummingbirdCoreTests/ClientTests.swift b/Tests/HummingbirdCoreTests/ClientTests.swift index d27682ed5..a37df5df3 100644 --- a/Tests/HummingbirdCoreTests/ClientTests.swift +++ b/Tests/HummingbirdCoreTests/ClientTests.swift @@ -14,8 +14,8 @@ import HTTPTypes import HummingbirdCore +import HummingbirdTesting import HummingbirdTLS -import HummingbirdXCT import Logging import NIOCore import NIOHTTPTypes @@ -201,7 +201,7 @@ struct HTTP1ClientChannel: HBClientChannel { struct InvalidHTTPPart: Error {} extension NIOAsyncChannelInboundStream.AsyncIterator { - mutating func readResponse() async throws -> HBXCTClient.Response { + mutating func readResponse() async throws -> HBTestClient.Response { let headPart = try await self.next() guard case .head(let head) = headPart else { throw InvalidHTTPPart() } var body = ByteBuffer() @@ -220,7 +220,7 @@ extension NIOAsyncChannelInboundStream.AsyncIterator { } extension NIOAsyncChannelOutboundWriter { - func writeRequest(_ request: HBXCTClient.Request) async throws { + func writeRequest(_ request: HBTestClient.Request) async throws { try await self.write(.head(request.head)) if let body = request.body, body.readableBytes > 0 { try await self.write(.body(body)) diff --git a/Tests/HummingbirdCoreTests/CoreTests.swift b/Tests/HummingbirdCoreTests/CoreTests.swift index f1cc58c6b..a750b80f0 100644 --- a/Tests/HummingbirdCoreTests/CoreTests.swift +++ b/Tests/HummingbirdCoreTests/CoreTests.swift @@ -16,7 +16,7 @@ import AsyncAlgorithms import Atomics import HTTPTypes import HummingbirdCore -import HummingbirdXCT +import HummingbirdTesting import Logging import NIOCore import NIOHTTPTypes @@ -281,7 +281,7 @@ class HummingBirdCoreTests: XCTestCase { do { _ = try await client.get("/", headers: [.connection: "keep-alive"]) XCTFail("Should not get here") - } catch HBXCTClient.Error.connectionClosing { + } catch HBTestClient.Error.connectionClosing { } catch { XCTFail("Unexpected error: \(error)") } diff --git a/Tests/HummingbirdCoreTests/HTTP2Tests.swift b/Tests/HummingbirdCoreTests/HTTP2Tests.swift index e58bd4b43..5cc6bbeb5 100644 --- a/Tests/HummingbirdCoreTests/HTTP2Tests.swift +++ b/Tests/HummingbirdCoreTests/HTTP2Tests.swift @@ -15,7 +15,7 @@ import AsyncHTTPClient import HummingbirdCore import HummingbirdHTTP2 -import HummingbirdXCT +import HummingbirdTesting import Logging import NIOCore import NIOHTTP1 diff --git a/Tests/HummingbirdCoreTests/TLSTests.swift b/Tests/HummingbirdCoreTests/TLSTests.swift index 451c9b06a..b5e269bb2 100644 --- a/Tests/HummingbirdCoreTests/TLSTests.swift +++ b/Tests/HummingbirdCoreTests/TLSTests.swift @@ -13,8 +13,8 @@ //===----------------------------------------------------------------------===// import HummingbirdCore +import HummingbirdTesting import HummingbirdTLS -import HummingbirdXCT import Logging import NIOCore import NIOPosix diff --git a/Tests/HummingbirdCoreTests/TSTests.swift b/Tests/HummingbirdCoreTests/TSTests.swift index b2b3286b6..9a7fe90b4 100644 --- a/Tests/HummingbirdCoreTests/TSTests.swift +++ b/Tests/HummingbirdCoreTests/TSTests.swift @@ -15,7 +15,7 @@ #if canImport(Network) import HummingbirdCore -import HummingbirdXCT +import HummingbirdTesting import Logging import Network import NIOCore diff --git a/Tests/HummingbirdCoreTests/TestUtils.swift b/Tests/HummingbirdCoreTests/TestUtils.swift index 6a42ba3b5..120643b14 100644 --- a/Tests/HummingbirdCoreTests/TestUtils.swift +++ b/Tests/HummingbirdCoreTests/TestUtils.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// import HummingbirdCore -import HummingbirdXCT +import HummingbirdTesting import Logging import NIOCore import NIOSSL @@ -74,8 +74,8 @@ public func testServer( configuration: HBServerConfiguration, eventLoopGroup: EventLoopGroup, logger: Logger, - clientConfiguration: HBXCTClient.Configuration = .init(), - _ test: @escaping @Sendable (HBServer, HBXCTClient) async throws -> Value + clientConfiguration: HBTestClient.Configuration = .init(), + _ test: @escaping @Sendable (HBServer, HBTestClient) async throws -> Value ) async throws -> Value { try await testServer( responder: responder, @@ -84,7 +84,7 @@ public func testServer( eventLoopGroup: eventLoopGroup, logger: logger ) { (server: HBServer, port: Int) in - let client = HBXCTClient( + let client = HBTestClient( host: "localhost", port: port, configuration: clientConfiguration, @@ -103,8 +103,8 @@ public func testServer( configuration: HBServerConfiguration, eventLoopGroup: EventLoopGroup, logger: Logger, - clientConfiguration: HBXCTClient.Configuration = .init(), - _ test: @escaping @Sendable (HBXCTClient) async throws -> Value + clientConfiguration: HBTestClient.Configuration = .init(), + _ test: @escaping @Sendable (HBTestClient) async throws -> Value ) async throws -> Value { try await testServer( responder: responder, diff --git a/Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift b/Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift index ef56cedf1..1a7e71908 100644 --- a/Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift +++ b/Tests/HummingbirdJobsTests/HummingbirdJobsTests.swift @@ -14,7 +14,7 @@ import Atomics import HummingbirdJobs -import HummingbirdXCT +import HummingbirdTesting import Logging import NIOConcurrencyHelpers import ServiceLifecycle diff --git a/Tests/HummingbirdRouterTests/MiddlewareTests.swift b/Tests/HummingbirdRouterTests/MiddlewareTests.swift index a92b976f6..eb9e6610b 100644 --- a/Tests/HummingbirdRouterTests/MiddlewareTests.swift +++ b/Tests/HummingbirdRouterTests/MiddlewareTests.swift @@ -15,7 +15,7 @@ import HTTPTypes import Hummingbird import HummingbirdRouter -import HummingbirdXCT +import HummingbirdTesting import Logging import NIOCore import XCTest @@ -43,7 +43,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(response.headers[.middleware], "TestMiddleware") } } @@ -67,7 +67,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in // headers come back in opposite order as middleware is applied to responses in that order XCTAssertEqual(response.headers[values: .middleware].first, "second") XCTAssertEqual(response.headers[values: .middleware].last, "first") @@ -92,7 +92,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { _ in + try await client.execute(uri: "/hello", method: .get) { _ in } } } @@ -113,7 +113,7 @@ final class MiddlewareTests: XCTestCase { let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "Edited error") XCTAssertEqual(response.status, .notFound) } @@ -154,7 +154,7 @@ final class MiddlewareTests: XCTestCase { try await app.test(.router) { client in let buffer = self.randomBuffer(size: 64000) - try await client.XCTExecute(uri: "/test", method: .get, body: buffer) { response in + try await client.execute(uri: "/test", method: .get, body: buffer) { response in let expectedOutput = ByteBuffer(bytes: buffer.readableBytesView.map { $0 ^ 255 }) XCTAssertEqual(expectedOutput, response.body) } diff --git a/Tests/HummingbirdRouterTests/RouterTests.swift b/Tests/HummingbirdRouterTests/RouterTests.swift index 674afb1e2..ba1e7a9da 100644 --- a/Tests/HummingbirdRouterTests/RouterTests.swift +++ b/Tests/HummingbirdRouterTests/RouterTests.swift @@ -14,7 +14,7 @@ import Hummingbird import HummingbirdRouter -import HummingbirdXCT +import HummingbirdTesting import Logging import NIOCore import XCTest @@ -53,7 +53,7 @@ final class RouterTests: XCTestCase { let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test/1", method: .get) { response in + try await client.execute(uri: "/test/1", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/test/{number}") } } @@ -84,13 +84,13 @@ final class RouterTests: XCTestCase { let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/") } - try await client.XCTExecute(uri: "/test/", method: .get) { response in + try await client.execute(uri: "/test/", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/test") } - try await client.XCTExecute(uri: "/test2/", method: .post) { response in + try await client.execute(uri: "/test2/", method: .post) { response in XCTAssertEqual(String(buffer: response.body), "/test2") } } @@ -126,19 +126,19 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test/", method: .get) { response in + try await client.execute(uri: "/test/", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/test") } - try await client.XCTExecute(uri: "/test2/", method: .post) { response in + try await client.execute(uri: "/test2/", method: .post) { response in XCTAssertEqual(String(buffer: response.body), "/test2") } - try await client.XCTExecute(uri: "/testGroup/", method: .get) { response in + try await client.execute(uri: "/testGroup/", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/testGroup") } - try await client.XCTExecute(uri: "/testGroup2", method: .get) { response in + try await client.execute(uri: "/testGroup2", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/testGroup2") } } @@ -158,11 +158,11 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/endpoint", method: .get) { response in + try await client.execute(uri: "/endpoint", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "GET") } - try await client.XCTExecute(uri: "/endpoint", method: .put) { response in + try await client.execute(uri: "/endpoint", method: .put) { response in XCTAssertEqual(String(buffer: response.body), "PUT") } } @@ -184,11 +184,11 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/group", method: .get) { response in + try await client.execute(uri: "/group", method: .get) { response in XCTAssertEqual(response.headers[.middleware], "TestMiddleware") } - try await client.XCTExecute(uri: "/not-group", method: .get) { response in + try await client.execute(uri: "/not-group", method: .get) { response in XCTAssertEqual(response.headers[.middleware], nil) } } @@ -205,7 +205,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/group", method: .head) { response in + try await client.execute(uri: "/group", method: .head) { response in XCTAssertEqual(response.headers[.middleware], "TestMiddleware") } } @@ -225,7 +225,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test/group", method: .get) { response in + try await client.execute(uri: "/test/group", method: .get) { response in XCTAssertEqual(response.headers[.middleware], "TestMiddleware") } } @@ -260,10 +260,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test/group", method: .get) { response in + try await client.execute(uri: "/test/group", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "route2") } - try await client.XCTExecute(uri: "/test", method: .get) { response in + try await client.execute(uri: "/test", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "route1") } } @@ -301,10 +301,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test", method: .get) { response in + try await client.execute(uri: "/test", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "route1") } - try await client.XCTExecute(uri: "/test", method: .post) { response in + try await client.execute(uri: "/test", method: .post) { response in XCTAssertEqual(String(buffer: response.body), "route2") } } @@ -318,7 +318,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user/1234", method: .delete) { response in + try await client.execute(uri: "/user/1234", method: .delete) { response in XCTAssertEqual(String(buffer: response.body), "1234") } } @@ -333,7 +333,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user/john/1234", method: .delete) { response in + try await client.execute(uri: "/user/john/1234", method: .delete) { response in XCTAssertEqual(String(buffer: response.body), "1234") } } @@ -350,7 +350,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/files/file.doc/test.jpg", method: .get) { response in + try await client.execute(uri: "/files/file.doc/test.jpg", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "test.doc") } } @@ -364,10 +364,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/files/file.doc/test.jpg", method: .get) { response in + try await client.execute(uri: "/files/file.doc/test.jpg", method: .get) { response in XCTAssertEqual(response.status, .ok) } - try await client.XCTExecute(uri: "/files/file.doc/test.png", method: .get) { response in + try await client.execute(uri: "/files/file.doc/test.png", method: .get) { response in XCTAssertEqual(response.status, .notFound) } } @@ -382,10 +382,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - let id = try await client.XCTExecute(uri: "/id", method: .get) { response -> String in + let id = try await client.execute(uri: "/id", method: .get) { response -> String in return String(buffer: response.body) } - try await client.XCTExecute(uri: "/id", method: .get) { response in + try await client.execute(uri: "/id", method: .get) { response in let id2 = String(buffer: response.body) XCTAssertNotEqual(id2, id) } @@ -401,7 +401,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/redirect", method: .get) { response in + try await client.execute(uri: "/redirect", method: .get) { response in XCTAssertEqual(response.headers[.location], "/other") XCTAssertEqual(response.status, .seeOther) } @@ -416,7 +416,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(router: router) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "hello") } } diff --git a/Tests/HummingbirdTests/ApplicationTests.swift b/Tests/HummingbirdTests/ApplicationTests.swift index 726fd2d5a..fd792529f 100644 --- a/Tests/HummingbirdTests/ApplicationTests.swift +++ b/Tests/HummingbirdTests/ApplicationTests.swift @@ -17,8 +17,8 @@ import HTTPTypes import Hummingbird import HummingbirdCore import HummingbirdHTTP2 +import HummingbirdTesting import HummingbirdTLS -import HummingbirdXCT import Logging import NIOCore import NIOSSL @@ -39,7 +39,7 @@ final class ApplicationTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: response.body), "GET: Hello") } @@ -53,7 +53,7 @@ final class ApplicationTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/accepted", method: .get) { response in + try await client.execute(uri: "/accepted", method: .get) { response in XCTAssertEqual(response.status, .accepted) } } @@ -66,7 +66,7 @@ final class ApplicationTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.live) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(response.headers[.contentLength], "5") XCTAssertNotNil(response.headers[.date]) } @@ -80,7 +80,7 @@ final class ApplicationTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder(), configuration: .init(serverName: "TestServer")) try await app.test(.live) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(response.headers[.server], "TestServer") } } @@ -94,7 +94,7 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .post) { response in + try await client.execute(uri: "/hello", method: .post) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: response.body), "POST: Hello") } @@ -112,10 +112,10 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "GET") } - try await client.XCTExecute(uri: "/hello", method: .post) { response in + try await client.execute(uri: "/hello", method: .post) { response in XCTAssertEqual(String(buffer: response.body), "POST") } } @@ -133,10 +133,10 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "GET") } - try await client.XCTExecute(uri: "/hello", method: .post) { response in + try await client.execute(uri: "/hello", method: .post) { response in XCTAssertEqual(String(buffer: response.body), "POST") } } @@ -150,7 +150,7 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/query?test=test%20data%C3%A9", method: .post) { response in + try await client.execute(uri: "/query?test=test%20data%C3%A9", method: .post) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: response.body), "test dataƩ") } @@ -165,7 +165,7 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/add?value=3&value=45&value=7", method: .post) { response in + try await client.execute(uri: "/add?value=3&value=45&value=7", method: .post) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: response.body), "55") } @@ -180,7 +180,7 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/array", method: .get) { response in + try await client.execute(uri: "/array", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "[\"yes\",\"no\"]") } } @@ -198,7 +198,7 @@ final class ApplicationTests: XCTestCase { try await app.test(.router) { client in let buffer = self.randomBuffer(size: 1_140_000) - try await client.XCTExecute(uri: "/echo-body", method: .post, body: buffer) { response in + try await client.execute(uri: "/echo-body", method: .post, body: buffer) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(response.body, buffer) } @@ -223,15 +223,15 @@ final class ApplicationTests: XCTestCase { try await app.test(.router) { client in let buffer = self.randomBuffer(size: 640_001) - try await client.XCTExecute(uri: "/streaming", method: .post, body: buffer) { response in + try await client.execute(uri: "/streaming", method: .post, body: buffer) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(response.body, buffer) } - try await client.XCTExecute(uri: "/streaming", method: .post) { response in + try await client.execute(uri: "/streaming", method: .post) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(response.body, ByteBuffer()) } - try await client.XCTExecute(uri: "/size", method: .post, body: buffer) { response in + try await client.execute(uri: "/size", method: .post, body: buffer) { response in XCTAssertEqual(String(buffer: response.body), "640001") } } @@ -246,11 +246,11 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in let buffer = self.randomBuffer(size: 64) - try await client.XCTExecute(uri: "/streaming", method: .post, body: buffer) { response in + try await client.execute(uri: "/streaming", method: .post, body: buffer) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(response.body, buffer) } - try await client.XCTExecute(uri: "/streaming", method: .post) { response in + try await client.execute(uri: "/streaming", method: .post) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(response.body, ByteBuffer()) } @@ -275,7 +275,7 @@ final class ApplicationTests: XCTestCase { try await app.test(.router) { client in let buffer = self.randomBuffer(size: 512_000) - try await client.XCTExecute(uri: "/hello", method: .put, body: buffer) { response in + try await client.execute(uri: "/hello", method: .put, body: buffer) { response in XCTAssertEqual(String(buffer: response.body), "512000") XCTAssertEqual(response.status, .ok) } @@ -297,7 +297,7 @@ final class ApplicationTests: XCTestCase { try await app.test(.router) { client in let buffer = self.randomBuffer(size: 100_000) - try await client.XCTExecute(uri: "/size", method: .post, body: buffer) { response in + try await client.execute(uri: "/size", method: .post, body: buffer) { response in XCTAssertEqual(String(buffer: response.body), "100000") } } @@ -315,11 +315,11 @@ final class ApplicationTests: XCTestCase { try await app.test(.router) { client in let buffer = self.randomBuffer(size: 64) - try await client.XCTExecute(uri: "/echo-body", method: .post, body: buffer) { response in + try await client.execute(uri: "/echo-body", method: .post, body: buffer) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(response.body, buffer) } - try await client.XCTExecute(uri: "/echo-body", method: .post) { response in + try await client.execute(uri: "/echo-body", method: .post) { response in XCTAssertEqual(response.status, .noContent) } } @@ -351,7 +351,7 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/name", method: .patch) { response in + try await client.execute(uri: "/name", method: .patch) { response in XCTAssertEqual(String(buffer: response.body), #"{"first":"john","last":"smith"}"#) } } @@ -369,7 +369,7 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .delete) { response in + try await client.execute(uri: "/hello", method: .delete) { response in XCTAssertEqual(response.status, .preconditionRequired) XCTAssertEqual(response.headers[.test], "value") XCTAssertEqual(response.headers[.contentType], "application/json") @@ -393,7 +393,7 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .patch) { response in + try await client.execute(uri: "/hello", method: .patch) { response in XCTAssertEqual(response.status, .multipleChoices) XCTAssertEqual(response.headers[.test], "value") XCTAssertEqual(response.headers[.contentType], "application/json") @@ -423,11 +423,11 @@ final class ApplicationTests: XCTestCase { try await app.test(.live) { client in let buffer = self.randomBuffer(size: 128 * 1024) // check non streamed route throws an error - try await client.XCTExecute(uri: "/upload", method: .post, body: buffer) { response in + try await client.execute(uri: "/upload", method: .post, body: buffer) { response in XCTAssertEqual(response.status, .contentTooLarge) } // check streamed route doesn't - try await client.XCTExecute(uri: "/stream", method: .post, body: buffer) { response in + try await client.execute(uri: "/stream", method: .post, body: buffer) { response in XCTAssertEqual(response.status, .ok) } } @@ -463,7 +463,7 @@ final class ApplicationTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.live) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .ok) let address = String(buffer: response.body) XCTAssert(address == "127.0.0.1" || address == "::1") @@ -483,7 +483,7 @@ final class ApplicationTests: XCTestCase { } let app = createApplication() try await app.test(.live) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: response.body), "GET: Hello") } @@ -505,7 +505,7 @@ final class ApplicationTests: XCTestCase { } let app = MyApp() try await app.test(.live) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: response.body), "GET: Hello") } @@ -579,7 +579,7 @@ final class ApplicationTests: XCTestCase { server: .tls(tlsConfiguration: self.getServerTLSConfiguration()) ) try await app.test(.ahc(.https)) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .ok) let string = String(buffer: response.body) XCTAssertEqual(string, "Hello") @@ -598,7 +598,7 @@ final class ApplicationTests: XCTestCase { server: .http2Upgrade(tlsConfiguration: self.getServerTLSConfiguration()) ) try await app.test(.ahc(.https)) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .ok) let string = String(buffer: response.body) XCTAssertEqual(string, "Hello") @@ -614,7 +614,7 @@ final class ApplicationTests: XCTestCase { } let app = HBApplication(router: router) try await app.test(.live) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .ok) let string = String(buffer: response.body) XCTAssertEqual(string, "Hello") @@ -639,7 +639,7 @@ final class ApplicationTests: XCTestCase { } let app = HBApplication(router: router) try await app.test(.live) { client in - try await client.XCTExecute(uri: "/", method: .post, body: buffer) { response in + try await client.execute(uri: "/", method: .post, body: buffer) { response in XCTAssertEqual(response.body, ByteBuffer(bytes: buffer.readableBytesView.map { $0 ^ 0xFF })) } } diff --git a/Tests/HummingbirdTests/CookiesTests.swift b/Tests/HummingbirdTests/CookiesTests.swift index d3ecee69b..5c5203d5c 100644 --- a/Tests/HummingbirdTests/CookiesTests.swift +++ b/Tests/HummingbirdTests/CookiesTests.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// @testable import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import XCTest class CookieTests: XCTestCase { @@ -73,7 +73,7 @@ class CookieTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .post) { response in + try await client.execute(uri: "/", method: .post) { response in XCTAssertEqual(response.headers[.setCookie], "test=value; HttpOnly") } } @@ -86,7 +86,7 @@ class CookieTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .post) { response in + try await client.execute(uri: "/", method: .post) { response in XCTAssertEqual(response.headers[.setCookie], "test=value; HttpOnly") } } @@ -99,7 +99,7 @@ class CookieTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .post, headers: [.cookie: "test=value"]) { response in + try await client.execute(uri: "/", method: .post, headers: [.cookie: "test=value"]) { response in XCTAssertEqual(String(buffer: response.body), "value") } } diff --git a/Tests/HummingbirdTests/DateCacheTests.swift b/Tests/HummingbirdTests/DateCacheTests.swift index 246fd6ad2..1cb4075a3 100644 --- a/Tests/HummingbirdTests/DateCacheTests.swift +++ b/Tests/HummingbirdTests/DateCacheTests.swift @@ -14,7 +14,7 @@ import Foundation import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import XCTest class HummingbirdDateTests: XCTestCase { @@ -38,12 +38,12 @@ class HummingbirdDateTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.live) { client in - let date = try await client.XCTExecute(uri: "/date", method: .get) { response in + let date = try await client.execute(uri: "/date", method: .get) { response in XCTAssertNotNil(response.headers[.date]) return response.headers[.date] } try await Task.sleep(nanoseconds: 1_500_000_000) - try await client.XCTExecute(uri: "/date", method: .get) { response in + try await client.execute(uri: "/date", method: .get) { response in XCTAssertNotEqual(response.headers[.date], date) } } diff --git a/Tests/HummingbirdTests/FileIOTests.swift b/Tests/HummingbirdTests/FileIOTests.swift index 1e495a7f2..feb6ee3c7 100644 --- a/Tests/HummingbirdTests/FileIOTests.swift +++ b/Tests/HummingbirdTests/FileIOTests.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import XCTest class FileIOTests: XCTestCase { @@ -39,7 +39,7 @@ class FileIOTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test.jpg", method: .get) { response in + try await client.execute(uri: "/test.jpg", method: .get) { response in XCTAssertEqual(response.body, buffer) } } @@ -57,7 +57,7 @@ class FileIOTests: XCTestCase { try await app.test(.router) { client in let buffer = ByteBufferAllocator().buffer(string: "This is a test") - try await client.XCTExecute(uri: "/store", method: .put, body: buffer) { response in + try await client.execute(uri: "/store", method: .put, body: buffer) { response in XCTAssertEqual(response.status, .ok) } } @@ -80,7 +80,7 @@ class FileIOTests: XCTestCase { try await app.test(.live) { client in let buffer = self.randomBuffer(size: 400_000) - try await client.XCTExecute(uri: "/store", method: .put, body: buffer) { response in + try await client.execute(uri: "/store", method: .put, body: buffer) { response in XCTAssertEqual(response.status, .ok) } diff --git a/Tests/HummingbirdTests/FileMiddlewareTests.swift b/Tests/HummingbirdTests/FileMiddlewareTests.swift index 321aecce6..99727732c 100644 --- a/Tests/HummingbirdTests/FileMiddlewareTests.swift +++ b/Tests/HummingbirdTests/FileMiddlewareTests.swift @@ -15,7 +15,7 @@ import Foundation import HTTPTypes import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import XCTest class HummingbirdFilesTests: XCTestCase { @@ -46,7 +46,7 @@ class HummingbirdFilesTests: XCTestCase { defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL)) } try await app.test(.router) { client in - try await client.XCTExecute(uri: filename, method: .get) { response in + try await client.execute(uri: filename, method: .get) { response in XCTAssertEqual(String(buffer: response.body), text) XCTAssertEqual(response.headers[.contentType], "image/jpeg") } @@ -66,7 +66,7 @@ class HummingbirdFilesTests: XCTestCase { defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL)) } try await app.test(.router) { client in - try await client.XCTExecute(uri: filename, method: .get) { response in + try await client.execute(uri: filename, method: .get) { response in XCTAssertEqual(response.body, buffer) } } @@ -85,28 +85,28 @@ class HummingbirdFilesTests: XCTestCase { defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL)) } try await app.test(.router) { client in - try await client.XCTExecute(uri: filename, method: .get, headers: [.range: "bytes=100-3999"]) { response in + try await client.execute(uri: filename, method: .get, headers: [.range: "bytes=100-3999"]) { response in let slice = buffer.getSlice(at: 100, length: 3900) XCTAssertEqual(response.body, slice) XCTAssertEqual(response.headers[.contentRange], "bytes 100-3999/326000") XCTAssertEqual(response.headers[.contentType], "text/plain") } - try await client.XCTExecute(uri: filename, method: .get, headers: [.range: "bytes=0-0"]) { response in + try await client.execute(uri: filename, method: .get, headers: [.range: "bytes=0-0"]) { response in let slice = buffer.getSlice(at: 0, length: 1) XCTAssertEqual(response.body, slice) XCTAssertEqual(response.headers[.contentRange], "bytes 0-0/326000") XCTAssertEqual(response.headers[.contentType], "text/plain") } - try await client.XCTExecute(uri: filename, method: .get, headers: [.range: "bytes=-3999"]) { response in + try await client.execute(uri: filename, method: .get, headers: [.range: "bytes=-3999"]) { response in let slice = buffer.getSlice(at: 0, length: 4000) XCTAssertEqual(response.body, slice) XCTAssertEqual(response.headers[.contentLength], "4000") XCTAssertEqual(response.headers[.contentRange], "bytes 0-3999/326000") } - try await client.XCTExecute(uri: filename, method: .get, headers: [.range: "bytes=6000-"]) { response in + try await client.execute(uri: filename, method: .get, headers: [.range: "bytes=6000-"]) { response in let slice = buffer.getSlice(at: 6000, length: 320_000) XCTAssertEqual(response.body, slice) XCTAssertEqual(response.headers[.contentRange], "bytes 6000-325999/326000") @@ -127,7 +127,7 @@ class HummingbirdFilesTests: XCTestCase { defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL)) } try await app.test(.router) { client in - let (eTag, modificationDate) = try await client.XCTExecute(uri: filename, method: .get, headers: [.range: "bytes=-3999"]) { response -> (String, String) in + let (eTag, modificationDate) = try await client.execute(uri: filename, method: .get, headers: [.range: "bytes=-3999"]) { response -> (String, String) in let eTag = try XCTUnwrap(response.headers[.eTag]) let modificationDate = try XCTUnwrap(response.headers[.lastModified]) let slice = buffer.getSlice(at: 0, length: 4000) @@ -136,15 +136,15 @@ class HummingbirdFilesTests: XCTestCase { return (eTag, modificationDate) } - try await client.XCTExecute(uri: filename, method: .get, headers: [.range: "bytes=4000-", .ifRange: eTag]) { response in + try await client.execute(uri: filename, method: .get, headers: [.range: "bytes=4000-", .ifRange: eTag]) { response in XCTAssertEqual(response.headers[.contentRange], "bytes 4000-9999/10000") } - try await client.XCTExecute(uri: filename, method: .get, headers: [.range: "bytes=4000-", .ifRange: modificationDate]) { response in + try await client.execute(uri: filename, method: .get, headers: [.range: "bytes=4000-", .ifRange: modificationDate]) { response in XCTAssertEqual(response.headers[.contentRange], "bytes 4000-9999/10000") } - try await client.XCTExecute(uri: filename, method: .get, headers: [.range: "bytes=4000-", .ifRange: "not valid"]) { response in + try await client.execute(uri: filename, method: .get, headers: [.range: "bytes=4000-", .ifRange: "not valid"]) { response in XCTAssertNil(response.headers[.contentRange]) } } @@ -163,7 +163,7 @@ class HummingbirdFilesTests: XCTestCase { defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL)) } try await app.test(.router) { client in - try await client.XCTExecute(uri: "/testHead.txt", method: .head) { response in + try await client.execute(uri: "/testHead.txt", method: .head) { response in XCTAssertEqual(response.body.readableBytes, 0) XCTAssertEqual(response.headers[.contentLength], text.utf8.count.description) XCTAssertEqual(response.headers[.contentType], "text/plain") @@ -188,10 +188,10 @@ class HummingbirdFilesTests: XCTestCase { try await app.test(.router) { client in var eTag: String? - try await client.XCTExecute(uri: filename, method: .head) { response in + try await client.execute(uri: filename, method: .head) { response in eTag = try XCTUnwrap(response.headers[.eTag]) } - try await client.XCTExecute(uri: filename, method: .head) { response in + try await client.execute(uri: filename, method: .head) { response in XCTAssertEqual(response.headers[.eTag], eTag) } } @@ -210,18 +210,18 @@ class HummingbirdFilesTests: XCTestCase { defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL)) } try await app.test(.router) { client in - let eTag = try await client.XCTExecute(uri: filename, method: .head) { response in + let eTag = try await client.execute(uri: filename, method: .head) { response in return try XCTUnwrap(response.headers[.eTag]) } - try await client.XCTExecute(uri: filename, method: .get, headers: [.ifNoneMatch: eTag]) { response in + try await client.execute(uri: filename, method: .get, headers: [.ifNoneMatch: eTag]) { response in XCTAssertEqual(response.status, .notModified) } var headers: HTTPFields = .init() headers[values: .ifNoneMatch] = ["test", "\(eTag)"] - try await client.XCTExecute(uri: filename, method: .get, headers: headers) { response in + try await client.execute(uri: filename, method: .get, headers: headers) { response in XCTAssertEqual(response.status, .notModified) } - try await client.XCTExecute(uri: filename, method: .get, headers: [.ifNoneMatch: "dummyETag"]) { response in + try await client.execute(uri: filename, method: .get, headers: [.ifNoneMatch: "dummyETag"]) { response in XCTAssertEqual(response.status, .ok) } } @@ -240,15 +240,15 @@ class HummingbirdFilesTests: XCTestCase { defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL)) } try await app.test(.router) { client in - let modifiedDate = try await client.XCTExecute(uri: filename, method: .head) { response in + let modifiedDate = try await client.execute(uri: filename, method: .head) { response in return try XCTUnwrap(response.headers[.lastModified]) } - try await client.XCTExecute(uri: filename, method: .get, headers: [.ifModifiedSince: modifiedDate]) { response in + try await client.execute(uri: filename, method: .get, headers: [.ifModifiedSince: modifiedDate]) { response in XCTAssertEqual(response.status, .notModified) } // one minute before current date let date = try XCTUnwrap(self.rfc1123Formatter.string(from: Date(timeIntervalSinceNow: -60))) - try await client.XCTExecute(uri: filename, method: .get, headers: [.ifModifiedSince: date]) { response in + try await client.execute(uri: filename, method: .get, headers: [.ifModifiedSince: date]) { response in XCTAssertEqual(response.status, .ok) } } @@ -274,10 +274,10 @@ class HummingbirdFilesTests: XCTestCase { defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL2)) } try await app.test(.router) { client in - try await client.XCTExecute(uri: filename, method: .get) { response in + try await client.execute(uri: filename, method: .get) { response in XCTAssertEqual(response.headers[.cacheControl], "max-age=2592000") } - try await client.XCTExecute(uri: "/test.jpg", method: .get) { response in + try await client.execute(uri: "/test.jpg", method: .get) { response in XCTAssertEqual(response.headers[.cacheControl], "max-age=2592000, private") } } @@ -295,7 +295,7 @@ class HummingbirdFilesTests: XCTestCase { defer { XCTAssertNoThrow(try FileManager.default.removeItem(at: fileURL)) } try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(String(buffer: response.body), text) } } diff --git a/Tests/HummingbirdTests/HandlerTests.swift b/Tests/HummingbirdTests/HandlerTests.swift index 91061c896..6d371df50 100644 --- a/Tests/HummingbirdTests/HandlerTests.swift +++ b/Tests/HummingbirdTests/HandlerTests.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import Logging import XCTest @@ -38,7 +38,7 @@ final class HandlerTests: XCTestCase { try await app.test(.router) { client in let body = ByteBufferAllocator().buffer(string: #"{"foo": "bar"}"#) - try await client.XCTExecute( + try await client.execute( uri: "/hello", method: .post, body: body @@ -58,7 +58,7 @@ final class HandlerTests: XCTestCase { try await app.test(.router) { client in let body = ByteBufferAllocator().buffer(string: #"{"value": "bar"}"#) - try await client.XCTExecute( + try await client.execute( uri: "/hello", method: .post, body: body @@ -78,7 +78,7 @@ final class HandlerTests: XCTestCase { try await app.test(.router) { client in let body = ByteBufferAllocator().buffer(string: #"{"value": null}"#) - try await client.XCTExecute( + try await client.execute( uri: "/hello", method: .post, body: body @@ -103,7 +103,7 @@ final class HandlerTests: XCTestCase { try await app.test(.router) { client in let body = ByteBufferAllocator().buffer(string: #"{invalid}"#) - try await client.XCTExecute( + try await client.execute( uri: "/hello", method: .post, body: body @@ -122,7 +122,7 @@ final class HandlerTests: XCTestCase { try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .post, body: ByteBufferAllocator().buffer(string: #"{"value": "Adam"}"#)) { response in + try await client.execute(uri: "/hello", method: .post, body: ByteBufferAllocator().buffer(string: #"{"value": "Adam"}"#)) { response in XCTAssertEqual(String(buffer: response.body), "String: Adam") } } @@ -134,7 +134,7 @@ final class HandlerTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get, body: ByteBufferAllocator().buffer(string: #"{"name2": "Adam"}"#)) { response in + try await client.execute(uri: "/hello", method: .get, body: ByteBufferAllocator().buffer(string: #"{"name2": "Adam"}"#)) { response in XCTAssertEqual(response.status, .badRequest) } } @@ -158,7 +158,7 @@ final class HandlerTests: XCTestCase { try await app.test(.router) { client in - try await client.XCTExecute(uri: "/23", method: .put) { response in + try await client.execute(uri: "/23", method: .put) { response in XCTAssertEqual(String(buffer: response.body), "23") } } diff --git a/Tests/HummingbirdTests/HummingBirdJSONTests.swift b/Tests/HummingbirdTests/HummingBirdJSONTests.swift index e28a73662..d54e2c140 100644 --- a/Tests/HummingbirdTests/HummingBirdJSONTests.swift +++ b/Tests/HummingbirdTests/HummingBirdJSONTests.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import Logging import XCTest @@ -38,7 +38,7 @@ class HummingbirdJSONTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in let body = #"{"name": "John Smith", "email": "john.smith@email.com", "age": 25}"# - try await client.XCTExecute(uri: "/user", method: .put, body: ByteBufferAllocator().buffer(string: body)) { + try await client.execute(uri: "/user", method: .put, body: ByteBufferAllocator().buffer(string: body)) { XCTAssertEqual($0.status, .ok) } } @@ -51,7 +51,7 @@ class HummingbirdJSONTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user", method: .get) { response in + try await client.execute(uri: "/user", method: .get) { response in let user = try JSONDecoder().decode(User.self, from: response.body) XCTAssertEqual(user.name, "John Smith") XCTAssertEqual(user.email, "john.smith@email.com") @@ -67,7 +67,7 @@ class HummingbirdJSONTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/json", method: .get) { response in + try await client.execute(uri: "/json", method: .get) { response in XCTAssertEqual(String(buffer: response.body), #"{"message":"Hello, world!"}"#) } } diff --git a/Tests/HummingbirdTests/MetricsTests.swift b/Tests/HummingbirdTests/MetricsTests.swift index 65d30ac32..93f6ced6d 100644 --- a/Tests/HummingbirdTests/MetricsTests.swift +++ b/Tests/HummingbirdTests/MetricsTests.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import Metrics import NIOConcurrencyHelpers import XCTest @@ -191,7 +191,7 @@ final class MetricsTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { _ in } + try await client.execute(uri: "/hello", method: .get) { _ in } } let counter = try XCTUnwrap(Self.testMetrics.counters["hb_requests"] as? TestCounter) @@ -210,7 +210,7 @@ final class MetricsTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { _ in } + try await client.execute(uri: "/hello", method: .get) { _ in } } let counter = try XCTUnwrap(Self.testMetrics.counters["hb_errors"] as? TestCounter) @@ -230,7 +230,7 @@ final class MetricsTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello2", method: .get) { _ in } + try await client.execute(uri: "/hello2", method: .get) { _ in } } let counter = try XCTUnwrap(Self.testMetrics.counters["hb_errors"] as? TestCounter) @@ -249,7 +249,7 @@ final class MetricsTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user/765", method: .get) { _ in } + try await client.execute(uri: "/user/765", method: .get) { _ in } } let counter = try XCTUnwrap(Self.testMetrics.counters["hb_errors"] as? TestCounter) diff --git a/Tests/HummingbirdTests/MiddlewareTests.swift b/Tests/HummingbirdTests/MiddlewareTests.swift index 2543205db..70c8bedec 100644 --- a/Tests/HummingbirdTests/MiddlewareTests.swift +++ b/Tests/HummingbirdTests/MiddlewareTests.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// @testable import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import XCTest final class MiddlewareTests: XCTestCase { @@ -38,7 +38,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(response.headers[.test], "TestMiddleware") } } @@ -61,7 +61,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in // headers come back in opposite order as middleware is applied to responses in that order XCTAssertEqual(response.headers[values: .test].first, "second") XCTAssertEqual(response.headers[values: .test].last, "first") @@ -85,7 +85,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { _ in + try await client.execute(uri: "/hello", method: .get) { _ in } } } @@ -105,7 +105,7 @@ final class MiddlewareTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get) { response in + try await client.execute(uri: "/hello", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "Edited error") XCTAssertEqual(response.status, .notFound) } @@ -128,7 +128,7 @@ final class MiddlewareTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test", method: .get) { _ in } + try await client.execute(uri: "/test", method: .get) { _ in } } } @@ -164,7 +164,7 @@ final class MiddlewareTests: XCTestCase { try await app.test(.router) { client in let buffer = self.randomBuffer(size: 64000) - try await client.XCTExecute(uri: "/test", method: .get, body: buffer) { response in + try await client.execute(uri: "/test", method: .get, body: buffer) { response in let expectedOutput = ByteBuffer(bytes: buffer.readableBytesView.map { $0 ^ 255 }) XCTAssertEqual(expectedOutput, response.body) } @@ -179,7 +179,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get, headers: [.origin: "foo.com"]) { response in + try await client.execute(uri: "/hello", method: .get, headers: [.origin: "foo.com"]) { response in // headers come back in opposite order as middleware is applied to responses in that order XCTAssertEqual(response.headers[.accessControlAllowOrigin], "foo.com") } @@ -194,7 +194,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .get, headers: [.origin: "foo.com"]) { response in + try await client.execute(uri: "/hello", method: .get, headers: [.origin: "foo.com"]) { response in // headers come back in opposite order as middleware is applied to responses in that order XCTAssertEqual(response.headers[.accessControlAllowOrigin], "*") } @@ -216,7 +216,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .options, headers: [.origin: "foo.com"]) { response in + try await client.execute(uri: "/hello", method: .options, headers: [.origin: "foo.com"]) { response in // headers come back in opposite order as middleware is applied to responses in that order XCTAssertEqual(response.headers[.accessControlAllowOrigin], "*") let headers = response.headers[.accessControlAllowHeaders] // .joined(separator: ", ") @@ -239,7 +239,7 @@ final class MiddlewareTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/hello", method: .put) { _ in + try await client.execute(uri: "/hello", method: .put) { _ in } } } diff --git a/Tests/HummingbirdTests/PersistTests.swift b/Tests/HummingbirdTests/PersistTests.swift index 7253e8f5c..53079904c 100644 --- a/Tests/HummingbirdTests/PersistTests.swift +++ b/Tests/HummingbirdTests/PersistTests.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import XCTest final class PersistTests: XCTestCase { @@ -53,8 +53,8 @@ final class PersistTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in let tag = UUID().uuidString - try await client.XCTExecute(uri: "/persist/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { _ in } - try await client.XCTExecute(uri: "/persist/\(tag)", method: .get) { response in + try await client.execute(uri: "/persist/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { _ in } + try await client.execute(uri: "/persist/\(tag)", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "Persist") } } @@ -72,8 +72,8 @@ final class PersistTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in let tag = UUID().uuidString - try await client.XCTExecute(uri: "/create/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { _ in } - try await client.XCTExecute(uri: "/persist/\(tag)", method: .get) { response in + try await client.execute(uri: "/create/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { _ in } + try await client.execute(uri: "/persist/\(tag)", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "Persist") } } @@ -94,10 +94,10 @@ final class PersistTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in let tag = UUID().uuidString - try await client.XCTExecute(uri: "/create/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { response in + try await client.execute(uri: "/create/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { response in XCTAssertEqual(response.status, .ok) } - try await client.XCTExecute(uri: "/create/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { response in + try await client.execute(uri: "/create/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { response in XCTAssertEqual(response.status, .conflict) } } @@ -109,11 +109,11 @@ final class PersistTests: XCTestCase { try await app.test(.router) { client in let tag = UUID().uuidString - try await client.XCTExecute(uri: "/persist/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "test1")) { _ in } - try await client.XCTExecute(uri: "/persist/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "test2")) { response in + try await client.execute(uri: "/persist/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "test1")) { _ in } + try await client.execute(uri: "/persist/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "test2")) { response in XCTAssertEqual(response.status, .ok) } - try await client.XCTExecute(uri: "/persist/\(tag)", method: .get) { response in + try await client.execute(uri: "/persist/\(tag)", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "test2") } } @@ -127,13 +127,13 @@ final class PersistTests: XCTestCase { let tag1 = UUID().uuidString let tag2 = UUID().uuidString - try await client.XCTExecute(uri: "/persist/\(tag1)/0", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest1")) { _ in } - try await client.XCTExecute(uri: "/persist/\(tag2)/10", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest2")) { _ in } + try await client.execute(uri: "/persist/\(tag1)/0", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest1")) { _ in } + try await client.execute(uri: "/persist/\(tag2)/10", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest2")) { _ in } try await Task.sleep(nanoseconds: 1_000_000_000) - try await client.XCTExecute(uri: "/persist/\(tag1)", method: .get) { response in + try await client.execute(uri: "/persist/\(tag1)", method: .get) { response in XCTAssertEqual(response.status, .noContent) } - try await client.XCTExecute(uri: "/persist/\(tag2)", method: .get) { response in + try await client.execute(uri: "/persist/\(tag2)", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "ThisIsTest2") } } @@ -164,8 +164,8 @@ final class PersistTests: XCTestCase { try await app.test(.router) { client in let tag = UUID().uuidString - try await client.XCTExecute(uri: "/codable/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { _ in } - try await client.XCTExecute(uri: "/codable/\(tag)", method: .get) { response in + try await client.execute(uri: "/codable/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "Persist")) { _ in } + try await client.execute(uri: "/codable/\(tag)", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "Persist") } } @@ -176,9 +176,9 @@ final class PersistTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in let tag = UUID().uuidString - try await client.XCTExecute(uri: "/persist/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest1")) { _ in } - try await client.XCTExecute(uri: "/persist/\(tag)", method: .delete) { _ in } - try await client.XCTExecute(uri: "/persist/\(tag)", method: .get) { response in + try await client.execute(uri: "/persist/\(tag)", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest1")) { _ in } + try await client.execute(uri: "/persist/\(tag)", method: .delete) { _ in } + try await client.execute(uri: "/persist/\(tag)", method: .get) { response in XCTAssertEqual(response.status, .noContent) } } @@ -190,15 +190,15 @@ final class PersistTests: XCTestCase { try await app.test(.router) { client in let tag = UUID().uuidString - try await client.XCTExecute(uri: "/persist/\(tag)/0", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest1")) { _ in } + try await client.execute(uri: "/persist/\(tag)/0", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest1")) { _ in } try await Task.sleep(nanoseconds: 1_000_000_000) - try await client.XCTExecute(uri: "/persist/\(tag)", method: .get) { response in + try await client.execute(uri: "/persist/\(tag)", method: .get) { response in XCTAssertEqual(response.status, .noContent) } - try await client.XCTExecute(uri: "/persist/\(tag)/10", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest1")) { response in + try await client.execute(uri: "/persist/\(tag)/10", method: .put, body: ByteBufferAllocator().buffer(string: "ThisIsTest1")) { response in XCTAssertEqual(response.status, .ok) } - try await client.XCTExecute(uri: "/persist/\(tag)", method: .get) { response in + try await client.execute(uri: "/persist/\(tag)", method: .get) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: response.body), "ThisIsTest1") } diff --git a/Tests/HummingbirdTests/RouterTests.swift b/Tests/HummingbirdTests/RouterTests.swift index 577bba253..3b1e0b07b 100644 --- a/Tests/HummingbirdTests/RouterTests.swift +++ b/Tests/HummingbirdTests/RouterTests.swift @@ -14,7 +14,7 @@ import Atomics @testable import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import Logging import NIOCore import Tracing @@ -50,7 +50,7 @@ final class RouterTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test/1", method: .get) { response in + try await client.execute(uri: "/test/1", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/test/:number") } } @@ -79,13 +79,13 @@ final class RouterTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/") } - try await client.XCTExecute(uri: "/test/", method: .get) { response in + try await client.execute(uri: "/test/", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/test") } - try await client.XCTExecute(uri: "/test2/", method: .post) { response in + try await client.execute(uri: "/test2/", method: .post) { response in XCTAssertEqual(String(buffer: response.body), "/test2") } } @@ -120,19 +120,19 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test/", method: .get) { response in + try await client.execute(uri: "/test/", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/test") } - try await client.XCTExecute(uri: "/test2/", method: .post) { response in + try await client.execute(uri: "/test2/", method: .post) { response in XCTAssertEqual(String(buffer: response.body), "/test2") } - try await client.XCTExecute(uri: "/testGroup/", method: .get) { response in + try await client.execute(uri: "/testGroup/", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/testGroup") } - try await client.XCTExecute(uri: "/testGroup2", method: .get) { response in + try await client.execute(uri: "/testGroup2", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "/testGroup2") } } @@ -151,11 +151,11 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/endpoint", method: .get) { response in + try await client.execute(uri: "/endpoint", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "GET") } - try await client.XCTExecute(uri: "/endpoint", method: .put) { response in + try await client.execute(uri: "/endpoint", method: .put) { response in XCTAssertEqual(String(buffer: response.body), "PUT") } } @@ -176,11 +176,11 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/group", method: .get) { response in + try await client.execute(uri: "/group", method: .get) { response in XCTAssertEqual(response.headers[.test], "TestMiddleware") } - try await client.XCTExecute(uri: "/not-group", method: .get) { response in + try await client.execute(uri: "/not-group", method: .get) { response in XCTAssertEqual(response.headers[.test], nil) } } @@ -196,7 +196,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/group", method: .head) { response in + try await client.execute(uri: "/group", method: .head) { response in XCTAssertEqual(response.headers[.test], "TestMiddleware") } } @@ -214,7 +214,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test/group", method: .get) { response in + try await client.execute(uri: "/test/group", method: .get) { response in XCTAssertEqual(response.headers[.test], "TestMiddleware") } } @@ -246,10 +246,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/test/group", method: .get) { response in + try await client.execute(uri: "/test/group", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "route2") } - try await client.XCTExecute(uri: "/test", method: .get) { response in + try await client.execute(uri: "/test", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "route1") } } @@ -263,7 +263,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user/1234", method: .delete) { response in + try await client.execute(uri: "/user/1234", method: .delete) { response in XCTAssertEqual(String(buffer: response.body), "1234") } } @@ -278,10 +278,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user/1234", method: .delete) { response in + try await client.execute(uri: "/user/1234", method: .delete) { response in XCTAssertEqual(String(buffer: response.body), "1235") } - try await client.XCTExecute(uri: "/user/what", method: .delete) { response in + try await client.execute(uri: "/user/what", method: .delete) { response in XCTAssertEqual(response.status, .badRequest) } } @@ -299,10 +299,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user/this", method: .delete) { response in + try await client.execute(uri: "/user/this", method: .delete) { response in XCTAssertEqual(String(buffer: response.body), "this") } - try await client.XCTExecute(uri: "/user/what", method: .delete) { response in + try await client.execute(uri: "/user/what", method: .delete) { response in XCTAssertEqual(response.status, .badRequest) } } @@ -317,7 +317,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user/john/1234", method: .delete) { response in + try await client.execute(uri: "/user/john/1234", method: .delete) { response in XCTAssertEqual(String(buffer: response.body), "1234") } } @@ -334,7 +334,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/files/file.doc/test.jpg", method: .get) { response in + try await client.execute(uri: "/files/file.doc/test.jpg", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "test.doc") } } @@ -348,10 +348,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/files/file.doc/test.jpg", method: .get) { response in + try await client.execute(uri: "/files/file.doc/test.jpg", method: .get) { response in XCTAssertEqual(response.status, .ok) } - try await client.XCTExecute(uri: "/files/file.doc/test.png", method: .get) { response in + try await client.execute(uri: "/files/file.doc/test.png", method: .get) { response in XCTAssertEqual(response.status, .notFound) } } @@ -366,10 +366,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user/?id=24&id=56", method: .get) { response in + try await client.execute(uri: "/user/?id=24&id=56", method: .get) { response in XCTAssertEqual(String(buffer: response.body), "[25,57]") } - try await client.XCTExecute(uri: "/user/?id=24&id=hello", method: .get) { response in + try await client.execute(uri: "/user/?id=24&id=hello", method: .get) { response in XCTAssertEqual(response.status, .badRequest) } } @@ -389,10 +389,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user/?id=this&id=and&id=that", method: .patch) { response in + try await client.execute(uri: "/user/?id=this&id=and&id=that", method: .patch) { response in XCTAssertEqual(String(buffer: response.body), "[\"this\",\"and\",\"that\"]") } - try await client.XCTExecute(uri: "/user/?id=this&id=hello", method: .patch) { response in + try await client.execute(uri: "/user/?id=this&id=hello", method: .patch) { response in XCTAssertEqual(response.status, .badRequest) } } @@ -406,10 +406,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - let id = try await client.XCTExecute(uri: "/id", method: .get) { response -> String in + let id = try await client.execute(uri: "/id", method: .get) { response -> String in return String(buffer: response.body) } - try await client.XCTExecute(uri: "/id", method: .get) { response in + try await client.execute(uri: "/id", method: .get) { response in let id2 = String(buffer: response.body) XCTAssertNotEqual(id, id2) } @@ -424,7 +424,7 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/redirect", method: .get) { response in + try await client.execute(uri: "/redirect", method: .get) { response in XCTAssertEqual(response.headers[.location], "/other") XCTAssertEqual(response.status, .seeOther) } @@ -442,10 +442,10 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/uppercased", method: .get) { response in + try await client.execute(uri: "/uppercased", method: .get) { response in XCTAssertEqual(response.status, .ok) } - try await client.XCTExecute(uri: "/LOWERCASED", method: .get) { response in + try await client.execute(uri: "/LOWERCASED", method: .get) { response in XCTAssertEqual(response.status, .ok) } } @@ -468,15 +468,15 @@ final class RouterTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/nohead", method: .head) { response in + try await client.execute(uri: "/nohead", method: .head) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(response.headers[.contentLength], "10") } - try await client.XCTExecute(uri: "/withhead", method: .head) { response in + try await client.execute(uri: "/withhead", method: .head) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(response.headers[.contentLanguage], "en") } - try await client.XCTExecute(uri: "/post", method: .head) { response in + try await client.execute(uri: "/post", method: .head) { response in XCTAssertEqual(response.status, .notFound) } } diff --git a/Tests/HummingbirdTests/TracingTests.swift b/Tests/HummingbirdTests/TracingTests.swift index b5c672101..33ea5d679 100644 --- a/Tests/HummingbirdTests/TracingTests.swift +++ b/Tests/HummingbirdTests/TracingTests.swift @@ -14,7 +14,7 @@ import HTTPTypes import Hummingbird -import HummingbirdXCT +import HummingbirdTesting @testable import Instrumentation import Tracing import XCTest @@ -42,7 +42,7 @@ final class TracingTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/users/42", method: .get) { response in + try await client.execute(uri: "/users/42", method: .get) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: response.body), "42") } @@ -81,7 +81,7 @@ final class TracingTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/users", method: .post, headers: [.contentLength: "2"], body: ByteBuffer(string: "42")) { response in + try await client.execute(uri: "/users", method: .post, headers: [.contentLength: "2"], body: ByteBuffer(string: "42")) { response in XCTAssertEqual(response.status, .internalServerError) } } @@ -132,7 +132,7 @@ final class TracingTests: XCTestCase { var requestHeaders = HTTPFields() requestHeaders[values: .accept] = ["text/plain", "application/json"] requestHeaders[.cacheControl] = "no-cache" - try await client.XCTExecute(uri: "/users/42", method: .get, headers: requestHeaders) { response in + try await client.execute(uri: "/users/42", method: .get, headers: requestHeaders) { response in XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: response.body), "42") } @@ -173,7 +173,7 @@ final class TracingTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/users", method: .post) { response in + try await client.execute(uri: "/users", method: .post) { response in XCTAssertEqual(response.status, .noContent) } } @@ -209,7 +209,7 @@ final class TracingTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .ok) } } @@ -242,7 +242,7 @@ final class TracingTests: XCTestCase { router.middlewares.add(HBTracingMiddleware()) let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .notFound) } } @@ -285,7 +285,7 @@ final class TracingTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .ok) } } @@ -320,7 +320,7 @@ final class TracingTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .ok) } } @@ -368,7 +368,7 @@ final class TracingTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .ok) } } @@ -405,7 +405,7 @@ extension TracingTests { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/", method: .get) { response in + try await client.execute(uri: "/", method: .get) { response in XCTAssertEqual(response.status, .ok) } } diff --git a/Tests/HummingbirdTests/URLEncodedForm/Application+URLEncodedFormTests.swift b/Tests/HummingbirdTests/URLEncodedForm/Application+URLEncodedFormTests.swift index bc64c7230..03eaca844 100644 --- a/Tests/HummingbirdTests/URLEncodedForm/Application+URLEncodedFormTests.swift +++ b/Tests/HummingbirdTests/URLEncodedForm/Application+URLEncodedFormTests.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// import Hummingbird -import HummingbirdXCT +import HummingbirdTesting import Logging import NIOCore import XCTest @@ -50,7 +50,7 @@ class HummingBirdURLEncodedTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in let body = "name=John%20Smith&email=john.smith%40email.com&age=25" - try await client.XCTExecute(uri: "/user", method: .put, body: ByteBufferAllocator().buffer(string: body)) { + try await client.execute(uri: "/user", method: .put, body: ByteBufferAllocator().buffer(string: body)) { XCTAssertEqual($0.status, .ok) } } @@ -63,7 +63,7 @@ class HummingBirdURLEncodedTests: XCTestCase { } let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in - try await client.XCTExecute(uri: "/user", method: .get) { response in + try await client.execute(uri: "/user", method: .get) { response in let user = try URLEncodedFormDecoder().decode(User.self, from: String(buffer: response.body)) XCTAssertEqual(user.name, "John Smith") XCTAssertEqual(user.email, "john.smith@email.com") diff --git a/Tests/HummingbirdTests/UUIDTests.swift b/Tests/HummingbirdTests/UUIDTests.swift index dbff72274..92ac797ab 100644 --- a/Tests/HummingbirdTests/UUIDTests.swift +++ b/Tests/HummingbirdTests/UUIDTests.swift @@ -25,7 +25,7 @@ final class UUIDTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in let uuid = UUID() - try await client.XCTExecute(uri: "\(uuid)", method: .get) { response in + try await client.execute(uri: "\(uuid)", method: .get) { response in let body = try XCTUnwrap(response.body) XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: body), "\"\(uuid.uuidString)\"") @@ -41,7 +41,7 @@ final class UUIDTests: XCTestCase { let app = HBApplication(responder: router.buildResponder()) try await app.test(.router) { client in let uuid = UUID() - try await client.XCTExecute(uri: "\(uuid)", method: .get) { response in + try await client.execute(uri: "\(uuid)", method: .get) { response in let body = try XCTUnwrap(response.body) XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: body), "\"\(uuid.uuidString)\"") @@ -59,7 +59,7 @@ final class UUIDTests: XCTestCase { try await app.test(.router) { client in let uuid = UUID() let uuid2 = UUID() - try await client.XCTExecute(uri: "/?id=\(uuid)&id=\(uuid2)&id=Wrong", method: .get) { response in + try await client.execute(uri: "/?id=\(uuid)&id=\(uuid2)&id=Wrong", method: .get) { response in let body = try XCTUnwrap(response.body) XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: body), "[\"\(uuid.uuidString)\",\"\(uuid2.uuidString)\"]") @@ -78,13 +78,13 @@ final class UUIDTests: XCTestCase { let uuid = UUID() let uuid2 = UUID() // test good request - try await client.XCTExecute(uri: "/?id=\(uuid)&id=\(uuid2)", method: .get) { response in + try await client.execute(uri: "/?id=\(uuid)&id=\(uuid2)", method: .get) { response in let body = try XCTUnwrap(response.body) XCTAssertEqual(response.status, .ok) XCTAssertEqual(String(buffer: body), "[\"\(uuid.uuidString)\",\"\(uuid2.uuidString)\"]") } // test bad request - try await client.XCTExecute(uri: "/?id=\(uuid)&id=\(uuid2)&id=Wrong", method: .get) { response in + try await client.execute(uri: "/?id=\(uuid)&id=\(uuid2)&id=Wrong", method: .get) { response in XCTAssertEqual(response.status, .badRequest) } }