#!/usr/bin/env bash # Stubbed curl tests for scripts/verify-api-health.sh. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" VERIFY="${ROOT}/scripts/verify-api-health.sh" SHA="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" failures=0 assert_exit() { local name="$1" expected="$2" got="$3" log="$4" if [[ "${got}" != "${expected}" ]]; then echo "FAIL: ${name}: expected exit ${expected}, got ${got}" >&2 sed -n '1,80p' "${log}" >&2 failures=$((failures + 1)) else echo "PASS: ${name}" fi } run_with_curl() { local name="$1" expected="$2" curl_body="$3" local dir dir="$(mktemp -d)" cat > "${dir}/curl" << CURL #!/usr/bin/env bash set -euo pipefail output="" write_out="" args=("\$@") i=0 while [[ \$i -lt \${#args[@]} ]]; do arg="\${args[\$i]}" case "\${arg}" in -o) i=\$((i + 1)); output="\${args[\$i]}" ;; -w) i=\$((i + 1)); write_out="\${args[\$i]}" ;; esac i=\$((i + 1)) done ${curl_body} CURL chmod +x "${dir}/curl" export PATH="${dir}:${PATH}" export SITE_URL="https://d111111abcdef8.cloudfront.net" export EXPECTED_SHA="${SHA}" export BUDGET=2 export INTERVAL=0 local log="${dir}/log.txt" set +e bash "${VERIFY}" > "${log}" 2>&1 local code=$? set -e assert_exit "${name}" "${expected}" "${code}" "${log}" rm -rf "${dir}" } run_with_curl "matching-sha" 0 ' [[ -n "${output}" ]] && printf "{\"stage\":\"dev\",\"sha\":\"'"${SHA}"'\"}\n" > "${output}" [[ -n "${write_out}" ]] && printf "200" exit 0 ' run_with_curl "wrong-sha" 1 ' [[ -n "${output}" ]] && printf "{\"stage\":\"dev\",\"sha\":\"unknown\"}\n" > "${output}" [[ -n "${write_out}" ]] && printf "200" exit 0 ' run_with_curl "health-503" 1 ' [[ -n "${output}" ]] && printf "{\"message\":\"nope\"}\n" > "${output}" [[ -n "${write_out}" ]] && printf "503" exit 0 ' if [[ "${failures}" -ne 0 ]]; then echo "FAIL: ${failures} verify-api-health cases failed" >&2 exit 1 fi echo "PASS: API health verify checks"