Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ekneg54 committed Mar 7, 2023
1 parent 05385c1 commit fbb55d0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
6 changes: 3 additions & 3 deletions logprep/framework/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ def _setup(self):
try:
output.setup()
except FatalOutputError as error:
self._logger.error(f"Output {self._output.describe()} failed: {error}")
self._output.metrics.number_of_errors += 1
self._logger.error(f"Output {output.describe()} failed: {error}")
output.metrics.number_of_errors += 1
self.stop()
if hasattr(self._input, "server"):
while self._input.server.config.port in self._used_server_ports:
Expand Down Expand Up @@ -389,7 +389,7 @@ def _get_event(self) -> dict:
event, non_critical_error_msg = self._input.get_next(
self._logprep_config.get("timeout")
)
if non_critical_error_msg:
if non_critical_error_msg and self._output:
for _, output in self._output.items():
if output.default:
output.store_failed(non_critical_error_msg, event, None)
Expand Down
4 changes: 2 additions & 2 deletions logprep/util/auto_rule_tester/auto_rule_corpus_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ def _align_extra_output_formats(self, extra_outputs):
if isinstance(extra_output, tuple):
documents, target = extra_output
for document in documents:
reformatted_extra_outputs.append({target: document})
reformatted_extra_outputs.append({str(target): document})
else:
for output in extra_output:
reformatted_extra_outputs.append({output[1]: output[0][0]})
reformatted_extra_outputs.append({str(output[1]): output[0][0]})
return reformatted_extra_outputs

def _compare_logprep_outputs(self, test_case_id, logprep_output):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/framework/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def test_processor_fatal_output_error_is_logged_pipeline_is_rebuilt(
def test_processor_fatal_output_error_in_setup_is_logged_pipeline_is_rebuilt(
self, mock_error, _
):
self.pipeline._output = mock.MagicMock()
self.pipeline._output = {"dummy": mock.MagicMock()}
self.pipeline._output["dummy"].setup.side_effect = FatalOutputError
self.pipeline.run()
mock_error.assert_called()
Expand Down Expand Up @@ -707,7 +707,7 @@ def test_pipeline_hmac_error_message_without_output_connector(self):
}
pipeline = Pipeline(config=self.config)
assert pipeline._output is None
event, extra_outputs = pipeline.process_pipeline()
event, _ = pipeline.process_pipeline()
assert event["hmac"]["hmac"] == "error"

def test_pipeline_run_raises_assertion_when_run_without_input(self):
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/util/test_auto_rule_corpus_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class TestAutoRuleTester:
"expected_output": {"winlog": {"event_data": {"IpAddress": "<IGNORE_VALUE>"}}},
"expected_extra_output": [
{
"pseudonyms": {
"({'kafka_output': 'pseudonyms'},)": {
"pseudonym": "<IGNORE_VALUE>",
"origin": "<IGNORE_VALUE>",
}
Expand Down Expand Up @@ -396,9 +396,14 @@ def test_run_with_two_processors_that_have_different_extra_outputs(
"winlog": {"event_id": "2222", "event_data": {"IpAddress": "<IGNORE_VALUE>"}},
},
"expected_extra_output": [
{"test_specific_topic": {"field1": "field 1 value"}},
{"test_specific_topic": {"message": "something"}},
{"pseudonyms": {"origin": "<IGNORE_VALUE>", "pseudonym": "<IGNORE_VALUE>"}},
{"({'kafka': 'topic'},)": {"field1": "field 1 value"}},
{"({'kafka': 'topic'},)": {"message": "something"}},
{
"({'kafka_output': 'pseudonyms'},)": {
"origin": "<IGNORE_VALUE>",
"pseudonym": "<IGNORE_VALUE>",
}
},
],
}
expected_prints = [
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/util/test_rule_dry_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def setup_method(self):
config = """
process_count: 1
timeout: 0.1
pipeline:
- normalizer:
type: normalizer
Expand All @@ -39,7 +38,7 @@ def setup_method(self):
regex_mapping: tests/testdata/unit/pseudonymizer/rules/regex_mapping.yml
hash_salt: a_secret_tasty_ingredient
outputs:
- jsonl_output: pseudonyms
- patched_output: pseudonyms
specific_rules:
- tests/testdata/unit/pseudonymizer/rules/specific/
generic_rules:
Expand All @@ -53,7 +52,7 @@ def setup_method(self):
generic_rules:
- tests/testdata/unit/pre_detector/rules/generic/
outputs:
- jsonl_output: sre_topic
- patched_output: sre_topic
"""
self.config_path = os.path.join(tempfile.gettempdir(), "dry-run-config.yml")
with open(self.config_path, "w", encoding="utf8") as config_file:
Expand Down

0 comments on commit fbb55d0

Please sign in to comment.