Skip to content

Commit 23944a3

Browse files
committed
swiftformat
1 parent aebc527 commit 23944a3

File tree

7 files changed

+55
-54
lines changed

7 files changed

+55
-54
lines changed

Sources/AWSLambdaTesting/Lambda+Testing.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
// }
3737

3838
#if swift(>=5.5)
39+
import _NIOConcurrency
3940
import AWSLambdaRuntime
4041
import AWSLambdaRuntimeCore
4142
import Dispatch
4243
import Logging
4344
import NIOCore
4445
import NIOPosix
45-
import _NIOConcurrency
4646

4747
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
4848
extension Lambda {
@@ -75,26 +75,27 @@ extension Lambda {
7575
try! eventLoopGroup.syncShutdownGracefully()
7676
}
7777
let eventLoop = eventLoopGroup.next()
78-
78+
7979
let promise = eventLoop.makePromise(of: Handler.self)
8080
let initContext = Lambda.InitializationContext(
8181
logger: logger,
8282
eventLoop: eventLoop,
83-
allocator: ByteBufferAllocator())
84-
83+
allocator: ByteBufferAllocator()
84+
)
85+
8586
let context = Context(requestID: config.requestID,
8687
traceID: config.traceID,
8788
invokedFunctionARN: config.invokedFunctionARN,
8889
deadline: .now() + config.timeout,
8990
logger: logger,
9091
eventLoop: eventLoop,
9192
allocator: ByteBufferAllocator())
92-
93+
9394
promise.completeWithTask {
9495
try await Handler(context: initContext)
9596
}
9697
let handler = try promise.futureResult.wait()
97-
98+
9899
return try eventLoop.flatSubmit {
99100
handler.handle(context: context, event: event)
100101
}.wait()

Sources/CodableSample/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct Handler: EventLoopLambdaHandler {
3535
}
3636
}
3737

38-
Lambda.run({ $0.eventLoop.makeSucceededFuture(Handler()) })
38+
Lambda.run { $0.eventLoop.makeSucceededFuture(Handler()) }
3939

4040
// MARK: - this can also be expressed as a closure:
4141

Sources/StringSample/main.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ struct Handler: EventLoopLambdaHandler {
2626
}
2727
}
2828

29-
Lambda.run({ $0.eventLoop.makeSucceededFuture(Handler()) })
29+
Lambda.run { $0.eventLoop.makeSucceededFuture(Handler()) }

Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LambdaHandlerTest: XCTestCase {
2020
#if compiler(>=5.5)
2121

2222
// MARK: - LambdaHandler
23-
23+
2424
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
2525
func testBootstrapSuccess() {
2626
let server = MockLambdaServer(behavior: Behavior())
@@ -38,7 +38,7 @@ class LambdaHandlerTest: XCTestCase {
3838
try await Task.sleep(nanoseconds: 100 * 1000 * 1000) // 0.1 seconds
3939
self.initialized = true
4040
}
41-
41+
4242
func handle(event: String, context: Lambda.Context) async throws -> String {
4343
event
4444
}
@@ -49,7 +49,7 @@ class LambdaHandlerTest: XCTestCase {
4949
let result = Lambda.run(configuration: configuration, handlerType: TestBootstrapHandler.self)
5050
assertLambdaLifecycleResult(result, shoudHaveRun: maxTimes)
5151
}
52-
52+
5353
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
5454
func testBootstrapFailure() {
5555
let server = MockLambdaServer(behavior: FailedBootstrapBehavior())
@@ -67,7 +67,7 @@ class LambdaHandlerTest: XCTestCase {
6767
try await Task.sleep(nanoseconds: 100 * 1000 * 1000) // 0.1 seconds
6868
throw TestError("kaboom")
6969
}
70-
70+
7171
func handle(event: String, context: Lambda.Context) async throws {
7272
XCTFail("How can this be called if init failed")
7373
}
@@ -119,7 +119,7 @@ class LambdaHandlerTest: XCTestCase {
119119

120120
let maxTimes = Int.random(in: 1 ... 10)
121121
let configuration = Lambda.Configuration(lifecycle: .init(maxTimes: maxTimes))
122-
122+
123123
let result = Lambda.run(configuration: configuration, handlerType: Handler.self)
124124
assertLambdaLifecycleResult(result, shoudHaveRun: maxTimes)
125125
}

Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct FailedHandler: EventLoopLambdaHandler {
3333
public init(_ reason: String) {
3434
self.reason = reason
3535
}
36-
36+
3737
func handle(context: Lambda.Context, event: String) -> EventLoopFuture<Void> {
3838
context.eventLoop.makeFailedFuture(TestError(self.reason))
3939
}

Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift

+30-30
Original file line numberDiff line numberDiff line change
@@ -40,45 +40,45 @@ class CodableLambdaTest: XCTestCase {
4040
struct Handler: EventLoopLambdaHandler {
4141
typealias In = Request
4242
typealias Out = Void
43-
43+
4444
let expected: Request
4545

4646
func handle(context: Lambda.Context, event: Request) -> EventLoopFuture<Void> {
4747
XCTAssertEqual(event, self.expected)
4848
return context.eventLoop.makeSucceededVoidFuture()
4949
}
5050
}
51-
51+
5252
let handler = Handler(expected: request)
5353

5454
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
5555
XCTAssertNoThrow(outputBuffer = try handler.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
5656
XCTAssertNil(outputBuffer)
5757
}
58-
58+
5959
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
6060
func testCodableVoidHandler() {
6161
struct Handler: LambdaHandler {
6262
typealias In = Request
6363
typealias Out = Void
64-
64+
6565
var expected: Request?
66-
66+
6767
init(context: Lambda.InitializationContext) async throws {}
68-
69-
func handle(event: Request, context: Lambda.Context) async throws -> Void {
68+
69+
func handle(event: Request, context: Lambda.Context) async throws {
7070
XCTAssertEqual(event, self.expected)
7171
}
7272
}
73-
73+
7474
XCTAsyncTest {
7575
let request = Request(requestId: UUID().uuidString)
7676
var inputBuffer: ByteBuffer?
7777
var outputBuffer: ByteBuffer?
78-
78+
7979
var handler = try await Handler(context: self.newInitContext())
8080
handler.expected = request
81-
81+
8282
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
8383
XCTAssertNoThrow(outputBuffer = try handler.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
8484
XCTAssertNil(outputBuffer)
@@ -90,52 +90,52 @@ class CodableLambdaTest: XCTestCase {
9090
var inputBuffer: ByteBuffer?
9191
var outputBuffer: ByteBuffer?
9292
var response: Response?
93-
93+
9494
struct Handler: EventLoopLambdaHandler {
9595
typealias In = Request
9696
typealias Out = Response
97-
97+
9898
let expected: Request
9999

100100
func handle(context: Lambda.Context, event: Request) -> EventLoopFuture<Response> {
101101
XCTAssertEqual(event, self.expected)
102102
return context.eventLoop.makeSucceededFuture(Response(requestId: event.requestId))
103103
}
104104
}
105-
105+
106106
let handler = Handler(expected: request)
107107

108108
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
109109
XCTAssertNoThrow(outputBuffer = try handler.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
110110
XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer)))
111111
XCTAssertEqual(response?.requestId, request.requestId)
112112
}
113-
113+
114114
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
115115
func testCodableHandler() {
116116
struct Handler: LambdaHandler {
117117
typealias In = Request
118118
typealias Out = Response
119-
119+
120120
var expected: Request?
121-
121+
122122
init(context: Lambda.InitializationContext) async throws {}
123-
123+
124124
func handle(event: Request, context: Lambda.Context) async throws -> Response {
125125
XCTAssertEqual(event, self.expected)
126126
return Response(requestId: event.requestId)
127127
}
128128
}
129-
129+
130130
XCTAsyncTest {
131131
let request = Request(requestId: UUID().uuidString)
132132
var response: Response?
133133
var inputBuffer: ByteBuffer?
134134
var outputBuffer: ByteBuffer?
135-
135+
136136
var handler = try await Handler(context: self.newInitContext())
137137
handler.expected = request
138-
138+
139139
XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
140140
XCTAssertNoThrow(outputBuffer = try handler.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
141141
XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer)))
@@ -155,7 +155,7 @@ class CodableLambdaTest: XCTestCase {
155155
eventLoop: self.eventLoopGroup.next(),
156156
allocator: ByteBufferAllocator())
157157
}
158-
158+
159159
func newInitContext() -> Lambda.InitializationContext {
160160
Lambda.InitializationContext(logger: Logger(label: "test"),
161161
eventLoop: self.eventLoopGroup.next(),
@@ -177,23 +177,23 @@ private struct Response: Codable, Equatable {
177177
}
178178
}
179179

180-
public extension XCTestCase {
180+
extension XCTestCase {
181181
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
182-
func XCTAsyncTest(
182+
public func XCTAsyncTest(
183183
expectationDescription: String = "Async operation",
184184
timeout: TimeInterval = 3,
185185
file: StaticString = #file,
186186
line: Int = #line,
187-
operation: @escaping () async throws -> ()
187+
operation: @escaping () async throws -> Void
188188
) {
189189
let expectation = self.expectation(description: expectationDescription)
190190
Task {
191-
do { try await operation() }
192-
catch {
193-
XCTFail("Error thrown while executing async function @ \(file):\(line): \(error)")
194-
Thread.callStackSymbols.forEach{print($0)}
195-
}
196-
expectation.fulfill()
191+
do { try await operation() }
192+
catch {
193+
XCTFail("Error thrown while executing async function @ \(file):\(line): \(error)")
194+
Thread.callStackSymbols.forEach { print($0) }
195+
}
196+
expectation.fulfill()
197197
}
198198
self.wait(for: [expectation], timeout: timeout)
199199
}

Tests/AWSLambdaTestingTests/Tests.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class LambdaTestingTests: XCTestCase {
2828
struct Response: Codable {
2929
let message: String
3030
}
31-
31+
3232
struct MyLambda: LambdaHandler {
3333
typealias In = Request
3434
typealias Out = Response
35-
35+
3636
init(context: Lambda.InitializationContext) {}
37-
37+
3838
func handle(event: Request, context: Lambda.Context) async throws -> Response {
3939
Response(message: "echo" + event.name)
4040
}
@@ -56,9 +56,9 @@ class LambdaTestingTests: XCTestCase {
5656
struct MyLambda: LambdaHandler {
5757
typealias In = Request
5858
typealias Out = Void
59-
59+
6060
init(context: Lambda.InitializationContext) {}
61-
61+
6262
func handle(event: Request, context: Lambda.Context) async throws {
6363
LambdaTestingTests.VoidLambdaHandlerInvokeCount += 1
6464
}
@@ -72,13 +72,13 @@ class LambdaTestingTests: XCTestCase {
7272

7373
func testInvocationFailure() {
7474
struct MyError: Error {}
75-
75+
7676
struct MyLambda: LambdaHandler {
7777
typealias In = String
7878
typealias Out = Void
79-
79+
8080
init(context: Lambda.InitializationContext) {}
81-
81+
8282
func handle(event: String, context: Lambda.Context) async throws {
8383
throw MyError()
8484
}
@@ -93,9 +93,9 @@ class LambdaTestingTests: XCTestCase {
9393
struct MyLambda: LambdaHandler {
9494
typealias In = String
9595
typealias Out = String
96-
96+
9797
init(context: Lambda.InitializationContext) {}
98-
98+
9999
func handle(event: String, context: Lambda.Context) async throws -> String {
100100
try await Task.sleep(nanoseconds: 500 * 1000 * 1000)
101101
return event

0 commit comments

Comments
 (0)