38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""Regression test against real production log samples (Chapter 12): both
|
|
files were provided during development after a real cPanel deployment and
|
|
confirmed to parse cleanly with zero failures against the default
|
|
Combined-format parser. Locked in here so a future change can't silently
|
|
break compatibility with this real-world data.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from app.services.log_parser.apache import combined_parser
|
|
|
|
FIXTURES_DIR = Path(__file__).parent / "fixtures"
|
|
|
|
|
|
def _count_parse_failures(path: Path) -> tuple[int, int]:
|
|
parser = combined_parser()
|
|
total = 0
|
|
failed = 0
|
|
with path.open(encoding="utf-8", errors="replace") as f:
|
|
for line in f:
|
|
total += 1
|
|
if parser.parse_line(line) is None:
|
|
failed += 1
|
|
return total, failed
|
|
|
|
|
|
def test_ssl_log_fixture_parses_with_zero_failures():
|
|
total, failed = _count_parse_failures(FIXTURES_DIR / "hemmatitasks.ir-ssl_log")
|
|
assert total == 222
|
|
assert failed == 0
|
|
|
|
|
|
def test_plain_log_fixture_parses_with_zero_failures():
|
|
total, failed = _count_parse_failures(FIXTURES_DIR / "hemmatitasks.ir")
|
|
assert total == 66
|
|
assert failed == 0
|