14
14
LambdaRuntimeClientError ,
15
15
_user_agent ,
16
16
)
17
+ from awslambdaric .lambda_runtime_marshaller import to_json
17
18
18
19
19
20
class TestInvocationRequest (unittest .TestCase ):
@@ -99,6 +100,15 @@ def test_wait_next_invocation(self, mock_runtime_client):
99
100
self .assertEqual (event_request .content_type , "application/json" )
100
101
self .assertEqual (event_request .event_body , response_body )
101
102
103
+ error_result = {
104
+ "errorMessage" : "Dummy message" ,
105
+ "errorType" : "Runtime.DummyError" ,
106
+ "requestId" : "" ,
107
+ "stackTrace" : [],
108
+ }
109
+
110
+ headers = {"Lambda-Runtime-Function-Error-Type" : error_result ["errorType" ]}
111
+
102
112
@patch ("http.client.HTTPConnection" , autospec = http .client .HTTPConnection )
103
113
def test_post_init_error (self , MockHTTPConnection ):
104
114
mock_conn = MockHTTPConnection .return_value
@@ -108,11 +118,14 @@ def test_post_init_error(self, MockHTTPConnection):
108
118
mock_response .code = http .HTTPStatus .ACCEPTED
109
119
110
120
runtime_client = LambdaRuntimeClient ("localhost:1234" )
111
- runtime_client .post_init_error ("error_data" )
121
+ runtime_client .post_init_error (self . error_result )
112
122
113
123
MockHTTPConnection .assert_called_with ("localhost:1234" )
114
124
mock_conn .request .assert_called_once_with (
115
- "POST" , "/2018-06-01/runtime/init/error" , "error_data"
125
+ "POST" ,
126
+ "/2018-06-01/runtime/init/error" ,
127
+ to_json (self .error_result ),
128
+ headers = self .headers ,
116
129
)
117
130
mock_response .read .assert_called_once ()
118
131
@@ -127,7 +140,7 @@ def test_post_init_error_non_accepted_status_code(self, MockHTTPConnection):
127
140
runtime_client = LambdaRuntimeClient ("localhost:1234" )
128
141
129
142
with self .assertRaises (LambdaRuntimeClientError ) as cm :
130
- runtime_client .post_init_error ("error_data" )
143
+ runtime_client .post_init_error (self . error_result )
131
144
returned_exception = cm .exception
132
145
133
146
self .assertEqual (returned_exception .endpoint , "/2018-06-01/runtime/init/error" )
@@ -215,12 +228,12 @@ def test_post_invocation_error_with_too_large_xray_cause(self, mock_runtime_clie
215
228
def test_connection_refused (self ):
216
229
with self .assertRaises (ConnectionRefusedError ):
217
230
runtime_client = LambdaRuntimeClient ("127.0.0.1:1" )
218
- runtime_client .post_init_error ("error" )
231
+ runtime_client .post_init_error (self . error_result )
219
232
220
233
def test_invalid_addr (self ):
221
234
with self .assertRaises (OSError ):
222
235
runtime_client = LambdaRuntimeClient ("::::" )
223
- runtime_client .post_init_error ("error" )
236
+ runtime_client .post_init_error (self . error_result )
224
237
225
238
def test_lambdaric_version (self ):
226
239
self .assertTrue (_user_agent ().endswith (__version__ ))
0 commit comments