Skip to content

Commit

Permalink
Remove XCT from all symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Mar 5, 2024
1 parent f9d4336 commit cb2b286
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Benchmarks/Benchmarks/Router/RouterBenchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Value>(
_ 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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand All @@ -53,17 +53,17 @@ struct HBXCTError: Error, Equatable {
}

/// Protocol for client used by HummingbirdTesting
public protocol HBXCTClientProtocol: Sendable {
public protocol HBTestClientProtocol: Sendable {
/// Execute URL request and provide response
func execute(
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:
Expand All @@ -78,18 +78,18 @@ extension HBXCTClientProtocol {
method: HTTPRequest.Method,
headers: HTTPFields = [:],
body: ByteBuffer? = nil,
testCallback: @escaping (HBXCTResponse) async throws -> Return = { $0 }
testCallback: @escaping (HBTestResponse) async throws -> Return = { $0 }

Check warning on line 81 in Sources/HummingbirdTesting/ApplicationTester.swift

View check run for this annotation

Codecov / codecov/patch

Sources/HummingbirdTesting/ApplicationTester.swift#L81

Added line #L81 was not covered by tests
) async throws -> Return {
let response = try await execute(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<Value>(_ test: @escaping @Sendable (any HBXCTClientProtocol) async throws -> Value) async throws -> Value
/// Run test server
func run<Value>(_ test: @escaping @Sendable (any HBTestClientProtocol) async throws -> Value) async throws -> Value
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import ServiceLifecycle
import XCTest

/// Test using a live server and AsyncHTTPClient as a client
final class HBXCTAsyncHTTPClient<App: HBApplicationProtocol>: HBXCTApplication {
struct Client: HBXCTClientProtocol {
final class HBAsyncHTTPClientTestFramework<App: HBApplicationProtocol>: HBApplicationTestFramework {
struct Client: HBTestClientProtocol {
let client: HTTPClient
let urlPrefix: String
let timeout: TimeAmount
Expand All @@ -37,7 +37,7 @@ final class HBXCTAsyncHTTPClient<App: HBApplicationProtocol>: HBXCTApplication {
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)
Expand All @@ -49,14 +49,14 @@ final class HBXCTAsyncHTTPClient<App: HBApplicationProtocol>: 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<Value>(_ test: @escaping @Sendable (HBXCTClientProtocol) async throws -> Value) async throws -> Value {
func run<Value>(_ test: @escaping @Sendable (HBTestClientProtocol) async throws -> Value) async throws -> Value {
try await withThrowingTaskGroup(of: Void.self) { group in
let serviceGroup = ServiceGroup(
configuration: .init(
Expand Down Expand Up @@ -90,7 +90,7 @@ final class HBXCTAsyncHTTPClient<App: HBApplicationProtocol>: HBXCTApplication {
}

let application: TestApplication<App>
let scheme: XCTScheme
let scheme: HBTestHTTPScheme
let timeout: TimeAmount
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ import ServiceLifecycle
import XCTest

/// Test using a live server
final class HBXCTLive<App: HBApplicationProtocol>: HBXCTApplication {
struct Client: HBXCTClientProtocol {
let client: HBXCTClient
final class HBLiveTestFramework<App: HBApplicationProtocol>: HBApplicationTestFramework {
struct Client: HBTestClientProtocol {
let client: HBTestClient

/// Send request and call test callback on the response returned
func execute(
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)
}
Expand All @@ -48,7 +48,7 @@ final class HBXCTLive<App: HBApplicationProtocol>: HBXCTApplication {
}

/// Start tests
func run<Value>(_ test: @escaping @Sendable (HBXCTClientProtocol) async throws -> Value) async throws -> Value {
func run<Value>(_ test: @escaping @Sendable (HBTestClientProtocol) async throws -> Value) async throws -> Value {
try await withThrowingTaskGroup(of: Void.self) { group in
let serviceGroup = ServiceGroup(
configuration: .init(
Expand All @@ -61,7 +61,7 @@ final class HBXCTLive<App: HBApplicationProtocol>: 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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +25,7 @@ import NIOPosix
import ServiceLifecycle

/// Test sending requests directly to router. This does not setup a live server
struct HBXCTRouter<Responder: HBResponder>: HBXCTApplication where Responder.Context: HBBaseRequestContext {
struct HBRouterTestFramework<Responder: HBResponder>: HBApplicationTestFramework where Responder.Context: HBBaseRequestContext {
let responder: Responder
let makeContext: @Sendable (Logger) -> Responder.Context
let services: [any Service]
Expand All @@ -46,7 +46,7 @@ struct HBXCTRouter<Responder: HBResponder>: HBXCTApplication where Responder.Con
}

/// Run test
func run<Value>(_ test: @escaping @Sendable (HBXCTClientProtocol) async throws -> Value) async throws -> Value {
func run<Value>(_ test: @escaping @Sendable (HBTestClientProtocol) async throws -> Value) async throws -> Value {
let client = Client(
responder: self.responder,
logger: self.logger,
Expand Down Expand Up @@ -88,15 +88,15 @@ struct HBXCTRouter<Responder: HBResponder>: 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 execute(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),
Expand All @@ -118,7 +118,7 @@ struct HBXCTRouter<Responder: HBResponder>: 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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/HummingbirdTesting/TestApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ServiceLifecycle
/// TestApplication used to wrap HBApplication being tested.
///
/// This is needed to override the `onServerRunning` function
struct TestApplication<BaseApp: HBApplicationProtocol>: HBApplicationProtocol, Service {
internal struct TestApplication<BaseApp: HBApplicationProtocol>: HBApplicationProtocol, Service {
typealias Responder = BaseApp.Responder
typealias ChildChannel = BaseApp.ChildChannel

Expand Down
2 changes: 1 addition & 1 deletion Sources/HummingbirdTesting/XCTClient+types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import HTTPTypes
import NIOCore

/// HTTP client types
extension HBXCTClient {
extension HBTestClient {
public enum Error: Swift.Error {
case invalidURL
case malformedResponse
Expand Down
Loading

0 comments on commit cb2b286

Please sign in to comment.