Skip to content

Commit

Permalink
add tests for event reference
Browse files Browse the repository at this point in the history
  • Loading branch information
ekneg54 committed Jul 10, 2024
1 parent b991148 commit 8ffde32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 9 additions & 4 deletions logprep/abc/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(self, name: str, configuration: "Processor.Config"):
specific_rules_targets=self._config.specific_rules,
)
self.has_custom_tests = False
self.result = ProcessorResult(processor_name=self.name)
self.result = None

@property
def _specific_rules(self):
Expand Down Expand Up @@ -187,15 +187,20 @@ def metric_labels(self) -> dict:
"name": self.name,
}

def process(self, event: dict):
"""Process a log event by calling the implemented `process` method of the
strategy object set in `_strategy` attribute.
def process(self, event: dict) -> ProcessorResult:
"""Process a log event.
Parameters
----------
event : dict
A dictionary representing a log event.
Returns
-------
ProcessorResult
A ProcessorResult object containing the processed event, errors,
extra data and a list of target outputs.
"""
self.result = ProcessorResult(processor_name=self.name, event=event)
logger.debug(f"{self.describe()} processing event {event}")
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/processor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,7 @@ def test_process_collects_errors_in_result_object(self):
):
result = self.object.process(self.match_all_event)
assert len(result.errors) > 0, "minimum one error should be in result object"

def test_result_object_has_reference_to_event(self):
result = self.object.process(self.match_all_event)
assert result.event is self.match_all_event

0 comments on commit 8ffde32

Please sign in to comment.