Skip to content

Commit

Permalink
Add optional port to TestClientProtocol (#427)
Browse files Browse the repository at this point in the history
* Add optional port to TestClientProtocol

* Project template update
  • Loading branch information
adam-fowler authored Apr 29, 2024
1 parent ce5d492 commit e5fbcd9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/api-breakage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
container:
image: swift:5.9
image: swift:5.10
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
image: ["swift:5.9", "swift:5.10", "swiftlang/swift:nightly-jammy"]
image: ["swift:5.9", "swift:5.10", "swiftlang/swift:nightly-6.0-jammy"]

container:
image: ${{ matrix.image }}
Expand Down
2 changes: 2 additions & 0 deletions Sources/HummingbirdTesting/ApplicationTester.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public protocol TestClientProtocol: Sendable {
headers: HTTPFields,
body: ByteBuffer?
) async throws -> TestResponse
// Port to connect to if test client is connecting to a live server
var port: Int? { get }
}

extension TestClientProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class AsyncHTTPClientTestFramework<App: ApplicationProtocol>: ApplicationT
struct Client: TestClientProtocol {
let client: HTTPClient
let urlPrefix: String
let port: Int?
let timeout: TimeAmount

/// Send request and call test callback on the response returned
Expand Down Expand Up @@ -75,7 +76,7 @@ final class AsyncHTTPClientTestFramework<App: ApplicationProtocol>: ApplicationT
eventLoopGroupProvider: .singleton,
configuration: .init(tlsConfiguration: tlsConfiguration)
)
let client = Client(client: httpClient, urlPrefix: "\(self.scheme)://localhost:\(port)", timeout: self.timeout)
let client = Client(client: httpClient, urlPrefix: "\(self.scheme)://localhost:\(port)", port: port, timeout: self.timeout)
do {
let value = try await test(client)
await serviceGroup.triggerGracefulShutdown()
Expand Down
2 changes: 2 additions & 0 deletions Sources/HummingbirdTesting/LiveTestFramework.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ final class LiveTestFramework<App: ApplicationProtocol>: ApplicationTestFramewor
let response = try await client.execute(request)
return .init(head: response.head, body: response.body ?? ByteBuffer(), trailerHeaders: response.trailerHeaders)
}

var port: Int? { self.client.port }
}

init(app: App) {
Expand Down
2 changes: 2 additions & 0 deletions Sources/HummingbirdTesting/RouterTestFramework.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ struct RouterTestFramework<Responder: HTTPResponder>: ApplicationTestFramework w
return try await group.next()!
}
}

var port: Int? { nil }
}

final class RouterResponseWriter: ResponseBodyWriter {
Expand Down

0 comments on commit e5fbcd9

Please sign in to comment.