#!/usr/bin/env bash # Quick check of a running CodeCraft: health, version, web UI, terminal client download. # # Usage: scripts/smoke-test.sh [URL] [EXPECTED_VERSION] # URL base URL (default http://127.0.0.1:8787) # EXPECTED_VERSION e.g. 202611-00003 (without "v"); checked when given # # Exit code 0 when everything answers, 1 otherwise. set -uo pipefail url="${1:-http://127.0.0.1:8787}" url="${url%/}" want="${2:-}" want="${want#v}" fail=0 check() { if [[ "$2" == ok ]]; then printf ' ok %s\n' "$1"; else printf ' FAIL %s (%s)\n' "$1" "$2"; fail=1; fi; } echo "smoke test: $url" health="" for _ in $(seq 1 60); do health=$(curl -fsS -m 5 "$url/api/health" 2>/dev/null) && break sleep 2 done [[ -n "$health" ]] && check "health" ok || check "health" "no answer after 2 minutes" if [[ -n "$health" ]]; then version=$(sed -n 's/.*"version":"\([^"]*\)".*/\1/p' <<<"$health") if [[ -n "$want" && "$version" != "$want" ]]; then check "version $version" "expected $want"; else check "version ${version:-?}" ok; fi grep -q '"ok":true' <<<"$health" && check "server reports ok" ok || check "server reports ok" "$health" fi code=$(curl -s -o /dev/null -m 10 -w '%{http_code}' "$url/") [[ "$code" == 200 ]] && check "web UI" ok || check "web UI" "HTTP $code" code=$(curl -s -o /dev/null -m 10 -w '%{http_code}' "$url/cli/install.sh") [[ "$code" == 200 ]] && check "terminal client install script" ok || check "terminal client install script" "HTTP $code" code=$(curl -s -o /dev/null -m 60 -w '%{http_code}' "$url/cli/download/linux-x86_64") [[ "$code" == 200 ]] && check "terminal client download" ok || check "terminal client download" "HTTP $code" exit $fail