File tree 2 files changed +13
-15
lines changed
Tests/AWSLambdaEventsTests
2 files changed +13
-15
lines changed Original file line number Diff line number Diff line change 12
12
//
13
13
//===----------------------------------------------------------------------===//
14
14
15
+ import HTTPTypes
16
+
15
17
#if canImport(FoundationEssentials)
16
18
import class FoundationEssentials. JSONEncoder
17
19
import class FoundationEssentials. Data
@@ -20,15 +22,13 @@ import class Foundation.JSONEncoder
20
22
import struct Foundation. Data
21
23
#endif
22
24
23
- import HTTPTypes
24
-
25
25
public enum APIGatewayResponseError : Error {
26
26
case failedToEncodeBody( Error )
27
27
}
28
28
29
29
extension APIGatewayV2Response {
30
30
31
- public init < Input: Encodable > (
31
+ public init < Input: Encodable > (
32
32
statusCode: HTTPResponse . Status ,
33
33
headers: HTTPHeaders ? = nil ,
34
34
body: Input ,
Original file line number Diff line number Diff line change 12
12
//
13
13
//===----------------------------------------------------------------------===//
14
14
15
+ import Foundation
15
16
import Testing
16
17
17
- import Foundation
18
-
19
18
@testable import AWSLambdaEvents
20
19
21
20
struct APIGatewayV2EncodableResponseTests {
22
21
23
-
24
22
// MARK: Encoding
25
23
struct BusinessResponse : Codable , Equatable {
26
24
let message : String
27
25
let code : Int
28
26
}
29
27
30
- @Test
28
+ @Test
31
29
func testResponseEncoding( ) throws {
32
30
33
- // given
31
+ // given
34
32
let businessResponse = BusinessResponse ( message: " Hello World " , code: 200 )
35
-
33
+
36
34
var response : APIGatewayV2Response ? = nil
37
- #expect( throws: Never . self) {
35
+ #expect( throws: Never . self) {
38
36
try response = APIGatewayV2Response ( statusCode: . ok, body: businessResponse)
39
- }
37
+ }
40
38
try #require( response? . body != nil )
41
39
42
- // when
43
- let body = response? . body? . data ( using: . utf8)
40
+ // when
41
+ let body = response? . body? . data ( using: . utf8)
44
42
try #require( body != nil )
45
43
46
- #expect( throws: Never . self) {
44
+ #expect( throws: Never . self) {
47
45
let encodedBody = try JSONDecoder ( ) . decode ( BusinessResponse . self, from: body!)
48
-
46
+
49
47
// then
50
48
#expect( encodedBody == businessResponse)
51
49
}
You can’t perform that action at this time.
0 commit comments