Skip to content

Commit deb5700

Browse files
Theobmoffatt
Theo
authored andcommitted
Update alb test data (#158)
resolves #153
1 parent 9281612 commit deb5700

5 files changed

+99
-70
lines changed

events/alb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ package events
44
type ALBTargetGroupRequest struct {
55
HTTPMethod string `json:"httpMethod"`
66
Path string `json:"path"`
7-
QueryStringParameters map[string]string `json:"queryStringParameters"`
8-
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters"`
9-
Headers map[string]string `json:"headers"`
10-
MultiValueHeaders map[string][]string `json:"multiValueHeaders"`
7+
QueryStringParameters map[string]string `json:"queryStringParameters,omitempty"`
8+
MultiValueQueryStringParameters map[string][]string `json:"multiValueQueryStringParameters,omitempty"`
9+
Headers map[string]string `json:"headers,omitempty"`
10+
MultiValueHeaders map[string][]string `json:"multiValueHeaders,omitempty"`
1111
RequestContext ALBTargetGroupRequestContext `json:"requestContext"`
1212
IsBase64Encoded bool `json:"isBase64Encoded"`
1313
Body string `json:"body"`

events/alb_test.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,30 @@ import (
1010
)
1111

1212
func TestALBTargetRequestMarshaling(t *testing.T) {
13-
// read json from file
14-
inputJSON, err := ioutil.ReadFile("./testdata/alb-lambda-target-request.json")
15-
if err != nil {
16-
t.Errorf("could not open test file. details: %v", err)
17-
}
13+
inputFiles := []string{
14+
"./testdata/alb-lambda-target-request-headers-only.json",
15+
"./testdata/alb-lambda-target-request-multivalue-headers.json"}
1816

19-
// de-serialize into Go object
20-
var inputEvent ALBTargetGroupRequest
21-
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
22-
t.Errorf("could not unmarshal event. details: %v", err)
23-
}
17+
for _, filename := range inputFiles {
18+
// read json from file
19+
inputJSON, err := ioutil.ReadFile(filename)
20+
if err != nil {
21+
t.Errorf("could not open test file. details: %v", err)
22+
}
2423

25-
// serialize to json
26-
outputJSON, err := json.Marshal(inputEvent)
27-
if err != nil {
28-
t.Errorf("could not marshal event. details: %v", err)
29-
}
24+
// de-serialize into Go object
25+
var inputEvent ALBTargetGroupRequest
26+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
27+
t.Errorf("could not unmarshal event. details: %v", err)
28+
}
3029

31-
assert.JSONEq(t, string(inputJSON), string(outputJSON))
30+
// serialize to json
31+
outputJSON, err := json.Marshal(inputEvent)
32+
if err != nil {
33+
t.Errorf("could not marshal event. details: %v", err)
34+
}
35+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
36+
}
3237
}
3338

3439
func TestALBTargetRequestMalformedJson(t *testing.T) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"requestContext": {
3+
"elb": {
4+
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/lambda-target/abcdefg"
5+
}
6+
},
7+
"httpMethod": "GET",
8+
"path": "/",
9+
"queryStringParameters": {
10+
"key": "hello"
11+
},
12+
"headers": {
13+
"accept": "*/*",
14+
"connection": "keep-alive",
15+
"host": "lambda-test-alb-1334523864.us-east-1.elb.amazonaws.com",
16+
"user-agent": "curl/7.54.0",
17+
"x-amzn-trace-id": "Root=1-5c34e93e-4dea0086f9763ac0667b115a",
18+
"x-forwarded-for": "25.12.198.67",
19+
"x-forwarded-port": "80",
20+
"x-forwarded-proto": "http",
21+
"x-imforwards": "20",
22+
"x-myheader": "123"
23+
},
24+
"body": "",
25+
"isBase64Encoded": false
26+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"requestContext": {
3+
"elb": {
4+
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/lambda-target/abcdefgh"
5+
}
6+
},
7+
"httpMethod": "GET",
8+
"path": "/",
9+
"multiValueQueryStringParameters": {
10+
"key": [
11+
"hello"
12+
]
13+
},
14+
"multiValueHeaders": {
15+
"accept": [
16+
"*/*"
17+
],
18+
"connection": [
19+
"keep-alive"
20+
],
21+
"host": [
22+
"lambda-test-alb-1234567.us-east-1.elb.amazonaws.com"
23+
],
24+
"user-agent": [
25+
"curl/7.54.0"
26+
],
27+
"x-amzn-trace-id": [
28+
"Root=1-5c34e7d4-00ca239424b68028d4c56d68"
29+
],
30+
"x-forwarded-for": [
31+
"72.21.198.67"
32+
],
33+
"x-forwarded-port": [
34+
"80"
35+
],
36+
"x-forwarded-proto": [
37+
"http"
38+
],
39+
"x-imforwards": [
40+
"20"
41+
],
42+
"x-myheader": [
43+
"123"
44+
]
45+
},
46+
"body": "",
47+
"isBase64Encoded": false
48+
}

events/testdata/alb-lambda-target-request.json

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)