Skip to content

Commit 38cc01a

Browse files
authored
[example] Update testing doc for clarity and remove some typos (#445)
1 parent 38d9e43 commit 38cc01a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Examples/Testing/README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ In this document, we describe four different testing strategies:
1010
* [Local invocation using the AWS SAM CLI](#local-invocation-using-the-aws-sam-cli)
1111

1212
> [!IMPORTANT]
13-
> In this example, the API Gateway sends a payload to the Lambda function as a JSON string. Your business payload is in the `body` section of the API Gateway payload. It is base64-encoded. You can find an example of the API Gateway payload in the `event.json` file. The API Gateway event format is documented in [Create AWS Lambda proxy integrations for HTTP APIs in API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html).
13+
> In this example, the API Gateway sends an event to your Lambda function as a JSON string. Your business payload is in the `body` section of the API Gateway event. It is base64-encoded. You can find an example of the API Gateway event in the `event.json` file. The API Gateway event format is documented in [Create AWS Lambda proxy integrations for HTTP APIs in API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html).
1414
1515
To include a sample event in your test targets, you must add the `event.json` file from the `Tests` directory to the binary bundle. To do so, add a `resources` section in your `Package.swift` file:
1616

@@ -47,7 +47,8 @@ class BusinessTests {
4747
let expectedOutput = arg.1
4848
#expect(input.uppercasedFirst() == expectedOutput)
4949
}
50-
}```
50+
}
51+
```
5152

5253
2. Add a test target to your `Package.swift` file.
5354
```swift
@@ -62,7 +63,7 @@ class BusinessTests {
6263

6364
## Integration Testing the handler function
6465

65-
You can test the handler function by creating an input event, a mock Lambda context, and calling the handler function from your test.
66+
You can test the handler function by creating an input event, a mock Lambda context, and calling your Lambda handler function from your test.
6667
Your Lambda handler function must be declared separatly from the `LambdaRuntime`. For example:
6768

6869
```swift
@@ -131,9 +132,9 @@ public struct HandlerTest {
131132

132133
You can test your Lambda function locally by invoking it with the Swift AWS Lambda Runtime.
133134

134-
You must pass a payload to the Lambda function. You can use the `Tests/event.json` file for this purpose. The return value is a `APIGatewayV2Response` object in this example.
135+
You must pass an event to the Lambda function. You can use the `Tests/event.json` file for this purpose. The return value is a `APIGatewayV2Response` object in this example.
135136

136-
Just type `swift run` to run the Lambda function locally.
137+
Just type `swift run` to run the Lambda function locally, this starts a local HTTP endpoint on localhost:7000.
137138

138139
```sh
139140
LOG_LEVEL=trace swift run
@@ -151,9 +152,9 @@ This returns the following response:
151152

152153
## Local invocation using the AWS SAM CLI
153154

154-
The AWS SAM CLI provides you with a local testing environment for your Lambda functions. It deploys and invoke your function locally in a Docker container designed to mimic the AWS Lambda environment.
155+
The AWS SAM CLI provides you with a local testing environment for your Lambda functions. It deploys and invokes your function locally in a Docker container designed to mimic the AWS Lambda environment.
155156

156-
You must pass a payload to the Lambda function. You can use the `event.json` file for this purpose. The return value is a `APIGatewayV2Response` object in this example.
157+
You must pass an event to the Lambda function. You can use the `event.json` file for this purpose. The return value is a `APIGatewayV2Response` object in this example.
157158

158159
```sh
159160
sam local invoke -e Tests/event.json
@@ -167,4 +168,4 @@ END RequestId: 5b71587a-39da-445e-855d-27a700e57efd
167168
REPORT RequestId: 5b71587a-39da-445e-855d-27a700e57efd Init Duration: 0.04 ms Duration: 21.57 ms Billed Duration: 22 ms Memory Size: 512 MB Max Memory Used: 512 MB
168169

169170
{"body": "Hello world of swift lambda!", "statusCode": 200, "headers": {"content-type": "application/json"}}
170-
```
171+
```

0 commit comments

Comments
 (0)