Skip to content

Commit

Permalink
Caroline Gilbert: fixed tests - all pass
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinecgilbert committed Mar 31, 2024
1 parent 12a4035 commit 097be29
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from unittest.mock import Mock
from handlers.opentelemetry_structlog.src.exporter import LogExporter
from datetime import datetime, timezone
from unittest.mock import MagicMock




Expand Down Expand Up @@ -224,6 +226,9 @@ class TestStructlogHandler(TestBase):
@pytest.fixture(autouse=True)
def inject_fixtures(self, caplog):
self.caplog = caplog # pylint: disable=attribute-defined-outside-init

def mocker(self):
return MagicMock()

def setUp(self):
super().setUp()
Expand Down Expand Up @@ -276,15 +281,22 @@ def test_parse_timestamp(self):
expected_timestamp = 1577836800000000000 # Expected nanoseconds since epoch
assert timestamp == expected_timestamp, "Timestamp should be correctly parsed to nanoseconds"

def test_call_method_processes_log_correctly(self, mocker):
exporter_instance = self.structlog_exporter()
mocker.patch.object(exporter_instance._logger, 'emit')
def test_call_method2(self):
# Mock the logger and exporter
exporter = MagicMock()
logger = MagicMock()
exporter_instance = StructlogHandler("test_service", "test_host", exporter)
exporter_instance._logger = logger

# Define an event dictionary
event_dict = {"level": "info", "event": "test event", "timestamp": datetime.now(timezone.utc)}
processed_event = exporter_instance.emit(logger=None, name=None, event_dict=event_dict)

exporter_instance._logger.emit.assert_called_once()
assert "timestamp" in processed_event, "Processed event should contain a timestamp"
# Add more assertions based on expected transformations and processing outcomes
# Call the __call__ method of StructlogHandler
processed_event = exporter_instance(logger=None, name=None, event_dict=event_dict)

# Assert that the logger's emit method was called with the processed event
logger.emit.assert_called_once()




0 comments on commit 097be29

Please sign in to comment.