Skip to content

Commit

Permalink
New response expectation
Browse files Browse the repository at this point in the history
  • Loading branch information
tib committed Dec 14, 2020
1 parent fcdb546 commit 74ec16a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
44 changes: 22 additions & 22 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
"repositoryURL": "https://github.com/swift-server/async-http-client.git",
"state": {
"branch": null,
"revision": "4b4d6605aa2e4f0c2ae3c7563795ae3bec259fff",
"version": "1.2.1"
"revision": "0a8dddbe15cd72f7bb5e47951fb7c1eb0836dfc2",
"version": "1.2.2"
}
},
{
"package": "async-kit",
"repositoryURL": "https://github.com/vapor/async-kit.git",
"state": {
"branch": null,
"revision": "7457413e57dbfac762b32dd30c1caf2c55a02a3d",
"version": "1.2.0"
"revision": "5760c79afb8ebc24fd3251fdd9724af225fdf1f9",
"version": "1.3.0"
}
},
{
"package": "console-kit",
"repositoryURL": "https://github.com/vapor/console-kit.git",
"state": {
"branch": null,
"revision": "7cf8185ad62d50ae9777ce78bcfde8f5c9f900e2",
"version": "4.2.1"
"revision": "7454e839bc5ae0e75c3946d2613e442fd342fe6b",
"version": "4.2.4"
}
},
{
Expand All @@ -51,8 +51,8 @@
"repositoryURL": "https://github.com/apple/swift-crypto.git",
"state": {
"branch": null,
"revision": "3c632a678e06ef15d6c9d93f7176dfb1de9e0696",
"version": "1.1.1"
"revision": "9680b7251cd2be22caaed8f1468bd9e8915a62fb",
"version": "1.1.2"
}
},
{
Expand All @@ -69,17 +69,17 @@
"repositoryURL": "https://github.com/apple/swift-metrics.git",
"state": {
"branch": null,
"revision": "708b960b4605abb20bc55d65abf6bad607252200",
"version": "2.0.0"
"revision": "e382458581b05839a571c578e90060fff499f101",
"version": "2.1.1"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "c3e2359c55cd8b47207ab7363b77c9c398a95294",
"version": "2.23.0"
"revision": "2bae395344d41710dffab456265d534d7dc34ab8",
"version": "2.25.0"
}
},
{
Expand All @@ -96,44 +96,44 @@
"repositoryURL": "https://github.com/apple/swift-nio-http2.git",
"state": {
"branch": null,
"revision": "78ddbdfca10f64e4399da37c63372fd8db232152",
"version": "1.15.0"
"revision": "d4060ac4d056a48d946298f04968f6f6080cc618",
"version": "1.16.2"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "cc0e80dbccf8c89c1f49c3a11c5929575035076c",
"version": "2.9.2"
"revision": "901a01423316c4ce672b1b58ce62aecb8069cb1f",
"version": "2.10.1"
}
},
{
"package": "swift-nio-transport-services",
"repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
"state": {
"branch": null,
"revision": "bb56586c4cab9a79dce6ec4738baddb5802c5de7",
"version": "1.9.0"
"revision": "5a352330c09a323e59ebd99afdf4ca3964c217bc",
"version": "1.9.1"
}
},
{
"package": "vapor",
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "fbf36940c29c90f9f6f66105c3e14bf892243dbc",
"version": "4.30.0"
"revision": "5148f02e42149f73f6616452062cf96b64afbda6",
"version": "4.36.2"
}
},
{
"package": "websocket-kit",
"repositoryURL": "https://github.com/vapor/websocket-kit.git",
"state": {
"branch": null,
"revision": "b0736014be634475dac4c23843811257d86dcdc1",
"version": "2.1.1"
"revision": "2b06a70dfcfa76a2e5079f60e3ae911511f09db0",
"version": "2.1.2"
}
}
]
Expand Down
9 changes: 9 additions & 0 deletions Sources/Spec/Spec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public final class Spec {
self.headers.replaceOrAdd(name: name, value: value)
return self
}

///set a buffer as the request body
public func buffer(_ buffer: ByteBuffer) -> Self {
self.buffer = buffer
Expand Down Expand Up @@ -103,6 +104,14 @@ public final class Spec {
return self
}

/// expect a byte buffer as a response
public func expect(file: StaticString = #file, line: UInt = #line, closure: @escaping ((XCTHTTPResponse) throws -> ()) = { _ in }) -> Self {
self.expectations.append({ res in
try closure(res)
})
return self
}

///test the given spec using a test method (in memory or via a running server), default is in memory
public func test(_ method: Application.Method = .inMemory, file: StaticString = #file, line: UInt = #line) throws {
let afterRequest: (XCTHTTPResponse) throws -> () = { res in
Expand Down
21 changes: 14 additions & 7 deletions Tests/SpecTests/SpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ import XCTest

final class SpecTests: XCTestCase {

static var allTests = [
("testExample", testExample),
]

func testExample() {
// coming soon...
}
func testExample() throws {
let app = Application(.testing)
defer { app.shutdown() }
/// configure dummy path
app.get("lorem-ipsum") { _ in "Lorem ipsum" }

/// test dummy path
try app.describe("Lorem ipsum dolor sit amet")
.get("/lorem-ipsum/")
.expect(.ok)
.expect { res in
XCTAssertEqual(res.body.string, "Lorem ipsum")
}
.test(.inMemory)
}
}

0 comments on commit 74ec16a

Please sign in to comment.