Skip to content

Commit 27511ec

Browse files
committed
swift format
1 parent cac72a6 commit 27511ec

File tree

5 files changed

+39
-41
lines changed

5 files changed

+39
-41
lines changed

Examples/Testing/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ let package = Package(
3232
resources: [
3333
.process("event.json")
3434
]
35-
)
35+
),
3636
]
3737
)
3838

Examples/Testing/Sources/Business.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
//===----------------------------------------------------------------------===//
32
//
43
// This source file is part of the SwiftAWSLambdaRuntime open source project
@@ -31,4 +30,4 @@ extension String {
3130
let remainingCharacters = dropFirst().lowercased()
3231
return firstCharacter + remainingCharacters
3332
}
34-
}
33+
}

Examples/Testing/Sources/main.swift

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,28 @@ import AWSLambdaRuntime
1919
import FoundationEssentials
2020
#else
2121
import Foundation
22-
#endif
22+
#endif
2323

2424
public struct MyHandler: Sendable {
2525

2626
public func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response {
27-
context.logger.debug("HTTP API Message received")
28-
context.logger.trace("Event: \(event)")
29-
30-
var header = HTTPHeaders()
31-
header["content-type"] = "application/json"
32-
33-
// API Gateway sends text or URL encoded data as a Base64 encoded string
34-
if let base64EncodedString = event.body,
35-
let decodedData = Data(base64Encoded: base64EncodedString),
36-
let decodedString = String(data: decodedData, encoding: .utf8) {
37-
38-
// call our business code to process the payload and return a response
39-
return APIGatewayV2Response(statusCode: .ok, headers: header, body: decodedString.uppercasedFirst())
40-
} else {
41-
return APIGatewayV2Response(statusCode: .badRequest)
42-
}
27+
context.logger.debug("HTTP API Message received")
28+
context.logger.trace("Event: \(event)")
29+
30+
var header = HTTPHeaders()
31+
header["content-type"] = "application/json"
32+
33+
// API Gateway sends text or URL encoded data as a Base64 encoded string
34+
if let base64EncodedString = event.body,
35+
let decodedData = Data(base64Encoded: base64EncodedString),
36+
let decodedString = String(data: decodedData, encoding: .utf8)
37+
{
38+
39+
// call our business code to process the payload and return a response
40+
return APIGatewayV2Response(statusCode: .ok, headers: header, body: decodedString.uppercasedFirst())
41+
} else {
42+
return APIGatewayV2Response(statusCode: .badRequest)
43+
}
4344
}
4445
}
4546

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
//===----------------------------------------------------------------------===//
32
//
43
// This source file is part of the SwiftAWSLambdaRuntime open source project
@@ -15,27 +14,27 @@
1514

1615
import Testing
1716

18-
@testable import APIGatewayLambda // to access the business code
17+
@testable import APIGatewayLambda // to access the business code
1918

2019
let valuesToTest: [(String, String)] = [
21-
("hello world", "Hello world"), // happy path
22-
("", ""), // Empty string
23-
("a", "A"), // Single character
24-
("A", "A"), // Single uppercase character
25-
("HELLO WORLD", "Hello world"), // All uppercase
26-
("hello world", "Hello world"), // All lowercase
27-
("hElLo WoRlD", "Hello world"), // Mixed case
28-
("123abc", "123abc"), // Numeric string
29-
("!@#abc", "!@#abc") // Special characters
20+
("hello world", "Hello world"), // happy path
21+
("", ""), // Empty string
22+
("a", "A"), // Single character
23+
("A", "A"), // Single uppercase character
24+
("HELLO WORLD", "Hello world"), // All uppercase
25+
("hello world", "Hello world"), // All lowercase
26+
("hElLo WoRlD", "Hello world"), // Mixed case
27+
("123abc", "123abc"), // Numeric string
28+
("!@#abc", "!@#abc"), // Special characters
3029
]
3130

3231
@Suite("Business Tests")
3332
class BusinessTests {
3433

3534
@Test("Uppercased First", arguments: valuesToTest)
36-
func uppercasedFirst(_ arg: (String,String)) {
35+
func uppercasedFirst(_ arg: (String, String)) {
3736
let input = arg.0
3837
let expectedOutput = arg.1
3938
#expect(input.uppercasedFirst() == expectedOutput)
4039
}
41-
}
40+
}

Examples/Testing/Tests/HandlerTests.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,25 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import Testing
16-
1715
import AWSLambdaEvents
1816
import AWSLambdaRuntime
1917
import Logging
18+
import Testing
2019

21-
@testable import APIGatewayLambda // to access the business code
20+
@testable import APIGatewayLambda // to access the business code
2221

2322
#if canImport(FoundationEssentials)
2423
import FoundationEssentials
2524
#else
2625
import Foundation
27-
#endif
26+
#endif
2827

2928
@Suite("Handler Tests")
3029
public struct HandlerTest {
3130

3231
@Test("Invoke handler")
3332
public func invokeHandler() async throws {
34-
33+
3534
// read event.json file
3635
let testBundle = Bundle.module
3736
guard let eventURL = testBundle.url(forResource: "event", withExtension: "json") else {
@@ -42,8 +41,8 @@ public struct HandlerTest {
4241

4342
// decode the event
4443
let apiGatewayRequest = try JSONDecoder().decode(APIGatewayV2Request.self, from: eventData)
45-
46-
// create a mock LambdaContext
44+
45+
// create a mock LambdaContext
4746
let lambdaContext = LambdaContext.__forTestsOnly(
4847
requestID: UUID().uuidString,
4948
traceID: UUID().uuidString,
@@ -59,4 +58,4 @@ public struct HandlerTest {
5958
#expect(response.statusCode == .ok)
6059
#expect(response.body == "Hello world of swift lambda!")
6160
}
62-
}
61+
}

0 commit comments

Comments
 (0)