#!/usr/bin/env bash # Smoke-test a deployed release through its public HTTPS URL, using a release record. # Usage: pricing/ci/smoke.sh pricing/releases/v1-staging.yml set -euo pipefail record="$1" val() { awk -v k="$1:" '$1 == k { print $2 }' "$record"; } url="$(val public_url)"; version="$(val expected_version)" commit="$(val expected_commit)"; total="$(val expected_total)" echo "Smoke test $url at $(date -u +%Y-%m-%dT%H:%M:%SZ): expect $version $commit total $total" health="$(curl -fsS --max-time 10 "$url/health")" identity="$(curl -fsS --max-time 10 "$url/")" price="$(curl -fsS --max-time 10 "$url/price?quantity=3")" bad="$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "$url/price?quantity=0")" echo "GET /health -> $health" echo "GET / -> $identity" echo "GET /price?quantity=3 -> $price" echo "GET /price?quantity=0 -> HTTP $bad" python3 - "$health" "$identity" "$price" "$bad" "$version" "$commit" "$total" <<'EOF' import json, sys health, identity, price = (json.loads(x) for x in sys.argv[1:4]) bad, version, commit, total = sys.argv[4:8] assert health["status"] == "ok", "health" assert identity["version"] == version, f"version {identity['version']} != {version}" assert identity["commit"] == commit, f"commit {identity['commit']} != {commit}" assert int(price["total"]) == int(total), f"total {price['total']} != {total}" assert bad == "400", f"invalid input returned {bad}" print("SMOKE PASS") EOF