Skip to content

Commit

Permalink
NIOAsyncChannelInboundStream.makeTesting in RouterTestFramework (humm…
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler authored and bcbod2002 committed Feb 6, 2025
1 parent 81ef0c2 commit f395f9a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Sources/HummingbirdTesting/RouterTestFramework.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ struct RouterTestFramework<Responder: HTTPResponder>: ApplicationTestFramework w
if let contentLength = body.map(\.readableBytes) {
headers[.contentLength] = String(describing: contentLength)
}
let (stream, source) = RequestBody.makeStream()
let (stream, source) = NIOAsyncChannelInboundStream<HTTPRequestPart>.makeTestingStream()
let iterator = stream.makeAsyncIterator()
let requestBody = NIOAsyncChannelRequestBody(iterator: iterator)

//let (stream, source) = RequestBody.makeStream()
let request = Request(
head: .init(method: method, scheme: "http", authority: "localhost", path: uri, headerFields: headers),
body: stream
body: RequestBody(nioAsyncChannelInbound: requestBody)
)
let logger = self.logger.with(metadataKey: "hb.request.id", value: .stringConvertible(RequestID()))
let context = self.makeContext(logger)
Expand All @@ -129,10 +133,13 @@ struct RouterTestFramework<Responder: HTTPResponder>: ApplicationTestFramework w
while body.readableBytes > 0 {
let chunkSize = min(32 * 1024, body.readableBytes)
let buffer = body.readSlice(length: chunkSize)!
try await source.yield(buffer)
source.yield(.body(buffer))
}
}
source.finish()
source.yield(.end(nil))
defer {
source.finish()
}
return try await group.next()!
}
}
Expand Down

0 comments on commit f395f9a

Please sign in to comment.