Files
test-e2e/scripts/orchestra_e2e_selftest.sh
T

50 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Self-test for the Orchestra E2E healthcheck.
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
}
# plain run
out=$(bash "$healthcheck")
status=$?
[ "$status" -eq 0 ] || fail "plain run exit status: want 0, got $status" "$out"
case "$out" in
*OK*) ;;
*) 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" "$jout"
jlines=$(printf '%s\n' "$jout" | wc -l)
[ "$jlines" -eq 1 ] || fail "--json run line count: want 1, got $jlines" "$jout"
case "$jout" in
'{"status":'*) ;;
*) fail '--json run stdout prefix: want {"status":' "$jout" ;;
esac
# --strict rejects an unknown flag
sout=$(bash "$healthcheck" --strict --nonsense 2>&1)
sstatus=$?
[ "$sstatus" -eq 2 ] || fail "--strict --nonsense exit status: want 2, got $sstatus" "$sout"
# --strict alone is accepted
gout=$(bash "$healthcheck" --strict)
gstatus=$?
[ "$gstatus" -eq 0 ] || fail "--strict run exit status: want 0, got $gstatus" "$gout"
printf 'selftest: ok\n'