diff --git a/log_enhancer/tests/test_core.py b/log_enhancer/tests/test_core.py new file mode 100644 index 0000000..e879269 --- /dev/null +++ b/log_enhancer/tests/test_core.py @@ -0,0 +1,70 @@ +import pytest +from typing import List, Dict + +import sys +from pathlib import Path + +import importlib + +# Sicherstellen, dass src im Pfad ist +ROOT = Path(__file__).resolve().parents[1] +sys.path.append(str(ROOT / 'src')) + +# Modulimport +core = importlib.import_module('log_enhancer.core') + + +def test_enhance_log_entries_adds_missing_fields(): + sample_logs: List[Dict] = [ + {"message": "Artifact processed successfully."}, + { + "message": "Missing key.", + "expected_artifact_path": "/data/artifacts/x.json", + }, + ] + + enhanced = core.enhance_log_entries(sample_logs) + + assert isinstance(enhanced, list) + assert all(isinstance(entry, dict) for entry in enhanced) + + for entry in enhanced: + assert 'message' in entry and isinstance(entry['message'], str) + assert 'expected_artifact_path' in entry + assert 'artifact_key' in entry + + # Eingaben, die bereits pfade enthalten, sollten beibehalten werden + for original, result in zip(sample_logs, enhanced): + if 'expected_artifact_path' in original: + assert result['expected_artifact_path'] == original['expected_artifact_path'] + + +def test_enhance_log_entries_preserves_length(): + logs = [{"message": f"msg-{i}"} for i in range(3)] + result = core.enhance_log_entries(logs) + assert len(result) == len(logs) + + +def test_enhance_log_entries_handles_empty_list(): + assert core.enhance_log_entries([]) == [] + + +def test_enhance_log_entries_invalid_input_type(): + with pytest.raises(AssertionError): + core.enhance_log_entries("not a list") + + +def test_enhance_log_entries_field_validation(): + logs = [{"message": None}] # invalid type + with pytest.raises(AssertionError): + core.enhance_log_entries(logs) + + +def test_enhance_log_entries_fills_consistent_values(): + logs = [{"message": "Processing unknown artifact."}] + result = core.enhance_log_entries(logs) + + entry = result[0] + assert entry['message'] == "Processing unknown artifact." + assert entry['expected_artifact_path'].startswith("/unknown/") or entry['expected_artifact_path'] != '' + assert len(entry['artifact_key']) > 0 \ No newline at end of file