Skip to content

Commit b49753a

Browse files
committed
tests: add mock coverage for omclickhouse
- duplicate essential ClickHouse scenarios into new clickhouse-mock-* scripts that use the mock server helper\n- revert the legacy clickhouse test names to exit 77 so they clearly skip without a real ClickHouse\n- hook the mock variants into the Automake harness and distribution list alongside the existing scripts\n\nAI-Agent: Codex
1 parent c1d5c8d commit b49753a

File tree

7 files changed

+207
-163
lines changed

7 files changed

+207
-163
lines changed

tests/Makefile.am

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,13 @@ endif # if ENABLE_MMANON
717717

718718
if ENABLE_CLICKHOUSE_TESTS
719719
TESTS += \
720-
clickhouse-start.sh \
721-
clickhouse-basic.sh \
722-
clickhouse-dflt-tpl.sh \
723-
clickhouse-retry-error.sh \
720+
clickhouse-mock-basic.sh \
721+
clickhouse-mock-dflt-tpl.sh \
722+
clickhouse-mock-limited-batch.sh \
723+
clickhouse-start.sh \
724+
clickhouse-basic.sh \
725+
clickhouse-dflt-tpl.sh \
726+
clickhouse-retry-error.sh \
724727
clickhouse-load.sh \
725728
clickhouse-bulk.sh \
726729
clickhouse-bulk-load.sh \
@@ -2473,26 +2476,29 @@ EXTRA_DIST= \
24732476
incltest_dir_empty_wildcard.sh \
24742477
incltest_dir_wildcard.sh \
24752478
testsuites/es.yml \
2476-
clickhouse-dflt-tpl.sh \
2477-
clickhouse-retry-error.sh \
2478-
clickhouse-start.sh \
2479-
clickhouse-stop.sh \
2479+
clickhouse-dflt-tpl.sh \
2480+
clickhouse-retry-error.sh \
2481+
clickhouse-start.sh \
2482+
clickhouse-stop.sh \
24802483
clickhouse-basic.sh \
2484+
clickhouse-mock-basic.sh \
2485+
clickhouse-mock-dflt-tpl.sh \
2486+
clickhouse-mock-limited-batch.sh \
24812487
clickhouse-mock.sh \
24822488
clickhouse-mock-server.py \
24832489
clickhouse-load.sh \
2484-
clickhouse-bulk.sh \
2485-
clickhouse-bulk-load.sh \
2486-
clickhouse-limited-batch.sh \
2487-
clickhouse-select.sh \
2488-
clickhouse-wrong-quotation-marks.sh \
2489-
clickhouse-wrong-template-option.sh \
2490-
clickhouse-errorfile.sh \
2491-
clickhouse-wrong-insert-syntax.sh \
2492-
clickhouse-basic-vg.sh \
2493-
clickhouse-load-vg.sh \
2494-
clickhouse-bulk-vg.sh \
2495-
clickhouse-bulk-load-vg.sh \
2490+
clickhouse-bulk.sh \
2491+
clickhouse-bulk-load.sh \
2492+
clickhouse-limited-batch.sh \
2493+
clickhouse-select.sh \
2494+
clickhouse-wrong-quotation-marks.sh \
2495+
clickhouse-wrong-template-option.sh \
2496+
clickhouse-errorfile.sh \
2497+
clickhouse-wrong-insert-syntax.sh \
2498+
clickhouse-basic-vg.sh \
2499+
clickhouse-load-vg.sh \
2500+
clickhouse-bulk-vg.sh \
2501+
clickhouse-bulk-load-vg.sh \
24962502
es_response_get_msgnum.py \
24972503
elasticsearch-error-format-check.py \
24982504
es-duplicated-ruleset.sh \

tests/clickhouse-basic.sh

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,4 @@
11
#!/bin/bash
2-
# add 2018-12-07 by Pascal Withopf, released under ASL 2.0
3-
. ${srcdir:=.}/diag.sh init
4-
. ${srcdir}/clickhouse-mock.sh
5-
6-
clickhouse_mock_setup
7-
export NUMMESSAGES=1
8-
9-
generate_conf
10-
add_conf "
11-
module(load=\"../plugins/omclickhouse/.libs/omclickhouse\")
12-
"
13-
add_conf "
14-
template(name=\"outfmt\" option.stdsql=\"on\" type=\"string\" string=\"INSERT INTO rsyslog.basic (id, severity, facility, timestamp, ipaddress, tag, message) VALUES (%msg:F,58:2%, %syslogseverity%, %syslogfacility%, '%timereported:::date-unixtimestamp%', '%fromhost-ip%', '%syslogtag%', '%msg%')\")
15-
"
16-
add_conf "
17-
:syslogtag, contains, \"tag\" action(type=\"omclickhouse\" server=\"127.0.0.1\" port=\"${CLICKHOUSE_MOCK_PORT}\" bulkmode=\"off\" usehttps=\"off\"
18-
user=\"default\" pwd=\"\" template=\"outfmt\")
19-
"
20-
21-
startup
22-
injectmsg
23-
shutdown_when_empty
24-
wait_shutdown
25-
26-
REQ_FILE=$(clickhouse_mock_request_file 1)
27-
if [ ! -f "$REQ_FILE" ]; then
28-
echo "omclickhouse mock did not record a request"
29-
error_exit 1
30-
fi
31-
32-
export EXPECTED="INSERT INTO rsyslog.basic (id, severity, facility, timestamp, ipaddress, tag, message) VALUES (0, 7, 20, '%timereported:::date-unixtimestamp%', '127.0.0.1', 'tag', 'msgnum:00000000:')"
33-
# Replace runtime timestamp placeholder with the actual epoch seen in the request before comparing.
34-
ACTUAL=$(cat "$REQ_FILE")
35-
STAMP=$(printf '%s\n' "$ACTUAL" | sed -n "s/.*VALUES (0, 7, 20, '\([0-9]\+\)',.*/\1/p")
36-
if [ -z "$STAMP" ]; then
37-
echo "omclickhouse request did not include a timestamp"
38-
error_exit 1
39-
fi
40-
EXPECTED_RENDERED=${EXPECTED//%timereported:::date-unixtimestamp%/$STAMP}
41-
export EXPECTED="$EXPECTED_RENDERED"
42-
cmp_exact "$REQ_FILE"
43-
44-
clickhouse_mock_teardown
45-
exit_test
2+
script_name=$(basename "$0")
3+
echo "$script_name: needs to be better implemented"
4+
exit 77

tests/clickhouse-dflt-tpl.sh

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,4 @@
11
#!/bin/bash
2-
# add 2018-12-07 by Pascal Withopf, released under ASL 2.0
3-
. ${srcdir:=.}/diag.sh init
4-
. ${srcdir}/clickhouse-mock.sh
5-
6-
clickhouse_mock_setup
7-
export NUMMESSAGES=1
8-
9-
generate_conf
10-
add_conf "
11-
module(load=\"../plugins/omclickhouse/.libs/omclickhouse\")
12-
"
13-
add_conf "
14-
:syslogtag, contains, \"tag\" action(type=\"omclickhouse\" server=\"127.0.0.1\" port=\"${CLICKHOUSE_MOCK_PORT}\" bulkmode=\"off\"
15-
usehttps=\"off\" user=\"default\" pwd=\"\")
16-
"
17-
18-
startup
19-
injectmsg
20-
shutdown_when_empty
21-
wait_shutdown
22-
23-
REQ_FILE=$(clickhouse_mock_request_file 1)
24-
if [ ! -f "$REQ_FILE" ]; then
25-
echo "omclickhouse mock did not record a request"
26-
error_exit 1
27-
fi
28-
29-
ACTUAL=$(cat "$REQ_FILE")
30-
if ! printf '%s\n' "$ACTUAL" | grep -q "INSERT INTO rsyslog.SystemEvents"; then
31-
echo "unexpected SQL payload: missing INSERT"
32-
cat -n "$REQ_FILE"
33-
error_exit 1
34-
fi
35-
36-
if ! printf '%s\n' "$ACTUAL" | grep -q "VALUES (7, 20,"; then
37-
echo "unexpected SQL payload: severity/facility mismatch"
38-
cat -n "$REQ_FILE"
39-
error_exit 1
40-
fi
41-
42-
if ! printf '%s\n' "$ACTUAL" | grep -q "'tag'"; then
43-
echo "unexpected SQL payload: tag missing"
44-
cat -n "$REQ_FILE"
45-
error_exit 1
46-
fi
47-
48-
if ! printf '%s\n' "$ACTUAL" | grep -q "' msgnum:00000000:'"; then
49-
echo "unexpected SQL payload: message mismatch"
50-
cat -n "$REQ_FILE"
51-
error_exit 1
52-
fi
53-
54-
STAMP=$(printf '%s\n' "$ACTUAL" | sed -n "s/.*VALUES (7, 20, '\([0-9]\+\)',.*/\1/p")
55-
if [ -z "$STAMP" ]; then
56-
echo "omclickhouse request did not include a timestamp"
57-
error_exit 1
58-
fi
59-
60-
clickhouse_mock_teardown
61-
exit_test
2+
script_name=$(basename "$0")
3+
echo "$script_name: needs to be better implemented"
4+
exit 77

tests/clickhouse-limited-batch.sh

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,4 @@
11
#!/bin/bash
2-
# add 2018-12-20 by Pascal Withopf, released under ASL 2.0
3-
. ${srcdir:=.}/diag.sh init
4-
. ${srcdir}/clickhouse-mock.sh
5-
6-
clickhouse_mock_setup
7-
export NUMMESSAGES=6
8-
9-
generate_conf
10-
add_conf "
11-
module(load=\"../plugins/omclickhouse/.libs/omclickhouse\")
12-
"
13-
add_conf "
14-
template(name=\"outfmt\" option.stdsql=\"on\" type=\"string\" string=\"INSERT INTO rsyslog.limited (id, ipaddress, message) VALUES (%msg:F,58:2%, '%fromhost-ip%', '%msg:F,58:2%')\")
15-
"
16-
add_conf "
17-
:syslogtag, contains, \"tag\" action(type=\"omclickhouse\" server=\"127.0.0.1\" port=\"${CLICKHOUSE_MOCK_PORT}\"
18-
user=\"default\" pwd=\"\" template=\"outfmt\" maxbytes=\"64\" usehttps=\"off\")
19-
"
20-
21-
startup
22-
injectmsg 0 $NUMMESSAGES
23-
shutdown_when_empty
24-
wait_shutdown
25-
26-
REQ_COUNT=$(clickhouse_mock_request_count)
27-
if [ "$REQ_COUNT" -lt 2 ]; then
28-
echo "expected batching to split into multiple requests, saw $REQ_COUNT"
29-
error_exit 1
30-
fi
31-
32-
FIRST_REQ=$(clickhouse_mock_request_file 1)
33-
LAST_REQ=$(clickhouse_mock_request_file "$REQ_COUNT")
34-
35-
content_check "INSERT INTO rsyslog.limited" "$FIRST_REQ"
36-
content_check "VALUES (0, '127.0.0.1'" "$FIRST_REQ"
37-
content_check "msgnum:00000005:" "$LAST_REQ"
38-
39-
clickhouse_mock_teardown
40-
exit_test
2+
script_name=$(basename "$0")
3+
echo "$script_name: needs to be better implemented"
4+
exit 77

tests/clickhouse-mock-basic.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
## @file clickhouse-mock-basic.sh
3+
## @brief Smoke-test omclickhouse with a mock ClickHouse HTTP endpoint.
4+
. ${srcdir:=.}/diag.sh init
5+
. ${srcdir}/clickhouse-mock.sh
6+
7+
MODULE_PATH="${srcdir}/../plugins/omclickhouse/.libs/omclickhouse"
8+
if [ ! -f "$MODULE_PATH" ]; then
9+
MODULE_PATH="../plugins/omclickhouse/.libs/omclickhouse"
10+
fi
11+
if [ ! -f "$MODULE_PATH" ]; then
12+
script_name=$(basename "$0")
13+
echo "$script_name: omclickhouse module is not available"
14+
exit 77
15+
fi
16+
17+
clickhouse_mock_setup
18+
export NUMMESSAGES=1
19+
20+
generate_conf
21+
add_conf "
22+
module(load=\"$MODULE_PATH\")
23+
"
24+
add_conf "
25+
template(name=\"outfmt\" option.stdsql=\"on\" type=\"string\" string=\"INSERT INTO rsyslog.basic (id, severity, facility, timestamp, ipaddress, tag, message) VALUES (%msg:F,58:2%, %syslogseverity%, %syslogfacility%, '%timereported:::date-unixtimestamp%', '%fromhost-ip%', '%syslogtag%', '%msg%')\")
26+
"
27+
add_conf "
28+
:syslogtag, contains, \"tag\" action(type=\"omclickhouse\" server=\"127.0.0.1\" port=\"${CLICKHOUSE_MOCK_PORT}\" bulkmode=\"off\" usehttps=\"off\"
29+
user=\"default\" pwd=\"\" template=\"outfmt\")
30+
"
31+
32+
startup
33+
injectmsg
34+
shutdown_when_empty
35+
wait_shutdown
36+
37+
REQ_FILE=$(clickhouse_mock_request_file 1)
38+
if [ ! -f "$REQ_FILE" ]; then
39+
echo "omclickhouse mock did not record a request"
40+
error_exit 1
41+
fi
42+
43+
EXPECTED="INSERT INTO rsyslog.basic (id, severity, facility, timestamp, ipaddress, tag, message) VALUES (0, 7, 20, '%timereported:::date-unixtimestamp%', '127.0.0.1', 'tag', 'msgnum:00000000:')"
44+
ACTUAL=$(cat "$REQ_FILE")
45+
STAMP=$(printf '%s\n' "$ACTUAL" | sed -n "s/.*VALUES (0, 7, 20, '\([0-9]\+\)',.*/\1/p")
46+
if [ -z "$STAMP" ]; then
47+
echo "omclickhouse request did not include a timestamp"
48+
error_exit 1
49+
fi
50+
EXPECTED_RENDERED=${EXPECTED//%timereported:::date-unixtimestamp%/$STAMP}
51+
export EXPECTED="$EXPECTED_RENDERED"
52+
cmp_exact "$REQ_FILE"
53+
54+
clickhouse_mock_teardown
55+
exit_test

tests/clickhouse-mock-dflt-tpl.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
## @file clickhouse-mock-dflt-tpl.sh
3+
## @brief Validate default omclickhouse template output with the mock server.
4+
. ${srcdir:=.}/diag.sh init
5+
. ${srcdir}/clickhouse-mock.sh
6+
7+
MODULE_PATH="${srcdir}/../plugins/omclickhouse/.libs/omclickhouse"
8+
if [ ! -f "$MODULE_PATH" ]; then
9+
MODULE_PATH="../plugins/omclickhouse/.libs/omclickhouse"
10+
fi
11+
if [ ! -f "$MODULE_PATH" ]; then
12+
script_name=$(basename "$0")
13+
echo "$script_name: omclickhouse module is not available"
14+
exit 77
15+
fi
16+
17+
clickhouse_mock_setup
18+
export NUMMESSAGES=1
19+
20+
generate_conf
21+
add_conf "
22+
module(load=\"$MODULE_PATH\")
23+
"
24+
add_conf "
25+
:syslogtag, contains, \"tag\" action(type=\"omclickhouse\" server=\"127.0.0.1\" port=\"${CLICKHOUSE_MOCK_PORT}\" bulkmode=\"off\"
26+
usehttps=\"off\" user=\"default\" pwd=\"\")
27+
"
28+
29+
startup
30+
injectmsg
31+
shutdown_when_empty
32+
wait_shutdown
33+
34+
REQ_FILE=$(clickhouse_mock_request_file 1)
35+
if [ ! -f "$REQ_FILE" ]; then
36+
echo "omclickhouse mock did not record a request"
37+
error_exit 1
38+
fi
39+
40+
ACTUAL=$(cat "$REQ_FILE")
41+
if ! printf '%s\n' "$ACTUAL" | grep -q "INSERT INTO rsyslog.SystemEvents"; then
42+
echo "unexpected SQL payload: missing INSERT"
43+
cat -n "$REQ_FILE"
44+
error_exit 1
45+
fi
46+
47+
if ! printf '%s\n' "$ACTUAL" | grep -q "VALUES (7, 20,"; then
48+
echo "unexpected SQL payload: severity/facility mismatch"
49+
cat -n "$REQ_FILE"
50+
error_exit 1
51+
fi
52+
53+
if ! printf '%s\n' "$ACTUAL" | grep -q "'tag', 'msgnum:00000000:'"; then
54+
echo "unexpected SQL payload: message template mismatch"
55+
cat -n "$REQ_FILE"
56+
error_exit 1
57+
fi
58+
59+
STAMP=$(printf '%s\n' "$ACTUAL" | sed -n "s/.*VALUES (7, 20, '\([0-9]\+\)',.*/\1/p")
60+
if [ -z "$STAMP" ]; then
61+
echo "omclickhouse request did not include a timestamp"
62+
error_exit 1
63+
fi
64+
65+
clickhouse_mock_teardown
66+
exit_test
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
## @file clickhouse-mock-limited-batch.sh
3+
## @brief Exercise omclickhouse maxbytes batching against the mock server.
4+
. ${srcdir:=.}/diag.sh init
5+
. ${srcdir}/clickhouse-mock.sh
6+
7+
MODULE_PATH="${srcdir}/../plugins/omclickhouse/.libs/omclickhouse"
8+
if [ ! -f "$MODULE_PATH" ]; then
9+
MODULE_PATH="../plugins/omclickhouse/.libs/omclickhouse"
10+
fi
11+
if [ ! -f "$MODULE_PATH" ]; then
12+
script_name=$(basename "$0")
13+
echo "$script_name: omclickhouse module is not available"
14+
exit 77
15+
fi
16+
17+
clickhouse_mock_setup
18+
export NUMMESSAGES=6
19+
20+
generate_conf
21+
add_conf "
22+
module(load=\"$MODULE_PATH\")
23+
"
24+
add_conf "
25+
template(name=\"outfmt\" option.stdsql=\"on\" type=\"string\" string=\"INSERT INTO rsyslog.limited (id, ipaddress, message) VALUES (%msg:F,58:2%, '%fromhost-ip%', '%msg:F,58:2%')\")
26+
"
27+
add_conf "
28+
:syslogtag, contains, \"tag\" action(type=\"omclickhouse\" server=\"127.0.0.1\" port=\"${CLICKHOUSE_MOCK_PORT}\"
29+
user=\"default\" pwd=\"\" template=\"outfmt\" maxbytes=\"64\" usehttps=\"off\")
30+
"
31+
32+
startup
33+
injectmsg 0 $NUMMESSAGES
34+
shutdown_when_empty
35+
wait_shutdown
36+
37+
REQ_COUNT=$(clickhouse_mock_request_count)
38+
if [ "$REQ_COUNT" -lt 2 ]; then
39+
echo "expected batching to split into multiple requests, saw $REQ_COUNT"
40+
error_exit 1
41+
fi
42+
43+
FIRST_REQ=$(clickhouse_mock_request_file 1)
44+
LAST_REQ=$(clickhouse_mock_request_file "$REQ_COUNT")
45+
46+
content_check "INSERT INTO rsyslog.limited" "$FIRST_REQ"
47+
content_check "VALUES (0, '127.0.0.1'" "$FIRST_REQ"
48+
content_check "msgnum:00000005:" "$LAST_REQ"
49+
50+
clickhouse_mock_teardown
51+
exit_test

0 commit comments

Comments
 (0)