Remove EmbeddedChannel restriction to IOData (#763)

Remove EmbeddedChannel restriction to IOData

Motivation:

You should be able to read any type from the outbound buffer.

Modifications:

Change Embedded channel outboundBuffer and pendingOutboundBuffer to store NIOAny instead of IOData and refactor test code accordingly.

Result:

- Users can test what went through the pipeline without serializing everything and using "if case let" syntax everywhere.
- fixes #551
This commit is contained in:
JovanMilenkovic authored and Johannes Weiss committed 2019-01-30 19:24:59 +00:00
1 parent 70c714a54d
commit cf56bfd119
15 files changed
+89 -123

No files matched your search

@@ -33,7 +33,7 @@ class HTTPResponseEncoderTests: XCTestCase {
var switchingResponse = HTTPResponseHead(version: HTTPVersion(major: 1, minor:1), status: status)
switchingResponse.headers = headers
XCTAssertNoThrow(try channel.writeOutbound(HTTPServerResponsePart.head(switchingResponse)))
if case .some(.byteBuffer(let buffer)) = channel.readOutbound() {
if let buffer = channel.readOutbound(as: ByteBuffer.self) {
return buffer
} else {
fatalError("Could not read ByteBuffer from channel")
@@ -103,14 +103,11 @@ class HTTPResponseEncoderTests: XCTestCase {
// This response contains neither Transfer-Encoding: chunked or Content-Length.
let response = HTTPResponseHead(version: HTTPVersion(major: 1, minor:0), status: .ok)
XCTAssertNoThrow(try channel.writeOutbound(HTTPServerResponsePart.head(response)))
let writtenData: IOData = channel.readOutbound()!
switch writtenData {
case .byteBuffer(let b):
let writtenResponse = b.getString(at: b.readerIndex, length: b.readableBytes)!
XCTAssertEqual(writtenResponse, "HTTP/1.0 200 OK\r\n\r\n")
case .fileRegion:
XCTFail("Unexpected file region")
guard let b = channel.readOutbound(as: ByteBuffer.self) else {
XCTFail("Could not read byte buffer")
return
}
let writtenResponse = b.getString(at: b.readerIndex, length: b.readableBytes)!
XCTAssertEqual(writtenResponse, "HTTP/1.0 200 OK\r\n\r\n")
}
}