Skip to content

Commit

Permalink
filterx: regexp_search light tests
Browse files Browse the repository at this point in the history
Signed-off-by: shifter <[email protected]>
  • Loading branch information
bshifter committed Nov 29, 2024
1 parent 93b8db4 commit 968c9d0
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions tests/light/functional_tests/filterx/test_filterx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,36 +1303,76 @@ def test_regexp_search(config, syslog_ng):
config, r"""
$MSG = {};
$MSG.unnamed = regexp_search("foobarbaz", /(foo)(bar)(baz)/);
$MSG.unnamed_keep_zero = regexp_search("foobarbaz", /(foo)(bar)(baz)/, keep_zero=true);
$MSG.unnamed_list_mode = regexp_search("foobarbaz", /(foo)(bar)(baz)/, list_mode=true);
$MSG.unnamed_keep_zero_list_mode = regexp_search("foobarbaz", /(foo)(bar)(baz)/, keep_zero=true, list_mode=true);
$MSG.named = regexp_search("foobarbaz", /(?<first>foo)(?<second>bar)(?<third>baz)/);
$MSG.named_keep_zero = regexp_search("foobarbaz", /(?<first>foo)(?<second>bar)(?<third>baz)/, keep_zero=true);
$MSG.named_list_mode = regexp_search("foobarbaz", /(?<first>foo)(?<second>bar)(?<third>baz)/, list_mode=true);
$MSG.named_keep_zero_list_mode = regexp_search("foobarbaz", /(?<first>foo)(?<second>bar)(?<third>baz)/, keep_zero=true, list_mode=true);
$MSG.mixed = regexp_search("foobarbaz", /(?<first>foo)(bar)(?<third>baz)/);
$MSG.mixed_keep_zero = regexp_search("foobarbaz", /(?<first>foo)(bar)(?<third>baz)/, keep_zero=true);
$MSG.mixed_list_mode = regexp_search("foobarbaz", /(?<first>foo)(bar)(?<third>baz)/, list_mode=true);
$MSG.mixed_keep_zero_list_mode = regexp_search("foobarbaz", /(?<first>foo)(bar)(?<third>baz)/, keep_zero=true, list_mode=true);
$MSG.force_list = json_array(regexp_search("foobarbaz", /(?<first>foo)(bar)(?<third>baz)/));
$MSG.force_dict = json(regexp_search("foobarbaz", /(foo)(bar)(baz)/));
$MSG.force_dict_list_mode = json(regexp_search("foobarbaz", /(foo)(bar)(baz)/, list_mode=true));
$MSG.no_match_unnamed = regexp_search("foobarbaz", /(almafa)/);
if (len($MSG.no_match_unnamed) == 0) {
$MSG.no_match_unnamed_handling = true;
};
$MSG.no_match_unnamed_list_mode = regexp_search("foobarbaz", /(almafa)/, list_mode=true);
if (len($MSG.no_match_unnamed_list_mode) == 0) {
$MSG.no_match_unnamed_list_mode_handling = true;
};
$MSG.no_match_named = regexp_search("foobarbaz", /(?<first>almafa)/);
if (len($MSG.no_match_named) == 0) {
$MSG.no_match_named_handling = true;
};
$MSG.no_match_named_list_mode = regexp_search("foobarbaz", /(?<first>almafa)/, list_mode=true);
if (len($MSG.no_match_named_list_mode) == 0) {
$MSG.no_match_named_list_mode_handling = true;
};
$MSG.full_match=regexp_search("foobarbaz", /foobarbaz/);
$MSG.full_match_list_mode=regexp_search("foobarbaz", /foobarbaz/, list_mode=true);
""",
)
syslog_ng.start(config)

assert file_true.get_stats()["processed"] == 1
assert "processed" not in file_false.get_stats()
assert json.loads(file_true.read_log()) == {
"unnamed": ["foobarbaz", "foo", "bar", "baz"],
"named": {"0": "foobarbaz", "first": "foo", "second": "bar", "third": "baz"},
"mixed": {"0": "foobarbaz", "first": "foo", "2": "bar", "third": "baz"},
"force_list": ["foobarbaz", "foo", "bar", "baz"],
"force_dict": {"0": "foobarbaz", "1": "foo", "2": "bar", "3": "baz"},
"no_match_unnamed": [],
"unnamed": {"1": "foo", "2": "bar", "3": "baz"},
"unnamed_keep_zero": {"0": "foobarbaz", "1": "foo", "2": "bar", "3": "baz"},
"unnamed_list_mode": ["foo", "bar", "baz"],
"unnamed_keep_zero_list_mode": ["foobarbaz", "foo", "bar", "baz"],
"named": {"first": "foo", "second": "bar", "third": "baz"},
"named_keep_zero": {"0": "foobarbaz", "first": "foo", "second": "bar", "third": "baz"},
"named_list_mode": ["foo", "bar", "baz"],
"named_keep_zero_list_mode": ["foobarbaz", "foo", "bar", "baz"],
"mixed": {"first": "foo", "2": "bar", "third": "baz"},
"mixed_keep_zero": {"0": "foobarbaz", "first": "foo", "2": "bar", "third": "baz"},
"mixed_list_mode": ["foo", "bar", "baz"],
"mixed_keep_zero_list_mode": ["foobarbaz", "foo", "bar", "baz"],
"force_list": ["foo", "bar", "baz"],
"force_dict": {"1": "foo", "2": "bar", "3": "baz"},
"force_dict_list_mode": {"1": "foo", "2": "bar", "3": "baz"},
"no_match_unnamed": {},
"no_match_unnamed_handling": True,
"no_match_unnamed_list_mode": [],
"no_match_unnamed_list_mode_handling": True,
"no_match_named": {},
"no_match_named_handling": True,
"no_match_named_list_mode": [],
"no_match_named_list_mode_handling": True,
"full_match": {"0": "foobarbaz"}, # does not suppress grp 0 when it's the only result
"full_match_list_mode": ["foobarbaz"], # does not suppress grp 0 when it's the only result
}


Expand Down

0 comments on commit 968c9d0

Please sign in to comment.