Skip to content

Commit 1a82f68

Browse files
added tests for logging if ctx_json is none
1 parent ff6e3c4 commit 1a82f68

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/test_dsm.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,50 @@ def test_get_context_exception_handled(self):
196196
"Unable to set dsm context: JSON parsing error"
197197
)
198198

199+
def test_debug_logging_for_skipped_messages(self):
200+
"""Test debug logging for various scenarios where messages are skipped"""
201+
202+
message_no_attrs = {"messageId": "test-id", "body": "test body"}
203+
204+
result = _get_dsm_context_from_sqs_lambda(message_no_attrs)
205+
206+
assert result is None
207+
self.mock_logger.debug.assert_called_with(
208+
"DataStreams skipped lambda message: %r", message_no_attrs
209+
)
210+
211+
self.mock_logger.reset_mock()
212+
213+
message_no_datadog = {
214+
"messageId": "test-id",
215+
"messageAttributes": {
216+
"other_attr": {"stringValue": "value", "dataType": "String"}
217+
},
218+
}
219+
220+
result = _get_dsm_context_from_sqs_lambda(message_no_datadog)
221+
222+
assert result is None
223+
self.mock_logger.debug.assert_called_with(
224+
"DataStreams skipped lambda message: %r", message_no_datadog
225+
)
226+
227+
self.mock_logger.reset_mock()
228+
229+
message_not_dict = {
230+
"messageId": "test-id",
231+
"messageAttributes": {
232+
"_datadog": {"stringValue": '"just a string"', "dataType": "String"}
233+
},
234+
}
235+
236+
result = _get_dsm_context_from_sqs_lambda(message_not_dict)
237+
238+
assert result is None
239+
self.mock_logger.debug.assert_called_with(
240+
"DataStreams did not handle lambda message: %r", message_not_dict
241+
)
242+
199243

200244
class TestGetDSMContextFromSQS(unittest.TestCase):
201245
def test_sqs_to_lambda_string_value_format(self):

0 commit comments

Comments
 (0)