Give the healthcheck a self-test and a machine-readable mode #11

Merged
kami merged 3 commits from orchestra/06G4FT0MB733H2ZCZ237WFHFD8 into master 2026-08-28 12:42:28 +02:00
Showing only changes of commit ba0e891348 - Show all commits
+8 -5
View File
@@ -4,8 +4,11 @@
here=$(cd "$(dirname "$0")" && pwd)
healthcheck="$here/orchestra_e2e_healthcheck.sh"
# fail <assertion> <captured stdout>: always echo what the healthcheck printed,
# so a red run is diagnosable without rerunning it by hand.
fail() {
printf 'selftest: FAILED %s\n' "$1" >&2
printf 'selftest: healthcheck stdout was:\n%s\n' "$2" >&2
exit 1
}
@@ -13,22 +16,22 @@ fail() {
out=$(bash "$healthcheck")
status=$?
[ "$status" -eq 0 ] || fail "plain run exit status: want 0, got $status"
[ "$status" -eq 0 ] || fail "plain run exit status: want 0, got $status" "$out"
case "$out" in
*OK*) ;;
*) fail "plain run stdout contains OK: got '$out'" ;;
*) fail "plain run stdout contains OK" "$out" ;;
esac
# --json run
jout=$(bash "$healthcheck" --json)
jstatus=$?
[ "$jstatus" -eq 0 ] || fail "--json run exit status: want 0, got $jstatus"
[ "$jstatus" -eq 0 ] || fail "--json run exit status: want 0, got $jstatus" "$jout"
jlines=$(printf '%s\n' "$jout" | wc -l)
[ "$jlines" -eq 1 ] || fail "--json run line count: want 1, got $jlines"
[ "$jlines" -eq 1 ] || fail "--json run line count: want 1, got $jlines" "$jout"
case "$jout" in
'{"status":'*) ;;
*) fail "--json run stdout prefix: want {\"status\": got '$jout'" ;;
*) fail '--json run stdout prefix: want {"status":' "$jout" ;;
esac
printf 'selftest: ok\n'