-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: sachintendulkar576123 <[email protected]>
- Loading branch information
1 parent
f422fba
commit c49a5f6
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
import datetime | ||
from monocle_apptrace.exporters.aws.s3_exporter import S3SpanExporter | ||
|
||
class TestS3SpanExporter(unittest.TestCase): | ||
@patch('boto3.client') | ||
def test_file_prefix_in_file_name(self, mock_boto_client): | ||
# Mock S3 client | ||
mock_s3_client = MagicMock() | ||
mock_boto_client.return_value = mock_s3_client | ||
|
||
# Instantiate the exporter with a custom prefix | ||
exporter = S3SpanExporter(bucket_name="test-bucket", region_name="us-east-1") | ||
file_prefix = "monocle_trace_" | ||
# Mock current time for consistency | ||
mock_current_time = datetime.datetime(2024, 12, 10, 10, 0, 0) | ||
with patch('datetime.datetime') as mock_datetime: | ||
mock_datetime.now.return_value = mock_current_time | ||
mock_datetime.strftime = datetime.datetime.strftime | ||
|
||
# Call the private method to upload data (we are testing the file naming logic) | ||
test_span_data = "{\"trace_id\": \"123\"}" | ||
exporter._S3SpanExporter__upload_to_s3(test_span_data) | ||
|
||
# Generate expected file name | ||
expected_file_name = f"{file_prefix}{mock_current_time.strftime(exporter.time_format)}.ndjson" | ||
|
||
# Verify the S3 client was called with the correct file name | ||
mock_s3_client.put_object.assert_called_once_with( | ||
Bucket="test-bucket", | ||
Key=expected_file_name, | ||
Body=test_span_data | ||
) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |