31 lines
788 B
Python
31 lines
788 B
Python
import io
|
|
|
|
import pytest
|
|
|
|
from app.services.parser import LogParseError, parse_log_file
|
|
|
|
|
|
def test_parse_log_file_supports_shell_style_quotes():
|
|
stream = io.BytesIO(
|
|
b'v015xxxxdate=2024-02-15 time=09:10:11 policy="Strict Policy" msg="blocked request"\n'
|
|
)
|
|
|
|
records, union_keys = parse_log_file(stream)
|
|
|
|
assert records == [
|
|
{
|
|
"v015xxxxdate": "2024-02-15",
|
|
"time": "09:10:11",
|
|
"policy": "Strict Policy",
|
|
"msg": "blocked request",
|
|
}
|
|
]
|
|
assert union_keys == ["v015xxxxdate", "time", "policy", "msg"]
|
|
|
|
|
|
def test_parse_log_file_rejects_tokens_without_equals():
|
|
stream = io.BytesIO(b"v015xxxxdate=2024-02-15 broken-token\n")
|
|
|
|
with pytest.raises(LogParseError):
|
|
parse_log_file(stream)
|