|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
| 15 | +import Foundation |
| 16 | + |
15 | 17 | @testable import App |
16 | 18 |
|
17 | 19 | import Dependencies |
18 | | -import XCTVapor |
| 20 | +import Testing |
19 | 21 |
|
20 | 22 |
|
21 | | -final class RoutesTests: AppTestCase { |
| 23 | +@Suite struct RoutesTests { |
22 | 24 |
|
23 | | - func test_documentation_images() async throws { |
| 25 | + @Test func documentation_images() async throws { |
24 | 26 | try await withDependencies { |
25 | 27 | $0.environment.awsDocsBucket = { "docs-bucket" } |
26 | 28 | $0.httpClient.fetchDocumentation = App.HTTPClient.echoURL() |
27 | 29 | } operation: { |
28 | | - // MUT |
29 | | - try await app.test(.GET, "foo/bar/1.2.3/images/baz.png") { res async in |
30 | | - // validation |
31 | | - XCTAssertEqual(res.status, .ok) |
32 | | - XCTAssertEqual(res.content.contentType?.description, "application/octet-stream") |
33 | | - XCTAssertEqual(res.body.asString(), "/foo/bar/1.2.3/images/baz.png") |
34 | | - } |
35 | | - try await app.test(.GET, "foo/bar/1.2.3/images/BAZ.png") { res async in |
36 | | - // validation |
37 | | - XCTAssertEqual(res.status, .ok) |
38 | | - XCTAssertEqual(res.content.contentType?.description, "application/octet-stream") |
39 | | - XCTAssertEqual(res.body.asString(), "/foo/bar/1.2.3/images/BAZ.png") |
| 30 | + try await withApp { app in |
| 31 | + // MUT |
| 32 | + try await app.test(.GET, "foo/bar/1.2.3/images/baz.png") { res async in |
| 33 | + // validation |
| 34 | + #expect(res.status == .ok) |
| 35 | + #expect(res.content.contentType?.description == "application/octet-stream") |
| 36 | + #expect(res.body.asString() == "/foo/bar/1.2.3/images/baz.png") |
| 37 | + } |
| 38 | + try await app.test(.GET, "foo/bar/1.2.3/images/BAZ.png") { res async in |
| 39 | + // validation |
| 40 | + #expect(res.status == .ok) |
| 41 | + #expect(res.content.contentType?.description == "application/octet-stream") |
| 42 | + #expect(res.body.asString() == "/foo/bar/1.2.3/images/BAZ.png") |
| 43 | + } |
40 | 44 | } |
41 | 45 | } |
42 | 46 | } |
43 | 47 |
|
44 | | - func test_documentation_img() async throws { |
| 48 | + @Test func documentation_img() async throws { |
45 | 49 | try await withDependencies { |
46 | 50 | $0.environment.awsDocsBucket = { "docs-bucket" } |
47 | 51 | $0.httpClient.fetchDocumentation = { @Sendable _ in .ok } |
48 | 52 | } operation: { |
49 | | - // MUT |
50 | | - try await app.test(.GET, "foo/bar/1.2.3/img/baz.png") { res async in |
51 | | - // validation |
52 | | - XCTAssertEqual(res.status, .ok) |
| 53 | + try await withApp { app in |
| 54 | + // MUT |
| 55 | + try await app.test(.GET, "foo/bar/1.2.3/img/baz.png") { res async in |
| 56 | + // validation |
| 57 | + #expect(res.status == .ok) |
| 58 | + } |
53 | 59 | } |
54 | 60 | } |
55 | 61 | } |
56 | 62 |
|
57 | | - func test_documentation_videos() async throws { |
| 63 | + @Test func documentation_videos() async throws { |
58 | 64 | try await withDependencies { |
59 | 65 | $0.environment.awsDocsBucket = { "docs-bucket" } |
60 | 66 | $0.httpClient.fetchDocumentation = { @Sendable _ in .ok } |
61 | 67 | } operation: { |
62 | | - // MUT |
63 | | - try await app.test(.GET, "foo/bar/1.2.3/videos/baz.mov") { res async in |
64 | | - // validation |
65 | | - XCTAssertEqual(res.status, .ok) |
| 68 | + try await withApp { app in |
| 69 | + // MUT |
| 70 | + try await app.test(.GET, "foo/bar/1.2.3/videos/baz.mov") { res async in |
| 71 | + // validation |
| 72 | + #expect(res.status == .ok) |
| 73 | + } |
66 | 74 | } |
67 | 75 | } |
68 | 76 | } |
69 | 77 |
|
70 | | - func test_openapi() async throws { |
71 | | - try await app.test(.GET, "openapi/openapi.json") { res async in |
72 | | - XCTAssertEqual(res.status, .ok) |
73 | | - struct Response: Codable, Equatable { |
74 | | - var info: Info |
75 | | - struct Info: Codable, Equatable { |
76 | | - var title: String |
| 78 | + @Test func openapi() async throws { |
| 79 | + try await withApp { app in |
| 80 | + try await app.test(.GET, "openapi/openapi.json") { res async throws in |
| 81 | + #expect(res.status == .ok) |
| 82 | + struct Response: Codable, Equatable { |
| 83 | + var info: Info |
| 84 | + struct Info: Codable, Equatable { |
| 85 | + var title: String |
| 86 | + } |
77 | 87 | } |
| 88 | + let decoded = try JSONDecoder().decode(Response.self, from: res.body) |
| 89 | + #expect(decoded == Response(info: .init(title: "Swift Package Index API"))) |
78 | 90 | } |
79 | | - XCTAssertEqualJSON(res.body.asString(), Response(info: .init(title: "Swift Package Index API"))) |
80 | 91 | } |
81 | 92 | } |
82 | 93 |
|
83 | | - func test_maintenanceMessage() throws { |
84 | | - try withDependencies { |
| 94 | + @Test func maintenanceMessage() async throws { |
| 95 | + try await withDependencies { |
85 | 96 | $0.environment.dbId = { nil } |
86 | 97 | $0.environment.maintenanceMessage = { "MAINTENANCE_MESSAGE" } |
87 | 98 | } operation: { |
88 | | - |
89 | | - try app.test(.GET, "/") { res in |
90 | | - XCTAssertContains(res.body.string, "MAINTENANCE_MESSAGE") |
| 99 | + try await withApp { app in |
| 100 | + try await app.test(.GET, "/") { res async in |
| 101 | + #expect(res.body.string.contains("MAINTENANCE_MESSAGE")) |
| 102 | + } |
91 | 103 | } |
92 | 104 | } |
93 | 105 | } |
|
0 commit comments