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 44def 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
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