|
12 | 12 | //
|
13 | 13 | //===----------------------------------------------------------------------===//
|
14 | 14 |
|
15 |
| -import XCTest |
| 15 | +import Foundation |
| 16 | +import Testing |
16 | 17 |
|
17 | 18 | @testable import AWSLambdaEvents
|
18 | 19 |
|
19 |
| -class APIGatewayV2Tests: XCTestCase { |
| 20 | +@Suite |
| 21 | +struct APIGatewayV2Tests { |
20 | 22 | static let exampleGetEventBody = """
|
21 | 23 | {
|
22 | 24 | "routeKey":"GET /hello",
|
@@ -189,36 +191,37 @@ class APIGatewayV2Tests: XCTestCase {
|
189 | 191 |
|
190 | 192 | // MARK: Decoding
|
191 | 193 |
|
192 |
| - func testRequestDecodingExampleGetRequest() { |
| 194 | + @Test func requestDecodingExampleGetRequest() throws { |
193 | 195 | let data = APIGatewayV2Tests.exampleGetEventBody.data(using: .utf8)!
|
194 |
| - var req: APIGatewayV2Request? |
195 |
| - XCTAssertNoThrow(req = try JSONDecoder().decode(APIGatewayV2Request.self, from: data)) |
| 196 | + let req = try JSONDecoder().decode(APIGatewayV2Request.self, from: data) |
196 | 197 |
|
197 |
| - XCTAssertEqual(req?.rawPath, "/hello") |
198 |
| - XCTAssertEqual(req?.context.http.method, .get) |
199 |
| - XCTAssertEqual(req?.queryStringParameters.count, 1) |
200 |
| - XCTAssertEqual(req?.rawQueryString, "foo=bar") |
201 |
| - XCTAssertEqual(req?.headers.count, 8) |
202 |
| - XCTAssertEqual(req?.context.authorizer?.jwt?.claims?["aud"], "customers") |
| 198 | + #expect(req.rawPath == "/hello") |
| 199 | + #expect(req.context.http.method == .get) |
| 200 | + #expect(req.queryStringParameters.count == 1) |
| 201 | + #expect(req.rawQueryString == "foo=bar") |
| 202 | + #expect(req.headers.count == 8) |
| 203 | + #expect(req.context.authorizer?.jwt?.claims?["aud"] == "customers") |
203 | 204 |
|
204 |
| - XCTAssertNil(req?.body) |
| 205 | + #expect(req.body == nil) |
205 | 206 | }
|
206 | 207 |
|
207 |
| - func testDecodingRequestClientCert() throws { |
| 208 | + @Test func decodingRequestClientCert() throws { |
208 | 209 | let data = APIGatewayV2Tests.fullExamplePayload.data(using: .utf8)!
|
209 | 210 | let request = try JSONDecoder().decode(APIGatewayV2Request.self, from: data)
|
210 | 211 | let clientCert = request.context.authentication?.clientCert
|
211 | 212 |
|
212 |
| - XCTAssertEqual(clientCert?.clientCertPem, "CERT_CONTENT") |
213 |
| - XCTAssertEqual(clientCert?.subjectDN, "www.example.com") |
214 |
| - XCTAssertEqual(clientCert?.issuerDN, "Example issuer") |
215 |
| - XCTAssertEqual(clientCert?.serialNumber, "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1") |
216 |
| - XCTAssertEqual(clientCert?.validity.notBefore, "May 28 12:30:02 2019 GMT") |
217 |
| - XCTAssertEqual(clientCert?.validity.notAfter, "Aug 5 09:36:04 2021 GMT") |
| 213 | + #expect(clientCert?.clientCertPem == "CERT_CONTENT") |
| 214 | + #expect(clientCert?.subjectDN == "www.example.com") |
| 215 | + #expect(clientCert?.issuerDN == "Example issuer") |
| 216 | + #expect(clientCert?.serialNumber == "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1") |
| 217 | + #expect(clientCert?.validity.notBefore == "May 28 12:30:02 2019 GMT") |
| 218 | + #expect(clientCert?.validity.notAfter == "Aug 5 09:36:04 2021 GMT") |
218 | 219 | }
|
219 | 220 |
|
220 |
| - func testDecodingNilCollections() { |
| 221 | + @Test func decodingNilCollections() throws { |
221 | 222 | let data = APIGatewayV2Tests.exampleGetEventBodyNilHeaders.data(using: .utf8)!
|
222 |
| - XCTAssertNoThrow(_ = try JSONDecoder().decode(APIGatewayV2Request.self, from: data)) |
| 223 | + #expect(throws: Never.self) { |
| 224 | + _ = try JSONDecoder().decode(APIGatewayV2Request.self, from: data) |
| 225 | + } |
223 | 226 | }
|
224 | 227 | }
|
0 commit comments