Skip to content

Commit

Permalink
filter: add E2E test for implicit and with NOT
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 May 23, 2024
1 parent a7824da commit c6ef5df
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/copyright/policy
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ tests/light/functional_tests/logpath/test_conditionals\.py
tests/light/functional_tests/logpath/test_midpoint_destinations\.py
tests/light/functional_tests/value-pairs/test_value_pairs\.py
tests/light/functional_tests/templates/test_template_stmt\.py
tests/light/functional_tests/filters/test_multiple_filters\.py
tests/light/functional_tests/filterx/test_filterx\.py
tests/light/functional_tests/filterx/test_filterx_scope\.py
tests/light/functional_tests/parsers/metrics-probe/test_metrics_probe\.py
Expand Down
1 change: 1 addition & 0 deletions tests/light/functional_tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EXTRA_DIST += \
tests/light/functional_tests/destination_drivers/unix_stream_destination/test_unix_stream_destination.py \
tests/light/functional_tests/filters/rate-limit/test_rate_limit_filter_acceptance.py \
tests/light/functional_tests/filters/test_filter_reference.py \
tests/light/functional_tests/filters/test_multiple_filters.py \
tests/light/functional_tests/logpath/__init__.py \
tests/light/functional_tests/logpath/test_conditionals.py \
tests/light/functional_tests/logpath/test_flags_catch_all.py \
Expand Down
70 changes: 70 additions & 0 deletions tests/light/functional_tests/filters/test_multiple_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python
#############################################################################
# Copyright (c) 2024 Attila Szakacs
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# As an additional exemption you are allowed to compile & link against the
# OpenSSL libraries as published by the OpenSSL project. See the file
# COPYING for details.
#
#############################################################################
from src.syslog_ng_config.renderer import render_statement


def test_multiple_filters_implicit_and(config, syslog_ng):
file_true = config.create_file_destination(file_name="dest-true.log", template="\"$MSG\\n\"")
file_false = config.create_file_destination(file_name="dest-false.log", template="\"$MSG\\n\"")

preamble = f"""
@version: {config.get_version()}
options {{ stats(level(1)); }};
source genmsg {{
example-msg-generator(num(1) template("MESSAGE"));
example-msg-generator(num(1) template("foobar"));
}};
filter f_filter {{
not program("xyz");
message("MESSAGE");
}};
destination dest_true {{
{render_statement(file_true)};
}};
destination dest_false {{
{render_statement(file_false)};
}};
log {{
source(genmsg);
if {{
filter(f_filter);
destination(dest_true);
}} else {{
destination(dest_false);
}};
}};
"""
config.set_raw_config(preamble)
syslog_ng.start(config)

assert file_true.get_stats()["processed"] == 1
assert file_false.get_stats()["processed"] == 1

assert "MESSAGE" in file_true.read_log()
assert "foobar" in file_false.read_log()

0 comments on commit c6ef5df

Please sign in to comment.