@@ -20,7 +20,24 @@ import XCTest
20
20
21
21
@available ( macOS 12 , iOS 15 , tvOS 15 , watchOS 8 , * )
22
22
class LambdaTestingTests : XCTestCase {
23
- func testCodableClosure( ) {
23
+ func testBasics( ) async throws {
24
+ struct MyLambda : LambdaHandler {
25
+ typealias Event = String
26
+ typealias Output = String
27
+
28
+ init ( context: LambdaInitializationContext ) { }
29
+
30
+ func handle( _ event: String , context: LambdaContext ) async throws -> String {
31
+ return event
32
+ }
33
+ }
34
+
35
+ let uuid = UUID ( ) . uuidString
36
+ let result = try await Lambda . test ( MyLambda . self, with: uuid)
37
+ XCTAssertEqual ( result, uuid)
38
+ }
39
+
40
+ func testCodableClosure( ) async throws {
24
41
struct Request : Codable {
25
42
let name : String
26
43
}
@@ -41,36 +58,36 @@ class LambdaTestingTests: XCTestCase {
41
58
}
42
59
43
60
let request = Request ( name: UUID ( ) . uuidString)
44
- var response : Response ?
45
- XCTAssertNoThrow ( response = try Lambda . test ( MyLambda . self, with: request) )
46
- XCTAssertEqual ( response? . message, " echo " + request. name)
61
+ let response = try await Lambda . test ( MyLambda . self, with: request)
62
+ XCTAssertEqual ( response. message, " echo " + request. name)
47
63
}
48
64
49
- // DIRTY HACK: To verify the handler was actually invoked, we change a global variable.
50
- static var VoidLambdaHandlerInvokeCount : Int = 0
51
- func testCodableVoidClosure( ) {
65
+ func testCodableVoidClosure( ) async throws {
52
66
struct Request : Codable {
53
67
let name : String
54
68
}
55
69
56
70
struct MyLambda : LambdaHandler {
71
+ // DIRTY HACK: To verify the handler was actually invoked, we change a global variable.
72
+ static var VoidLambdaHandlerInvokeCount : Int = 0
73
+
57
74
typealias Event = Request
58
75
typealias Output = Void
59
76
60
77
init ( context: LambdaInitializationContext ) { }
61
78
62
79
func handle( _ event: Request , context: LambdaContext ) async throws {
63
- LambdaTestingTests . VoidLambdaHandlerInvokeCount += 1
80
+ Self . VoidLambdaHandlerInvokeCount += 1
64
81
}
65
82
}
66
83
67
- Self . VoidLambdaHandlerInvokeCount = 0
68
84
let request = Request ( name: UUID ( ) . uuidString)
69
- XCTAssertNoThrow ( try Lambda . test ( MyLambda . self, with: request) )
70
- XCTAssertEqual ( Self . VoidLambdaHandlerInvokeCount, 1 )
85
+ MyLambda . VoidLambdaHandlerInvokeCount = 0
86
+ try await Lambda . test ( MyLambda . self, with: request)
87
+ XCTAssertEqual ( MyLambda . VoidLambdaHandlerInvokeCount, 1 )
71
88
}
72
89
73
- func testInvocationFailure( ) {
90
+ func testInvocationFailure( ) async throws {
74
91
struct MyError : Error { }
75
92
76
93
struct MyLambda : LambdaHandler {
@@ -84,12 +101,15 @@ class LambdaTestingTests: XCTestCase {
84
101
}
85
102
}
86
103
87
- XCTAssertThrowsError ( try Lambda . test ( MyLambda . self, with: UUID ( ) . uuidString) ) { error in
104
+ do {
105
+ try await Lambda . test ( MyLambda . self, with: UUID ( ) . uuidString)
106
+ XCTFail ( " expected to throw " )
107
+ } catch {
88
108
XCTAssert ( error is MyError )
89
109
}
90
110
}
91
111
92
- func testAsyncLongRunning( ) {
112
+ func testAsyncLongRunning( ) async throws {
93
113
struct MyLambda : LambdaHandler {
94
114
typealias Event = String
95
115
typealias Output = String
@@ -103,7 +123,8 @@ class LambdaTestingTests: XCTestCase {
103
123
}
104
124
105
125
let uuid = UUID ( ) . uuidString
106
- XCTAssertEqual ( try Lambda . test ( MyLambda . self, with: uuid) , uuid)
126
+ let result = try await Lambda . test ( MyLambda . self, with: uuid)
127
+ XCTAssertEqual ( result, uuid)
107
128
}
108
129
}
109
130
#endif
0 commit comments