51490707f5
# Conflicts: # TASK.md # scripts/orchestra_e2e_healthcheck.sh # scripts/test_healthcheck.sh
34 lines
1.6 KiB
Bash
Executable File
34 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Self-check for orchestra_e2e_healthcheck.sh.
|
|
|
|
HC="$(dirname "$0")/orchestra_e2e_healthcheck.sh"
|
|
OK='OK - all healthchecks passed'
|
|
USAGE="$(printf 'Usage: orchestra_e2e_healthcheck.sh [--quiet] [--json] [--summary] [--timing] [--list-checks]\n\nHealthcheck script for Orchestra E2E tests.\nExits 0 with a success message if all checks pass.\n --quiet Suppress the success message; still exits 0.\n --list-checks Print the name of each check; exits 0.\n --summary Print one line per check before the success message.\n --timing Print elapsed milliseconds for each check.\nVersion: 1.0.0')"
|
|
fails=0
|
|
|
|
check() { # check <expected-stdout> <label> [args...]
|
|
local want=$1 label=$2 got status raw
|
|
shift 2
|
|
raw=$(bash "$HC" "$@" 2>/dev/null)
|
|
status=$?
|
|
# Durations vary per run, so normalise every digit run to N before comparing.
|
|
got=$(printf '%s' "$raw" | sed -E 's/[0-9]+ms/Nms/g; s/("healthchecks":)[0-9]+/\1N/g')
|
|
if [ "$got" != "$want" ] || [ "$status" -ne 0 ]; then
|
|
printf 'FAIL: %s (exit=%s)\n---got---\n%s\n---want---\n%s\n' "$label" "$status" "$got" "$want"
|
|
fails=$((fails + 1))
|
|
fi
|
|
}
|
|
|
|
check "$OK" 'no args'
|
|
check '' '--quiet' --quiet
|
|
check "$USAGE" '--help' --help
|
|
check "$USAGE" '--help --quiet' --help --quiet
|
|
check "$USAGE" '--quiet --help' --quiet --help
|
|
check "$OK" 'unknown flag ignored' --bogus
|
|
check "$(printf 'healthchecks: Nms\n%s' "$OK")" '--timing' --timing
|
|
check '' '--timing --quiet' --timing --quiet
|
|
check '{"status":"ok","checks":1,"timings":{"healthchecks":N}}' '--timing --json' --timing --json
|
|
|
|
[ "$fails" -eq 0 ] || exit 1
|
|
printf 'all checks passed\n'
|