diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
commit | dcc721a95bef6f0d8e6d8775b8efe33e5aecd562 (patch) | |
tree | 66a2774cd0ee294d019efd71d2544c70f42b2842 /tests/json_object_suicide_in_loop-vg.sh | |
parent | Initial commit. (diff) | |
download | rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.tar.xz rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.zip |
Adding upstream version 8.2402.0.upstream/8.2402.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | tests/json_object_suicide_in_loop-vg.sh | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/json_object_suicide_in_loop-vg.sh b/tests/json_object_suicide_in_loop-vg.sh new file mode 100755 index 0000000..cccb4cb --- /dev/null +++ b/tests/json_object_suicide_in_loop-vg.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# basic test for looping over json object and unsetting it while inside the loop-body +# added 2016-03-31 by singh.janmejay +# This file is part of the rsyslog project, released under ASL 2.0 +. ${srcdir:=.}/diag.sh init + +uname +if [ $(uname) = "FreeBSD" ] ; then + echo "This test currently does not work on FreeBSD." + exit 77 +fi +generate_conf +add_conf ' +template(name="corge" type="string" string="corge: key: %$.corge!key% val: %$.corge!value%\n") +template(name="quux" type="string" string="quux: %$.quux%\n") +template(name="post_suicide_foo" type="string" string="post_suicide_foo: ' +add_conf "'%\$!foo%'" +add_conf '\n") + +module(load="../plugins/mmjsonparse/.libs/mmjsonparse") +module(load="../plugins/imptcp/.libs/imptcp") +input(type="imptcp" port="0" listenPortFileName="'$RSYSLOG_DYNNAME'.tcpflood_port") + +action(type="mmjsonparse") +set $.garply = ""; + +foreach ($.quux in $!foo) do { + if ($.quux!key == "str2") then { + set $.quux!random_key = $.quux!key; + unset $!foo; #because it is deep copied, the foreach loop will continue to work, but the action to print "post_suicide_foo" will not see $!foo + } + action(type="omfile" file=`echo $RSYSLOG_OUT_LOG` template="quux") + foreach ($.corge in $.quux!value) do { + action(type="omfile" file="'$RSYSLOG_DYNNAME'.out.async.log" template="corge" queue.type="linkedlist" action.copyMsg="on") + } +} +action(type="omfile" file=`echo $RSYSLOG_OUT_LOG` template="post_suicide_foo") +' +startup_vg +tcpflood -m 1 -I $srcdir/testsuites/json_object_input +echo doing shutdown +shutdown_when_empty +echo wait on shutdown +wait_shutdown_vg +check_exit_vg +content_check 'quux: { "key": "str1", "value": "abc0" }' +content_check 'quux: { "key": "str2", "value": "def1", "random_key": "str2" }' +content_check 'quux: { "key": "str3", "value": "ghi2" }' +assert_content_missing 'quux: { "key": "str4", "value": "jkl3" }' +content_check 'quux: { "key": "obj", "value": { "bar": { "k1": "important_msg", "k2": "other_msg" } } }' +custom_content_check 'corge: key: bar val: { "k1": "important_msg", "k2": "other_msg" }' $RSYSLOG_DYNNAME.out.async.log +content_check "post_suicide_foo: ''" +exit_test |