Skip to content

Commit 39b42fc

Browse files
add wanted tests
1 parent 554d7b4 commit 39b42fc

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/test_tracing.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,6 +2660,76 @@ def test_sns_event_with_datadog_message_attributes(
26602660
)
26612661
self.assertEqual(result, mock_context)
26622662

2663+
@patch("datadog_lambda.tracing._extract_context_with_data_streams")
2664+
def test_sqs_event_determines_is_sqs_true_when_event_source_arn_present(
2665+
self, mock_extract_context_with_data_streams
2666+
):
2667+
"""Test that is_sqs = True when eventSourceARN is present in first record"""
2668+
dd_data = {"dd-pathway-ctx-base64": "12345"}
2669+
dd_json_data = json.dumps(dd_data)
2670+
2671+
event = {
2672+
"Records": [
2673+
{
2674+
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:test-queue",
2675+
"messageAttributes": {
2676+
"_datadog": {"dataType": "String", "stringValue": dd_json_data}
2677+
},
2678+
}
2679+
]
2680+
}
2681+
2682+
mock_context = Context(trace_id=12345, span_id=67890, sampling_priority=1)
2683+
mock_extract_context_with_data_streams.return_value = mock_context
2684+
2685+
result = extract_context_from_sqs_or_sns_event_or_context(
2686+
event, self.lambda_context
2687+
)
2688+
2689+
mock_extract_context_with_data_streams.assert_called_once_with(
2690+
dd_data, "sqs", "arn:aws:sqs:us-east-1:123456789012:test-queue"
2691+
)
2692+
self.assertEqual(result, mock_context)
2693+
2694+
@patch("datadog_lambda.tracing._extract_context_with_data_streams")
2695+
def test_sns_to_sqs_event_detection_and_processing(
2696+
self, mock_extract_context_with_data_streams
2697+
):
2698+
"""Test SNS->SQS case where SQS body contains SNS notification"""
2699+
dd_data = {"dd-pathway-ctx-base64": "12345"}
2700+
dd_json_data = json.dumps(dd_data)
2701+
2702+
sns_notification = {
2703+
"Type": "Notification",
2704+
"TopicArn": "arn:aws:sns:us-east-1:123456789012:test-topic",
2705+
"MessageAttributes": {
2706+
"_datadog": {"Type": "String", "Value": dd_json_data}
2707+
},
2708+
"Message": "test message",
2709+
}
2710+
2711+
event = {
2712+
"Records": [
2713+
{
2714+
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:test-queue",
2715+
"body": json.dumps(sns_notification),
2716+
"messageAttributes": {},
2717+
}
2718+
]
2719+
}
2720+
2721+
mock_context = Context(trace_id=12345, span_id=67890, sampling_priority=1)
2722+
mock_extract_context_with_data_streams.return_value = mock_context
2723+
2724+
result = extract_context_from_sqs_or_sns_event_or_context(
2725+
event, self.lambda_context
2726+
)
2727+
2728+
mock_extract_context_with_data_streams.assert_called_once_with(
2729+
dd_data, "sqs", "arn:aws:sqs:us-east-1:123456789012:test-queue"
2730+
)
2731+
self.assertEqual(result, mock_context)
2732+
26632733

26642734
class TestExtractContextFromKinesisEvent(unittest.TestCase):
26652735
def setUp(self):

0 commit comments

Comments
 (0)