Skip to content

Commit

Permalink
Add a new method to XCTApplicationTester that tests and returns an XC…
Browse files Browse the repository at this point in the history
…THTTPResponse directly
  • Loading branch information
tonyarnold committed Nov 1, 2021
1 parent 1c4d362 commit ab43bc3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Sources/XCTVapor/XCTApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,28 @@ extension XCTApplicationTester {
}
return self
}

public func performTest(
_ method: HTTPMethod,
_ path: String,
headers: HTTPHeaders = [:],
body: ByteBuffer? = nil,
file: StaticString = #file,
line: UInt = #line,
beforeRequest: (inout XCTHTTPRequest) throws -> () = { _ in }
) throws -> XCTHTTPResponse {
var request = XCTHTTPRequest(
method: method,
url: .init(path: path),
headers: headers,
body: body ?? ByteBufferAllocator().buffer(capacity: 0)
)
try beforeRequest(&request)
do {
return try self.performTest(request: request)
} catch {
XCTFail("\(error)", file: (file), line: line)
throw error
}
}
}

0 comments on commit ab43bc3

Please sign in to comment.