Skip to content

Commit 117e483

Browse files
author
Riley Priddle
committed
updated test case to cover process
1 parent fb9eaca commit 117e483

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

firetail_lambda/__init__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@
44
def firetail_handler(enable_sleeper=False):
55
def decorator(func):
66
def wrapper_func(*args, **kwargs):
7-
compatible = True
87
start_time = time.time()
98

109
# make sure it is a valid handler function
1110
if len(args) < 2:
12-
compatible = False
13-
if compatible:
14-
# Unpack the args
15-
event, _ = args
11+
return func(*args, **kwargs)
12+
13+
# Unpack the args
14+
event, _ = args
1615

1716
# Get the response returned down the chain
1817
response = func(*args, **kwargs)
1918

2019
# Create our log payload, and print it
21-
if compatible:
22-
log_payload = base64.b64encode(json.dumps({"event": event,"response": response}).encode("utf-8")).decode("ascii")
23-
print("firetail:loggingapi:%s" % (log_payload))
20+
log_payload = base64.b64encode(json.dumps({"event": event,"response": response}).encode("utf-8")).decode("ascii")
21+
print("firetail:loggingapi:%s" % (log_payload))
2422

2523
## Ensure the execution time is >25ms to give the logs API time to propagate our print() to the extension.
26-
if enable_sleeper and compatible:
24+
if enable_sleeper:
2725
time.sleep(max(time.time() - start_time + 500/1000, 0))
2826

2927
# Return the response from down the chain

tests/test_firetail.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unittest
2+
import json
3+
import contextlib
4+
from io import StringIO
5+
6+
from firetail_lambda import firetail_handler
7+
8+
class TestSimple(unittest.TestCase):
9+
10+
def test_handler_api(self):
11+
event = {}
12+
@firetail_handler()
13+
def handler(event, context):
14+
return 201, json.dumps({"message": "success"})
15+
16+
temp_stdout = StringIO()
17+
with contextlib.redirect_stdout(temp_stdout):
18+
handler(event, "")
19+
output = temp_stdout.getvalue().strip()
20+
self.assertEqual(output, 'firetail:loggingapi:eyJldmVudCI6IHt9LCAicmVzcG9uc2UiOiBbMjAxLCAie1wibWVzc2FnZVwiOiBcInN1Y2Nlc3NcIn0iXX0=')
21+
22+
23+
if __name__ == '__main__':
24+
unittest.main()

tests/test_module1.py

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

0 commit comments

Comments
 (0)