Skip to content

Commit

Permalink
filterx: add E2E test for set_fields()
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Szakacs <attila.szakacs@axoflow.com>
  • Loading branch information
alltilla committed Nov 29, 2024
1 parent 95224f8 commit f788f78
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/light/functional_tests/filterx/test_filterx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2520,3 +2520,33 @@ def test_proper_generation_counter(config, syslog_ng):
assert "processed" in file_true.get_stats()
assert file_true.get_stats()["processed"] == 1
assert file_true.read_log() == '{"from_nvtable":"almafa","from_a_macro":"2000-01-01T00:00:00+01:00","unset_then_set":"kortefa"}\n'


def test_set_fields(config, syslog_ng):
(file_true, file_false) = create_config(
config, r"""
$MSG = {
"foo": "foo_exists",
"bar": "bar_exists",
};
set_fields(
$MSG,
overrides={
"foo": [invalid_expr, "foo_override"],
"baz": "baz_override",
"almafa": [invalid_expr_1, null], # Should not have any effect, as there is no valid expr or non-null here.
},
defaults={
"foo": [invalid_expr, "foo_default"], # Should not have any effect, "foo" is handled by overrides.
"bar": "bar_default", # Should not have any effect, "bar" already has value in the dict.
"almafa": "almafa_default",
"kortefa": [invalid_expr_1, null], # Should not have any effect, as there is no valid expr or non-null here.
}
);
""",
)
syslog_ng.start(config)

assert file_true.get_stats()["processed"] == 1
assert "processed" not in file_false.get_stats()
assert file_true.read_log() == '{"foo":"foo_override","bar":"bar_exists","baz":"baz_override","almafa":"almafa_default"}\n'

0 comments on commit f788f78

Please sign in to comment.