Skip to content

Commit

Permalink
kvformat: filterx-func-parse-kv function light tests
Browse files Browse the repository at this point in the history
Signed-off-by: shifter <[email protected]>
  • Loading branch information
bshifter committed May 3, 2024
1 parent 12972dc commit 4e2f1ab
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions tests/light/functional_tests/filterx/test_filterx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,3 +1120,107 @@ def test_regexp_search_error_in_pattern(config, syslog_ng):
)
with pytest.raises(Exception):
syslog_ng.start(config)


def test_parse_kv_default_option_set_is_skippable(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
$MSG = parse_kv("foo=bar, thisisstray bar=baz");
""",
)
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\":\"bar\",\"bar\":\"baz\"}\n"


def test_parse_kv_default_options_are_nullable(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
$MSG = parse_kv("foo=bar, thisisstray bar=baz", null, null, null, null);
""",
)
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\":\"bar\",\"bar\":\"baz\"}\n"


def test_parse_kv_opts_over_max_opt_are_skipped(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
$MSG = parse_kv("foo=bar, bar=baz", null, null, null, null, null, null, null, null, null);
""",
)
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\":\"bar\",\"bar\":\"baz\"}\n"


def test_parse_kv_prefix(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
$MSG = parse_kv("foo=bar, bar=baz", "prefix.");
""",
)
syslog_ng.start(config)

assert file_true.get_stats()["processed"] == 1
assert "processed" not in file_false.get_stats()
assert file_true.read_log() == "{\"prefix.foo\":\"bar\",\"prefix.bar\":\"baz\"}\n"


def test_parse_kv_value_separator(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
$MSG = parse_kv("foo@bar, bar@baz", null, "@");
""",
)
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\":\"bar\",\"bar\":\"baz\"}\n"


def test_parse_kv_value_separator_use_first_character(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
$MSG = parse_kv("foo@bar, bar@baz", null, "@!$");
""",
)
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\":\"bar\",\"bar\":\"baz\"}\n"


def test_parse_kv_pair_separator(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
$MSG = parse_kv("foo=bar#bar=baz", null, null, "#");
""",
)
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\":\"bar\",\"bar\":\"baz\"}\n"


def test_parse_kv_stray_words_value_name(config, syslog_ng):
(file_true, file_false) = create_config(
config, """
$MSG = parse_kv("foo=bar, thisisstray bar=baz", null, null, null, "stray_words");
""",
)
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\":\"bar\",\"bar\":\"baz\",\"stray_words\":\"thisisstray\"}\n"

0 comments on commit 4e2f1ab

Please sign in to comment.