From c3b86788168125a1f740a382b9329cd777a94dea Mon Sep 17 00:00:00 2001 From: Szilard Parrag Date: Thu, 19 Sep 2024 12:27:38 +0200 Subject: [PATCH] lib/filterx: add E2E test for startswith/endswith/includes Signed-off-by: Szilard Parrag --- .../functional_tests/filterx/test_filterx.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/light/functional_tests/filterx/test_filterx.py b/tests/light/functional_tests/filterx/test_filterx.py index 9022e0cf2..dda09ec78 100644 --- a/tests/light/functional_tests/filterx/test_filterx.py +++ b/tests/light/functional_tests/filterx/test_filterx.py @@ -2304,3 +2304,35 @@ def test_parse_windows_eventlog_xml(config, syslog_ng): }, }, } + + +def test_startswith_endswith_includes(config, syslog_ng): + (file_true, file_false) = create_config( + config, r""" + result = json(); + if (startswith($MSG, ["dummy_prefix", "foo"])) + { + result.startswith_foo = true; + }; + bar_var = "bar"; + if (includes($MSG, bar_var, ignorecase=true)) + { + result.contains_bar = true; + }; + baz_list = ["baz"]; + if (endswith($MSG, baz_list, ignorecase=true)) + { + result.endswith_baz = true; + }; + if (includes(${values.str}, ${values.str})) + { + result.works_with_message_value = true; + }; + $MSG = json(); + $MSG = result; + """, msg="fooBARbAz", + ) + syslog_ng.start(config) + + assert "processed" not in file_false.get_stats() + assert file_true.read_log() == '{"startswith_foo":true,"contains_bar":true,"endswith_baz":true,"works_with_message_value":true}\n'