|
1 | | -@testable import App |
2 | 1 | import Hummingbird |
3 | 2 | import HummingbirdTesting |
4 | 3 | import ServiceLifecycle |
5 | | -import XCTest |
| 4 | +import Testing |
| 5 | + |
| 6 | +@testable import App |
6 | 7 |
|
7 | | -final class AppTests: XCTestCase { |
| 8 | +struct AppTests { |
8 | 9 | struct TestAppArguments: AppArguments { |
9 | 10 | var hostname: String { "127.0.0.1" } |
10 | 11 | var port: Int { 8081 } |
@@ -55,66 +56,66 @@ final class AppTests: XCTestCase { |
55 | 56 |
|
56 | 57 | // MARK: tests |
57 | 58 |
|
58 | | - func testSimple() async throws { |
| 59 | + @Test func testSimple() async throws { |
59 | 60 | try await self.testProxy { router in |
60 | 61 | router.get("hello") { _, _ in |
61 | | - return "Hello" |
| 62 | + "Hello" |
62 | 63 | } |
63 | 64 | } test: { port in |
64 | 65 | let proxy = buildApplication(TestAppArguments(location: "", target: "http://localhost:\(port)")) |
65 | 66 | try await proxy.test(.live) { client in |
66 | 67 | try await client.execute(uri: "/hello", method: .get) { response in |
67 | | - XCTAssertEqual(String(buffer: response.body), "Hello") |
| 68 | + #expect(String(buffer: response.body) == "Hello") |
68 | 69 | } |
69 | 70 | } |
70 | 71 | } |
71 | 72 | } |
72 | 73 |
|
73 | | - func testLocation() async throws { |
| 74 | + @Test func testLocation() async throws { |
74 | 75 | try await self.testProxy { router in |
75 | 76 | router.get("hello") { _, _ in |
76 | | - return "Hello" |
| 77 | + "Hello" |
77 | 78 | } |
78 | 79 | } test: { port in |
79 | 80 | let proxy = buildApplication(TestAppArguments(location: "/proxy", target: "http://localhost:\(port)")) |
80 | 81 | try await proxy.test(.live) { client in |
81 | 82 | try await client.execute(uri: "/proxy/hello", method: .get) { response in |
82 | | - XCTAssertEqual(String(buffer: response.body), "Hello") |
| 83 | + #expect(String(buffer: response.body) == "Hello") |
83 | 84 | } |
84 | 85 | } |
85 | 86 | } |
86 | 87 | } |
87 | 88 |
|
88 | | - func testEchoBody() async throws { |
| 89 | + @Test func testEchoBody() async throws { |
89 | 90 | let string = "This is a test body" |
90 | 91 | let buffer = ByteBuffer(string: string) |
91 | 92 | try await self.testProxy { router in |
92 | 93 | router.post("echo") { request, _ in |
93 | 94 | // test content length was passed through |
94 | | - XCTAssertEqual(request.headers[.contentLength], buffer.readableBytes.description) |
| 95 | + #expect(request.headers[.contentLength] == buffer.readableBytes.description) |
95 | 96 | return Response(status: .ok, body: .init(asyncSequence: request.body)) |
96 | 97 | } |
97 | 98 | } test: { port in |
98 | 99 | let proxy = buildApplication(TestAppArguments(location: "", target: "http://localhost:\(port)")) |
99 | 100 | try await proxy.test(.live) { client in |
100 | 101 | try await client.execute(uri: "/echo", method: .post, body: buffer) { response in |
101 | | - XCTAssertEqual(response.body, buffer) |
| 102 | + #expect(response.body == buffer) |
102 | 103 | } |
103 | 104 | } |
104 | 105 | } |
105 | 106 | } |
106 | 107 |
|
107 | | - func testLargeBody() async throws { |
| 108 | + @Test func testLargeBody() async throws { |
108 | 109 | try await self.testProxy { router in |
109 | 110 | router.post("echo") { request, _ in |
110 | | - return Response(status: .ok, body: .init(asyncSequence: request.body)) |
| 111 | + Response(status: .ok, body: .init(asyncSequence: request.body)) |
111 | 112 | } |
112 | 113 | } test: { port in |
113 | 114 | let proxy = buildApplication(TestAppArguments(location: "", target: "http://localhost:\(port)")) |
114 | 115 | try await proxy.test(.live) { client in |
115 | 116 | let buffer = self.randomBuffer(size: 1024 * 1500) |
116 | 117 | try await client.execute(uri: "/echo", method: .post, body: buffer) { response in |
117 | | - XCTAssertEqual(response.body, buffer) |
| 118 | + #expect(response.body == buffer) |
118 | 119 | } |
119 | 120 | } |
120 | 121 | } |
|
0 commit comments