Skip to content

Commit c2361a3

Browse files
authored
Fix aws lambda tests (by reducing event size) (#3770)
Our AWS Lambda tests rely on outputting our events as JSON to stdout and parsing this output. AWS Lambda limits the amount of stdout it returns. So by reducing the size of the events we can fix the tests, that where broken by printing to much data to stdout so the output is truncated and can not be parsed into actual JSON structures again.
1 parent 417be9f commit c2361a3

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

tests/integrations/aws_lambda/test_aws.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def truncate_data(data):
9898
elif key == "cloudwatch logs":
9999
for cloudwatch_key in data["extra"]["cloudwatch logs"].keys():
100100
if cloudwatch_key in ["url", "log_group", "log_stream"]:
101-
cleaned_data["extra"].setdefault("cloudwatch logs", {})[cloudwatch_key] = data["extra"]["cloudwatch logs"][cloudwatch_key]
101+
cleaned_data["extra"].setdefault("cloudwatch logs", {})[cloudwatch_key] = data["extra"]["cloudwatch logs"][cloudwatch_key].split("=")[0]
102102
103103
if data.get("level") is not None:
104104
cleaned_data["level"] = data.get("level")
@@ -228,7 +228,7 @@ def test_handler(event, context):
228228
assert event["extra"]["lambda"]["function_name"].startswith("test_")
229229

230230
logs_url = event["extra"]["cloudwatch logs"]["url"]
231-
assert logs_url.startswith("https://console.aws.amazon.com/cloudwatch/home?region=")
231+
assert logs_url.startswith("https://console.aws.amazon.com/cloudwatch/home?region")
232232
assert not re.search("(=;|=$)", logs_url)
233233
assert event["extra"]["cloudwatch logs"]["log_group"].startswith(
234234
"/aws/lambda/test_"
@@ -370,7 +370,7 @@ def test_handler(event, context):
370370
assert event["extra"]["lambda"]["function_name"].startswith("test_")
371371

372372
logs_url = event["extra"]["cloudwatch logs"]["url"]
373-
assert logs_url.startswith("https://console.aws.amazon.com/cloudwatch/home?region=")
373+
assert logs_url.startswith("https://console.aws.amazon.com/cloudwatch/home?region")
374374
assert not re.search("(=;|=$)", logs_url)
375375
assert event["extra"]["cloudwatch logs"]["log_group"].startswith(
376376
"/aws/lambda/test_"
@@ -462,23 +462,23 @@ def test_handler(event, context):
462462
"X-Forwarded-Proto": "https"
463463
},
464464
"httpMethod": "GET",
465-
"path": "/path1",
465+
"path": "/1",
466466
"queryStringParameters": {
467-
"done": "false"
467+
"done": "f"
468468
},
469-
"dog": "Maisey"
469+
"d": "D1"
470470
},
471471
{
472472
"headers": {
473473
"Host": "x2.io",
474474
"X-Forwarded-Proto": "http"
475475
},
476476
"httpMethod": "POST",
477-
"path": "/path2",
477+
"path": "/2",
478478
"queryStringParameters": {
479-
"done": "true"
479+
"done": "t"
480480
},
481-
"dog": "Charlie"
481+
"d": "D2"
482482
}
483483
]
484484
""",
@@ -538,9 +538,9 @@ def test_handler(event, context):
538538
request_data = {
539539
"headers": {"Host": "x1.io", "X-Forwarded-Proto": "https"},
540540
"method": "GET",
541-
"url": "https://x1.io/path1",
541+
"url": "https://x1.io/1",
542542
"query_string": {
543-
"done": "false",
543+
"done": "f",
544544
},
545545
}
546546
else:

0 commit comments

Comments
 (0)