Improved log formatting support by @kanta.logfmt, which replaces old resolver and user_display arguments (breaking change).
This commit is contained in:
@@ -16,10 +16,34 @@ def test_delete():
|
||||
assert any("old_key" in line for line in lines)
|
||||
|
||||
|
||||
def test_resolver():
|
||||
def test_logfmt():
|
||||
lines = format_diff(
|
||||
{"users": {"uuid-1": {"name": "Alice"}}},
|
||||
previous={},
|
||||
resolver=lambda x: "Alice" if x == "uuid-1" else x,
|
||||
logfmt=lambda value, path: "Alice" if value == "uuid-1" else None,
|
||||
)
|
||||
assert any("Alice" in line for line in lines)
|
||||
|
||||
|
||||
def test_logfmt_uses_path_context():
|
||||
lines = format_diff(
|
||||
{
|
||||
"users": {"uuid-1": {"name": "Alice"}},
|
||||
"groups": {"uuid-1": {"name": "Admins"}},
|
||||
},
|
||||
previous={},
|
||||
logfmt=lambda value, path: (
|
||||
"User Alice" if path.startswith("users.") and value == "uuid-1" else None
|
||||
),
|
||||
)
|
||||
assert any("User Alice" in line for line in lines)
|
||||
assert any("uuid-1" in line for line in lines)
|
||||
|
||||
|
||||
def test_logfmt_formats_non_string_value():
|
||||
lines = format_diff(
|
||||
{"count": 42},
|
||||
previous={},
|
||||
logfmt=lambda value, path: "forty-two" if value == 42 else None,
|
||||
)
|
||||
assert any("forty-two" in line for line in lines)
|
||||
|
||||
Reference in New Issue
Block a user