diff --git a/Examples/LambdaFunctions/Sources/Benchmark/main.swift b/Examples/LambdaFunctions/Sources/Benchmark/main.swift index 88346400..d0d54706 100644 --- a/Examples/LambdaFunctions/Sources/Benchmark/main.swift +++ b/Examples/LambdaFunctions/Sources/Benchmark/main.swift @@ -22,10 +22,10 @@ import NIO Lambda.run { $0.eventLoop.makeSucceededFuture(BenchmarkHandler()) } struct BenchmarkHandler: EventLoopLambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String - func handle(event: String, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { context.eventLoop.makeSucceededFuture("hello, world!") } } diff --git a/Examples/LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift b/Examples/LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift index 2df62afa..1db53573 100644 --- a/Examples/LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift +++ b/Examples/LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift @@ -25,8 +25,8 @@ import Logging @main struct CurrencyExchangeHandler: LambdaHandler { - typealias In = Request - typealias Out = [Exchange] + typealias Event = Request + typealias Output = [Exchange] let calculator: ExchangeRatesCalculator @@ -35,7 +35,7 @@ struct CurrencyExchangeHandler: LambdaHandler { self.calculator = ExchangeRatesCalculator() } - func handle(event: Request, context: Lambda.Context) async throws -> [Exchange] { + func handle(_ event: Request, context: Lambda.Context) async throws -> [Exchange] { try await withCheckedThrowingContinuation { continuation in self.calculator.run(logger: context.logger) { result in switch result { diff --git a/Examples/LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift b/Examples/LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift index 10f5cfd5..f7d47dd6 100644 --- a/Examples/LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift +++ b/Examples/LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift @@ -18,12 +18,12 @@ import AWSLambdaRuntime @main struct ErrorsHappenHandler: LambdaHandler { - typealias In = Request - typealias Out = Response + typealias Event = Request + typealias Output = Response init(context: Lambda.InitializationContext) async throws {} - func handle(event request: Request, context: Lambda.Context) async throws -> Response { + func handle(_ request: Request, context: Lambda.Context) async throws -> Response { // switch over the error type "requested" by the request, and trigger such error accordingly switch request.error { // no error here! diff --git a/Examples/LambdaFunctions/Sources/HelloWorld/HelloWorldHandler.swift b/Examples/LambdaFunctions/Sources/HelloWorld/HelloWorldHandler.swift index 06214244..ac795e65 100644 --- a/Examples/LambdaFunctions/Sources/HelloWorld/HelloWorldHandler.swift +++ b/Examples/LambdaFunctions/Sources/HelloWorld/HelloWorldHandler.swift @@ -17,14 +17,14 @@ import AWSLambdaRuntime // introductory example, the obligatory "hello, world!" @main struct HelloWorldHandler: LambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String init(context: Lambda.InitializationContext) async throws { // setup your resources that you want to reuse here. } - func handle(event: String, context: Lambda.Context) async throws -> String { + func handle(_ event: String, context: Lambda.Context) async throws -> String { "hello, world" } } diff --git a/Examples/LocalDebugging/MyLambda/Sources/MyLambda/MyLambdaHandler.swift b/Examples/LocalDebugging/MyLambda/Sources/MyLambda/MyLambdaHandler.swift index 0c2225fb..3d4c88d3 100644 --- a/Examples/LocalDebugging/MyLambda/Sources/MyLambda/MyLambdaHandler.swift +++ b/Examples/LocalDebugging/MyLambda/Sources/MyLambda/MyLambdaHandler.swift @@ -19,14 +19,14 @@ import Shared // a local server simulator which will allow local debugging @main struct MyLambdaHandler: LambdaHandler { - typealias In = Request - typealias Out = Response + typealias Event = Request + typealias Output = Response init(context: Lambda.InitializationContext) async throws { // setup your resources that you want to reuse for every invocation here. } - func handle(event request: Request, context: Lambda.Context) async throws -> Response { + func handle(_ request: Request, context: Lambda.Context) async throws -> Response { // TODO: something useful Response(message: "Hello, \(request.name)!") } diff --git a/Sources/AWSLambdaRuntime/Lambda+Codable.swift b/Sources/AWSLambdaRuntime/Lambda+Codable.swift index 960e068e..f7da53bd 100644 --- a/Sources/AWSLambdaRuntime/Lambda+Codable.swift +++ b/Sources/AWSLambdaRuntime/Lambda+Codable.swift @@ -21,33 +21,33 @@ import NIOFoundationCompat // MARK: - Codable support -/// Implementation of a`ByteBuffer` to `In` decoding -extension EventLoopLambdaHandler where In: Decodable { +/// Implementation of a`ByteBuffer` to `Event` decoding +extension EventLoopLambdaHandler where Event: Decodable { @inlinable - public func decode(buffer: ByteBuffer) throws -> In { - try self.decoder.decode(In.self, from: buffer) + public func decode(buffer: ByteBuffer) throws -> Event { + try self.decoder.decode(Event.self, from: buffer) } } -/// Implementation of `Out` to `ByteBuffer` encoding -extension EventLoopLambdaHandler where Out: Encodable { +/// Implementation of `Output` to `ByteBuffer` encoding +extension EventLoopLambdaHandler where Output: Encodable { @inlinable - public func encode(allocator: ByteBufferAllocator, value: Out) throws -> ByteBuffer? { + public func encode(allocator: ByteBufferAllocator, value: Output) throws -> ByteBuffer? { try self.encoder.encode(value, using: allocator) } } -/// Default `ByteBuffer` to `In` decoder using Foundation's JSONDecoder +/// Default `ByteBuffer` to `Event` decoder using Foundation's JSONDecoder /// Advanced users that want to inject their own codec can do it by overriding these functions. -extension EventLoopLambdaHandler where In: Decodable { +extension EventLoopLambdaHandler where Event: Decodable { public var decoder: LambdaCodableDecoder { Lambda.defaultJSONDecoder } } -/// Default `Out` to `ByteBuffer` encoder using Foundation's JSONEncoder +/// Default `Output` to `ByteBuffer` encoder using Foundation's JSONEncoder /// Advanced users that want to inject their own codec can do it by overriding these functions. -extension EventLoopLambdaHandler where Out: Encodable { +extension EventLoopLambdaHandler where Output: Encodable { public var encoder: LambdaCodableEncoder { Lambda.defaultJSONEncoder } diff --git a/Sources/AWSLambdaRuntimeCore/Lambda+String.swift b/Sources/AWSLambdaRuntimeCore/Lambda+String.swift index 800afc15..f5a68f27 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda+String.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda+String.swift @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// import NIOCore -extension EventLoopLambdaHandler where In == String { +extension EventLoopLambdaHandler where Event == String { /// Implementation of a `ByteBuffer` to `String` decoding @inlinable public func decode(buffer: ByteBuffer) throws -> String { @@ -25,7 +25,7 @@ extension EventLoopLambdaHandler where In == String { } } -extension EventLoopLambdaHandler where Out == String { +extension EventLoopLambdaHandler where Output == String { /// Implementation of `String` to `ByteBuffer` encoding @inlinable public func encode(allocator: ByteBufferAllocator, value: String) throws -> ByteBuffer? { diff --git a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift index 2dda45a9..68d99f07 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift @@ -19,7 +19,7 @@ import NIOCore // MARK: - LambdaHandler #if compiler(>=5.5) -/// Strongly typed, processing protocol for a Lambda that takes a user defined `In` and returns a user defined `Out` async. +/// Strongly typed, processing protocol for a Lambda that takes a user defined `Event` and returns a user defined `Output` async. @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) public protocol LambdaHandler: EventLoopLambdaHandler { /// The Lambda initialization method @@ -34,19 +34,19 @@ public protocol LambdaHandler: EventLoopLambdaHandler { /// Concrete Lambda handlers implement this method to provide the Lambda functionality. /// /// - parameters: - /// - event: Event of type `In` representing the event or request. + /// - event: Event of type `Event` representing the event or request. /// - context: Runtime `Context`. /// - /// - Returns: A Lambda result ot type `Out`. - func handle(event: In, context: Lambda.Context) async throws -> Out + /// - Returns: A Lambda result ot type `Output`. + func handle(_ event: Event, context: Lambda.Context) async throws -> Output } @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) extension LambdaHandler { - public func handle(event: In, context: Lambda.Context) -> EventLoopFuture { - let promise = context.eventLoop.makePromise(of: Out.self) + public func handle(_ event: Event, context: Lambda.Context) -> EventLoopFuture { + let promise = context.eventLoop.makePromise(of: Output.self) promise.completeWithTask { - try await self.handle(event: event, context: context) + try await self.handle(event, context: context) } return promise.futureResult } @@ -62,59 +62,59 @@ extension LambdaHandler { // MARK: - EventLoopLambdaHandler -/// Strongly typed, `EventLoopFuture` based processing protocol for a Lambda that takes a user defined `In` and returns a user defined `Out` asynchronously. -/// `EventLoopLambdaHandler` extends `ByteBufferLambdaHandler`, performing `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding. +/// Strongly typed, `EventLoopFuture` based processing protocol for a Lambda that takes a user defined `Event` and returns a user defined `Output` asynchronously. +/// `EventLoopLambdaHandler` extends `ByteBufferLambdaHandler`, performing `ByteBuffer` -> `Event` decoding and `Output` -> `ByteBuffer` encoding. /// /// - note: To implement a Lambda, implement either `LambdaHandler` or the `EventLoopLambdaHandler` protocol. /// The `LambdaHandler` will offload the Lambda execution to a `DispatchQueue` making processing safer but slower /// The `EventLoopLambdaHandler` will execute the Lambda on the same `EventLoop` as the core runtime engine, making the processing faster but requires /// more care from the implementation to never block the `EventLoop`. public protocol EventLoopLambdaHandler: ByteBufferLambdaHandler { - associatedtype In - associatedtype Out + associatedtype Event + associatedtype Output /// The Lambda handling method /// Concrete Lambda handlers implement this method to provide the Lambda functionality. /// /// - parameters: /// - context: Runtime `Context`. - /// - event: Event of type `In` representing the event or request. + /// - event: Event of type `Event` representing the event or request. /// /// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine. - /// The `EventLoopFuture` should be completed with either a response of type `Out` or an `Error` - func handle(event: In, context: Lambda.Context) -> EventLoopFuture + /// The `EventLoopFuture` should be completed with either a response of type `Output` or an `Error` + func handle(_ event: Event, context: Lambda.Context) -> EventLoopFuture - /// Encode a response of type `Out` to `ByteBuffer` + /// Encode a response of type `Output` to `ByteBuffer` /// Concrete Lambda handlers implement this method to provide coding functionality. /// - parameters: /// - allocator: A `ByteBufferAllocator` to help allocate the `ByteBuffer`. - /// - value: Response of type `Out`. + /// - value: Response of type `Output`. /// /// - Returns: A `ByteBuffer` with the encoded version of the `value`. - func encode(allocator: ByteBufferAllocator, value: Out) throws -> ByteBuffer? + func encode(allocator: ByteBufferAllocator, value: Output) throws -> ByteBuffer? - /// Decode a`ByteBuffer` to a request or event of type `In` + /// Decode a`ByteBuffer` to a request or event of type `Event` /// Concrete Lambda handlers implement this method to provide coding functionality. /// /// - parameters: /// - buffer: The `ByteBuffer` to decode. /// - /// - Returns: A request or event of type `In`. - func decode(buffer: ByteBuffer) throws -> In + /// - Returns: A request or event of type `Event`. + func decode(buffer: ByteBuffer) throws -> Event } extension EventLoopLambdaHandler { - /// Driver for `ByteBuffer` -> `In` decoding and `Out` -> `ByteBuffer` encoding + /// Driver for `ByteBuffer` -> `Event` decoding and `Output` -> `ByteBuffer` encoding @inlinable - public func handle(event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture { - let input: In + public func handle(_ event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture { + let input: Event do { input = try self.decode(buffer: event) } catch { return context.eventLoop.makeFailedFuture(CodecError.requestDecoding(error)) } - return self.handle(event: input, context: context).flatMapThrowing { output in + return self.handle(input, context: context).flatMapThrowing { output in do { return try self.encode(allocator: context.allocator, value: output) } catch { @@ -125,7 +125,7 @@ extension EventLoopLambdaHandler { } /// Implementation of `ByteBuffer` to `Void` decoding -extension EventLoopLambdaHandler where Out == Void { +extension EventLoopLambdaHandler where Output == Void { @inlinable public func encode(allocator: ByteBufferAllocator, value: Void) throws -> ByteBuffer? { nil @@ -148,7 +148,7 @@ public protocol ByteBufferLambdaHandler { /// /// - Returns: An `EventLoopFuture` to report the result of the Lambda back to the runtime engine. /// The `EventLoopFuture` should be completed with either a response encoded as `ByteBuffer` or an `Error` - func handle(event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture + func handle(_ event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture /// Clean up the Lambda resources asynchronously. /// Concrete Lambda handlers implement this method to shutdown resources like `HTTPClient`s and database connections. diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift b/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift index 70a71277..542ede87 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRunner.swift @@ -62,7 +62,7 @@ extension Lambda { self.isGettingNextInvocation = true return self.runtimeClient.getNextInvocation(logger: logger).peekError { error in logger.error("could not fetch work from lambda runtime engine: \(error)") - }.flatMap { invocation, event in + }.flatMap { invocation, bytes in // 2. send invocation to handler self.isGettingNextInvocation = false let context = Context(logger: logger, @@ -70,7 +70,7 @@ extension Lambda { allocator: self.allocator, invocation: invocation) logger.debug("sending invocation to lambda handler \(handler)") - return handler.handle(event: event, context: context) + return handler.handle(bytes, context: context) // Hopping back to "our" EventLoop is important in case the handler returns a future that // originiated from a foreign EventLoop/EventLoopGroup. // This can happen if the handler uses a library (lets say a DB client) that manages its own threads/loops diff --git a/Sources/AWSLambdaTesting/Lambda+Testing.swift b/Sources/AWSLambdaTesting/Lambda+Testing.swift index d3cbc760..8f61419f 100644 --- a/Sources/AWSLambdaTesting/Lambda+Testing.swift +++ b/Sources/AWSLambdaTesting/Lambda+Testing.swift @@ -66,9 +66,9 @@ extension Lambda { public static func test( _ handlerType: Handler.Type, - with event: Handler.In, + with event: Handler.Event, using config: TestConfig = .init() - ) throws -> Handler.Out { + ) throws -> Handler.Output { let logger = Logger(label: "test") let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) defer { @@ -97,7 +97,7 @@ extension Lambda { let handler = try promise.futureResult.wait() return try eventLoop.flatSubmit { - handler.handle(event: event, context: context) + handler.handle(event, context: context) }.wait() } } diff --git a/Sources/CodableSample/main.swift b/Sources/CodableSample/main.swift index 37c11718..dae2b39e 100644 --- a/Sources/CodableSample/main.swift +++ b/Sources/CodableSample/main.swift @@ -26,10 +26,10 @@ struct Response: Codable { // in this example we are receiving and responding with codables. Request and Response above are examples of how to use // codables to model your reqeuest and response objects struct Handler: EventLoopLambdaHandler { - typealias In = Request - typealias Out = Response + typealias Event = Request + typealias Output = Response - func handle(event: Request, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: Request, context: Lambda.Context) -> EventLoopFuture { // as an example, respond with the input event's reversed body context.eventLoop.makeSucceededFuture(Response(body: String(event.body.reversed()))) } diff --git a/Sources/StringSample/main.swift b/Sources/StringSample/main.swift index 900e582f..d80820f8 100644 --- a/Sources/StringSample/main.swift +++ b/Sources/StringSample/main.swift @@ -17,10 +17,10 @@ import NIOCore // in this example we are receiving and responding with strings struct Handler: EventLoopLambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String - func handle(event: String, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { // as an example, respond with the event's reversed body context.eventLoop.makeSucceededFuture(String(event.reversed())) } diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift index d349d7dc..edf597e4 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift @@ -28,8 +28,8 @@ class LambdaHandlerTest: XCTestCase { defer { XCTAssertNoThrow(try server.stop().wait()) } struct TestBootstrapHandler: LambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String var initialized = false @@ -39,7 +39,7 @@ class LambdaHandlerTest: XCTestCase { self.initialized = true } - func handle(event: String, context: Lambda.Context) async throws -> String { + func handle(_ event: String, context: Lambda.Context) async throws -> String { event } } @@ -57,8 +57,8 @@ class LambdaHandlerTest: XCTestCase { defer { XCTAssertNoThrow(try server.stop().wait()) } struct TestBootstrapHandler: LambdaHandler { - typealias In = String - typealias Out = Void + typealias Event = String + typealias Output = Void var initialized = false @@ -68,7 +68,7 @@ class LambdaHandlerTest: XCTestCase { throw TestError("kaboom") } - func handle(event: String, context: Lambda.Context) async throws { + func handle(_ event: String, context: Lambda.Context) async throws { XCTFail("How can this be called if init failed") } } @@ -86,12 +86,12 @@ class LambdaHandlerTest: XCTestCase { defer { XCTAssertNoThrow(try server.stop().wait()) } struct Handler: LambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String init(context: Lambda.InitializationContext) {} - func handle(event: String, context: Lambda.Context) async throws -> String { + func handle(_ event: String, context: Lambda.Context) async throws -> String { event } } @@ -109,12 +109,12 @@ class LambdaHandlerTest: XCTestCase { defer { XCTAssertNoThrow(try server.stop().wait()) } struct Handler: LambdaHandler { - typealias In = String - typealias Out = Void + typealias Event = String + typealias Output = Void init(context: Lambda.InitializationContext) {} - func handle(event: String, context: Lambda.Context) async throws {} + func handle(_ event: String, context: Lambda.Context) async throws {} } let maxTimes = Int.random(in: 1 ... 10) @@ -131,12 +131,12 @@ class LambdaHandlerTest: XCTestCase { defer { XCTAssertNoThrow(try server.stop().wait()) } struct Handler: LambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String init(context: Lambda.InitializationContext) {} - func handle(event: String, context: Lambda.Context) async throws -> String { + func handle(_ event: String, context: Lambda.Context) async throws -> String { throw TestError("boom") } } @@ -156,10 +156,10 @@ class LambdaHandlerTest: XCTestCase { defer { XCTAssertNoThrow(try server.stop().wait()) } struct Handler: EventLoopLambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String - func handle(event: String, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { context.eventLoop.makeSucceededFuture(event) } } @@ -178,10 +178,10 @@ class LambdaHandlerTest: XCTestCase { defer { XCTAssertNoThrow(try server.stop().wait()) } struct Handler: EventLoopLambdaHandler { - typealias In = String - typealias Out = Void + typealias Event = String + typealias Output = Void - func handle(event: String, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { context.eventLoop.makeSucceededFuture(()) } } @@ -200,10 +200,10 @@ class LambdaHandlerTest: XCTestCase { defer { XCTAssertNoThrow(try server.stop().wait()) } struct Handler: EventLoopLambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String - func handle(event: String, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { context.eventLoop.makeFailedFuture(TestError("boom")) } } diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift index ed514376..67c12ae0 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift @@ -19,7 +19,7 @@ struct EchoHandler: EventLoopLambdaHandler { typealias In = String typealias Out = String - func handle(event: String, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { context.eventLoop.makeSucceededFuture(event) } } @@ -34,7 +34,7 @@ struct FailedHandler: EventLoopLambdaHandler { self.reason = reason } - func handle(event: String, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { context.eventLoop.makeFailedFuture(TestError(self.reason)) } } diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaLifecycleTest.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaLifecycleTest.swift index 7b0226e6..b0c83113 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaLifecycleTest.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaLifecycleTest.swift @@ -54,7 +54,7 @@ class LambdaLifecycleTest: XCTestCase { self.shutdown = shutdown } - func handle(event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: ByteBuffer, context: Lambda.Context) -> EventLoopFuture { self.handler(context, event) } diff --git a/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift b/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift index c8520867..770f1efb 100644 --- a/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift +++ b/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift @@ -38,12 +38,12 @@ class CodableLambdaTest: XCTestCase { var outputBuffer: ByteBuffer? struct Handler: EventLoopLambdaHandler { - typealias In = Request - typealias Out = Void + typealias Event = Request + typealias Output = Void let expected: Request - func handle(event: Request, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: Request, context: Lambda.Context) -> EventLoopFuture { XCTAssertEqual(event, self.expected) return context.eventLoop.makeSucceededVoidFuture() } @@ -52,7 +52,7 @@ class CodableLambdaTest: XCTestCase { let handler = Handler(expected: request) XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator)) - XCTAssertNoThrow(outputBuffer = try handler.handle(event: XCTUnwrap(inputBuffer), context: self.newContext()).wait()) + XCTAssertNoThrow(outputBuffer = try handler.handle(XCTUnwrap(inputBuffer), context: self.newContext()).wait()) XCTAssertNil(outputBuffer) } @@ -63,12 +63,12 @@ class CodableLambdaTest: XCTestCase { var response: Response? struct Handler: EventLoopLambdaHandler { - typealias In = Request - typealias Out = Response + typealias Event = Request + typealias Output = Response let expected: Request - func handle(event: Request, context: Lambda.Context) -> EventLoopFuture { + func handle(_ event: Request, context: Lambda.Context) -> EventLoopFuture { XCTAssertEqual(event, self.expected) return context.eventLoop.makeSucceededFuture(Response(requestId: event.requestId)) } @@ -77,7 +77,7 @@ class CodableLambdaTest: XCTestCase { let handler = Handler(expected: request) XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator)) - XCTAssertNoThrow(outputBuffer = try handler.handle(event: XCTUnwrap(inputBuffer), context: self.newContext()).wait()) + XCTAssertNoThrow(outputBuffer = try handler.handle(XCTUnwrap(inputBuffer), context: self.newContext()).wait()) XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer))) XCTAssertEqual(response?.requestId, request.requestId) } @@ -86,14 +86,14 @@ class CodableLambdaTest: XCTestCase { @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) func testCodableVoidHandler() { struct Handler: LambdaHandler { - typealias In = Request - typealias Out = Void + typealias Event = Request + typealias Output = Void var expected: Request? init(context: Lambda.InitializationContext) async throws {} - func handle(event: Request, context: Lambda.Context) async throws { + func handle(_ event: Request, context: Lambda.Context) async throws { XCTAssertEqual(event, self.expected) } } @@ -107,7 +107,7 @@ class CodableLambdaTest: XCTestCase { handler.expected = request XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator)) - XCTAssertNoThrow(outputBuffer = try handler.handle(event: XCTUnwrap(inputBuffer), context: self.newContext()).wait()) + XCTAssertNoThrow(outputBuffer = try handler.handle(XCTUnwrap(inputBuffer), context: self.newContext()).wait()) XCTAssertNil(outputBuffer) } } @@ -115,14 +115,14 @@ class CodableLambdaTest: XCTestCase { @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) func testCodableHandler() { struct Handler: LambdaHandler { - typealias In = Request - typealias Out = Response + typealias Event = Request + typealias Output = Response var expected: Request? init(context: Lambda.InitializationContext) async throws {} - func handle(event: Request, context: Lambda.Context) async throws -> Response { + func handle(_ event: Request, context: Lambda.Context) async throws -> Response { XCTAssertEqual(event, self.expected) return Response(requestId: event.requestId) } @@ -138,7 +138,7 @@ class CodableLambdaTest: XCTestCase { handler.expected = request XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator)) - XCTAssertNoThrow(outputBuffer = try handler.handle(event: XCTUnwrap(inputBuffer), context: self.newContext()).wait()) + XCTAssertNoThrow(outputBuffer = try handler.handle(XCTUnwrap(inputBuffer), context: self.newContext()).wait()) XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer))) XCTAssertEqual(response?.requestId, request.requestId) } diff --git a/Tests/AWSLambdaTestingTests/Tests.swift b/Tests/AWSLambdaTestingTests/Tests.swift index ae0efbcc..8b888931 100644 --- a/Tests/AWSLambdaTestingTests/Tests.swift +++ b/Tests/AWSLambdaTestingTests/Tests.swift @@ -30,12 +30,12 @@ class LambdaTestingTests: XCTestCase { } struct MyLambda: LambdaHandler { - typealias In = Request - typealias Out = Response + typealias Event = Request + typealias Output = Response init(context: Lambda.InitializationContext) {} - func handle(event: Request, context: Lambda.Context) async throws -> Response { + func handle(_ event: Request, context: Lambda.Context) async throws -> Response { Response(message: "echo" + event.name) } } @@ -54,12 +54,12 @@ class LambdaTestingTests: XCTestCase { } struct MyLambda: LambdaHandler { - typealias In = Request - typealias Out = Void + typealias Event = Request + typealias Output = Void init(context: Lambda.InitializationContext) {} - func handle(event: Request, context: Lambda.Context) async throws { + func handle(_ event: Request, context: Lambda.Context) async throws { LambdaTestingTests.VoidLambdaHandlerInvokeCount += 1 } } @@ -74,12 +74,12 @@ class LambdaTestingTests: XCTestCase { struct MyError: Error {} struct MyLambda: LambdaHandler { - typealias In = String - typealias Out = Void + typealias Event = String + typealias Output = Void init(context: Lambda.InitializationContext) {} - func handle(event: String, context: Lambda.Context) async throws { + func handle(_ event: String, context: Lambda.Context) async throws { throw MyError() } } @@ -91,12 +91,12 @@ class LambdaTestingTests: XCTestCase { func testAsyncLongRunning() { struct MyLambda: LambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String init(context: Lambda.InitializationContext) {} - func handle(event: String, context: Lambda.Context) async throws -> String { + func handle(_ event: String, context: Lambda.Context) async throws -> String { try await Task.sleep(nanoseconds: 500 * 1000 * 1000) return event }