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 28, 2024
1 parent 7ee0cbf commit a081ed1
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 @@ -2497,3 +2497,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, invalid_expr_2], # Should not have any effect, as there is no valid expr 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, invalid_expr_2], # Should not have any effect, as there is no valid expr 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 a081ed1

Please sign in to comment.