Files
rename-mvp/regression_tests.sh
2026-03-07 13:22:52 +01:00

116 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [ -z "${BASE_URL:-}" ]; then
if curl --silent --fail http://127.0.0.1:8085/api/health >/dev/null 2>&1; then
BASE_URL="http://127.0.0.1:8085"
elif curl --silent --fail http://host.containers.internal:8085/api/health >/dev/null 2>&1; then
BASE_URL="http://host.containers.internal:8085"
else
echo "ERROR: could not determine BASE_URL. Tried 127.0.0.1 and host.containers.internal." >&2
exit 1
fi
fi
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
echo "== Regression test 1: health =="
curl --fail --silent --show-error \
"${BASE_URL}/api/health" \
-o "${TMP_DIR}/health.json"
cat "${TMP_DIR}/health.json"
python3 - "${TMP_DIR}/health.json" <<'PY'
import json
import sys
from pathlib import Path
path = Path(sys.argv[1])
data = json.loads(path.read_text(encoding="utf-8"))
assert isinstance(data, dict), "health response must be an object"
assert data.get("status") == "ok", "health.status must be 'ok'"
print("health JSON validation passed")
PY
echo
echo "== Regression test 2: tvdb auth-status =="
curl --fail --silent --show-error \
"${BASE_URL}/api/tvdb/auth-status" \
-o "${TMP_DIR}/auth_status.json"
cat "${TMP_DIR}/auth_status.json"
python3 - "${TMP_DIR}/auth_status.json" <<'PY'
import json
import sys
from pathlib import Path
path = Path(sys.argv[1])
data = json.loads(path.read_text(encoding="utf-8"))
assert isinstance(data, dict), "auth-status response must be an object"
required_keys = [
"configured",
"has_token",
"expires_at",
"renew_after",
"token_source",
]
for key in required_keys:
assert key in data, f"auth-status missing key: {key}"
assert isinstance(data["configured"], bool), "configured must be boolean"
assert isinstance(data["has_token"], bool), "has_token must be boolean"
assert data["token_source"] in {"none", "login", "cached", "renewed"}, \
"token_source must be one of none/login/cached/renewed"
print("auth-status JSON validation passed")
PY
echo
echo "== Regression test 3: tvdb search =="
curl --fail --silent --show-error \
"${BASE_URL}/api/tvdb/search?q=elsbeth" \
-o "${TMP_DIR}/search.json"
cat "${TMP_DIR}/search.json"
python3 - "${TMP_DIR}/search.json" <<'PY'
import json
import sys
from pathlib import Path
path = Path(sys.argv[1])
data = json.loads(path.read_text(encoding="utf-8"))
assert isinstance(data, dict), "search response must be an object"
assert "items" in data, "search response missing items"
assert isinstance(data["items"], list), "items must be a list"
assert len(data["items"]) > 0, "items list must not be empty"
first = data["items"][0]
assert isinstance(first, dict), "first item must be an object"
required_item_keys = ["id", "name", "year", "display_name"]
for key in required_item_keys:
assert key in first, f"search item missing key: {key}"
names = [
(item.get("display_name") or item.get("name") or "")
for item in data["items"]
]
assert any("Elsbeth" in name for name in names), \
"expected at least one search result containing 'Elsbeth'"
print("search JSON validation passed")
PY
echo
echo "All regression tests passed."