From: Willy Tarreau Date: Mon, 21 Sep 2026 20:51:41 +0000 (+0000) Subject: REGTESTS: cli: add a smoke test for the read-only CLI commands X-Git-Tag: v3.5-dev8~49 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=09d1c04d7dbfa419a126527a20a3812948610d6a;p=haproxy.git REGTESTS: cli: add a smoke test for the read-only CLI commands Most of the "show" commands of the CLI had no coverage at all, so a crash or a broken output in one of their dump functions would go unnoticed. This test issues show version, cli level, cli sockets, env, startup-logs, dev, backend, defaults, default-server, servers state, servers conn, stat, info, schema json, sess, errors, fd, pools, activity, threads, tasks, profiling, anon, table, map and acl once on a small but non-empty configuration. The patterns are deliberately loose: the point is to verify that each command is accepted and that its dump reaches its first line, not to freeze output formats which are explicitly allowed to change. --- diff --git a/reg-tests/cli/show_commands.vtc b/reg-tests/cli/show_commands.vtc new file mode 100644 index 000000000..4d6c87c43 --- /dev/null +++ b/reg-tests/cli/show_commands.vtc @@ -0,0 +1,121 @@ +varnishtest "Smoke test of the read-only CLI commands" + +# Most of the "show" commands of the CLI had no coverage at all, which +# means that a crash or a broken output in one of their dump functions +# would go unnoticed. This test issues each of them once on a small but +# non-empty configuration and checks that the answer has the expected +# shape. +# +# The patterns are deliberately loose: the point is to verify that the +# command is accepted and that its dump reaches its first line, not to +# freeze an output format which is explicitly allowed to change. + +feature ignore_unknown_macro + +haproxy h1 -conf { + global + .if feature(THREAD) + thread-groups 1 + .endif + chroot / + + defaults mydefs + mode http + timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" + timeout client "${HAPROXY_TEST_TIMEOUT-5s}" + timeout server "${HAPROXY_TEST_TIMEOUT-5s}" + + frontend fe from mydefs + bind "fd@${fe}" + default_backend be + + backend be from mydefs + default-server maxconn 7 + server s1 127.0.0.1:1 disabled +} -start + +haproxy h1 -cli { + send "show version" + expect ~ "^[0-9]+[.][0-9]+" + + send "show cli level" + expect ~ "^(admin|operator|user)" + + send "show cli sockets" + expect ~ "^# socket lvl processes" + + send "show env HAPROXY_LOCALPEER" + expect ~ "^HAPROXY_LOCALPEER=" + + send "show startup-logs" + expect ~ "[A-Z]+" + + send "show dev" + expect ~ "HAProxy version" + + # proxies and servers + send "show backend" + expect ~ "^# name\nbe" + + send "show defaults" + expect ~ "mydefs" + + send "show defaults mydefs" + expect ~ "mydefs" + + send "show default-server be" + expect ~ "be" + + send "show servers state" + expect ~ "# be_id be_name srv_id srv_name" + + send "show servers conn" + expect ~ "# bkname/svname bkid/svid addr port" + + # statistics + send "show stat" + expect ~ "^# pxname,svname,qcur" + + send "show info" + expect ~ "Name: HAProxy" + + send "show schema json" + expect ~ "json-schema.org" + + # runtime state + send "show sess" + expect ~ "proto=(tcpv4|tcpv6|unix)" + + send "show errors" + expect ~ "^Total events captured on " + + send "show fd" + expect ~ "st=0x" + + send "show pools" + expect ~ "^Dumping pools usage" + + send "show activity" + expect ~ "^thread_id: " + + send "show threads" + expect ~ "Thread [0-9]* " + + send "show tasks" + expect ~ "^Running tasks: " + + send "show profiling" + expect ~ "Per-task CPU profiling" + + send "show anon" + expect ~ "^Anonymized mode disabled" + + send "show table" + expect ~ "^$" + + send "show map" + expect ~ "^# id [(]file[)] description" + + send "show acl" + expect ~ "^# id [(]file[)] description" +}