56 lines
1.6 KiB
Bash
Executable File
56 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Self-check for orchestra_e2e_healthcheck.sh.
|
|
#
|
|
# The pinned USAGE string is gone. Pinning the help text meant every flag
|
|
# added to the healthcheck turned this file red for a reason that had nothing
|
|
# to do with the flag, so the usage assertions now check shape rather than
|
|
# exact bytes: --help must print a Usage: line, must mention every long flag
|
|
# the script actually parses, and must exit 0 from any argument position.
|
|
|
|
HC="$(dirname "$0")/orchestra_e2e_healthcheck.sh"
|
|
OK='OK - all healthchecks passed'
|
|
fails=0
|
|
|
|
fail() {
|
|
printf 'FAIL: %s\n' "$1"
|
|
fails=$((fails + 1))
|
|
}
|
|
|
|
exact() { # exact <expected-stdout> <label> [args...]
|
|
local want=$1 label=$2 got status
|
|
shift 2
|
|
got=$(bash "$HC" "$@" 2>/dev/null)
|
|
status=$?
|
|
if [ "$got" != "$want" ] || [ "$status" -ne 0 ]; then
|
|
fail "$label (exit=$status, got: $got)"
|
|
fi
|
|
}
|
|
|
|
usage_shape() { # usage_shape <label> [args...]
|
|
local label=$1 got status flag
|
|
shift
|
|
got=$(bash "$HC" "$@" 2>/dev/null)
|
|
status=$?
|
|
[ "$status" -eq 0 ] || fail "$label: exit=$status"
|
|
case "$got" in
|
|
Usage:*) ;;
|
|
*) fail "$label: no Usage: line" ;;
|
|
esac
|
|
# Every long flag the script parses must be documented.
|
|
for flag in $(grep -o -- '--[a-z][a-z-]*' "$HC" | sort -u); do
|
|
case "$got" in
|
|
*"$flag"*) ;;
|
|
*) fail "$label: $flag is parsed but undocumented" ;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
exact "$OK" 'no args'
|
|
exact '' '--quiet' --quiet
|
|
usage_shape '--help' --help
|
|
usage_shape '--help --quiet' --help --quiet
|
|
usage_shape '--quiet --help' --quiet --help
|
|
|
|
[ "$fails" -eq 0 ] || exit 1
|
|
printf 'all checks passed\n'
|