File tree Expand file tree Collapse file tree 3 files changed +31
-20
lines changed Expand file tree Collapse file tree 3 files changed +31
-20
lines changed Original file line number Diff line number Diff line change 4
4
def firetail_handler (enable_sleeper = False ):
5
5
def decorator (func ):
6
6
def wrapper_func (* args , ** kwargs ):
7
- compatible = True
8
7
start_time = time .time ()
9
8
10
9
# make sure it is a valid handler function
11
10
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
16
15
17
16
# Get the response returned down the chain
18
17
response = func (* args , ** kwargs )
19
18
20
19
# 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 ))
24
22
25
23
## 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 :
27
25
time .sleep (max (time .time () - start_time + 500 / 1000 , 0 ))
28
26
29
27
# Return the response from down the chain
Original file line number Diff line number Diff line change
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 ()
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments