1414 LambdaRuntimeClientError ,
1515 _user_agent ,
1616)
17+ from awslambdaric .lambda_runtime_marshaller import to_json
1718
1819
1920class TestInvocationRequest (unittest .TestCase ):
@@ -99,6 +100,15 @@ def test_wait_next_invocation(self, mock_runtime_client):
99100 self .assertEqual (event_request .content_type , "application/json" )
100101 self .assertEqual (event_request .event_body , response_body )
101102
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+
102112 @patch ("http.client.HTTPConnection" , autospec = http .client .HTTPConnection )
103113 def test_post_init_error (self , MockHTTPConnection ):
104114 mock_conn = MockHTTPConnection .return_value
@@ -108,11 +118,14 @@ def test_post_init_error(self, MockHTTPConnection):
108118 mock_response .code = http .HTTPStatus .ACCEPTED
109119
110120 runtime_client = LambdaRuntimeClient ("localhost:1234" )
111- runtime_client .post_init_error ("error_data" )
121+ runtime_client .post_init_error (self . error_result )
112122
113123 MockHTTPConnection .assert_called_with ("localhost:1234" )
114124 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 ,
116129 )
117130 mock_response .read .assert_called_once ()
118131
@@ -127,7 +140,7 @@ def test_post_init_error_non_accepted_status_code(self, MockHTTPConnection):
127140 runtime_client = LambdaRuntimeClient ("localhost:1234" )
128141
129142 with self .assertRaises (LambdaRuntimeClientError ) as cm :
130- runtime_client .post_init_error ("error_data" )
143+ runtime_client .post_init_error (self . error_result )
131144 returned_exception = cm .exception
132145
133146 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
215228 def test_connection_refused (self ):
216229 with self .assertRaises (ConnectionRefusedError ):
217230 runtime_client = LambdaRuntimeClient ("127.0.0.1:1" )
218- runtime_client .post_init_error ("error" )
231+ runtime_client .post_init_error (self . error_result )
219232
220233 def test_invalid_addr (self ):
221234 with self .assertRaises (OSError ):
222235 runtime_client = LambdaRuntimeClient ("::::" )
223- runtime_client .post_init_error ("error" )
236+ runtime_client .post_init_error (self . error_result )
224237
225238 def test_lambdaric_version (self ):
226239 self .assertTrue (_user_agent ().endswith (__version__ ))
0 commit comments