prepare tests for throwing readIn/Outbound (#861)

Motivation:

readInbound/Outbound will soon throw errors if the type isn't right.

Modifications:

prepare tests for throwing readIn/Outbound

Result:

@ianpartridge's PR should pretty much merge after this.
This commit is contained in:
Johannes Weiss authored and Cory Benfield committed 2019-03-04 09:40:59 +00:00
1 parent 49659664c2
commit a1981eb0fd
16 files changed
+328 -288

No files matched your search

@@ -33,7 +33,7 @@ class HTTPRequestEncoderTests: XCTestCase {
var request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:1), method: method, uri: "/uri")
request.headers = headers
try channel.writeOutbound(HTTPClientRequestPart.head(request))
if let buffer = channel.readOutbound(as: ByteBuffer.self) {
if let buffer = try channel.readOutbound(as: ByteBuffer.self) {
return buffer
} else {
fatalError("Could not read ByteBuffer from channel")
@@ -83,7 +83,7 @@ class HTTPRequestEncoderTests: XCTestCase {
// This request contains neither Transfer-Encoding: chunked or Content-Length.
let request = HTTPRequestHead(version: HTTPVersion(major: 1, minor:0), method: .GET, uri: "/uri")
XCTAssertNoThrow(try channel.writeOutbound(HTTPClientRequestPart.head(request)))
let writtenData = channel.readOutbound(as: ByteBuffer.self)!
let writtenData = try channel.readOutbound(as: ByteBuffer.self)!
let writtenResponse = writtenData.getString(at: writtenData.readerIndex, length: writtenData.readableBytes)!
XCTAssertEqual(writtenResponse, "GET /uri HTTP/1.0\r\n\r\n")
}
@@ -129,10 +129,14 @@ class HTTPRequestEncoderTests: XCTestCase {
}
private func assertOutboundContainsOnly(_ channel: EmbeddedChannel, _ expected: String) {
if let buffer = channel.readOutbound(as: ByteBuffer.self) {
buffer.assertContainsOnly(expected)
} else {
fatalError("Could not read ByteBuffer from channel")
do {
if let buffer = try channel.readOutbound(as: ByteBuffer.self) {
buffer.assertContainsOnly(expected)
} else {
fatalError("Could not read ByteBuffer from channel")
}
} catch {
XCTFail("unexpected error: \(error)")
}
}
}