]> git.kaiwu.me - haproxy.git/commitdiff
REGTESTS: cli: add a smoke test for the read-only CLI commands
authorWilly Tarreau <w@1wt.eu>
Mon, 21 Sep 2026 20:51:41 +0000 (20:51 +0000)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Sep 2026 15:19:30 +0000 (17:19 +0200)
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.

reg-tests/cli/show_commands.vtc [new file with mode: 0644]

diff --git a/reg-tests/cli/show_commands.vtc b/reg-tests/cli/show_commands.vtc
new file mode 100644 (file)
index 0000000..4d6c87c
--- /dev/null
@@ -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"
+}