-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·49 lines (41 loc) · 1.21 KB
/
test.sh
File metadata and controls
executable file
·49 lines (41 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
set -euo pipefail
# Test runner and optional health check
# Usage:
# ./test.sh # run pytest
# ./test.sh --health # run pytest, then quick health check against local server
# ./test.sh --url http://localhost:8000 # override base URL for health check
PROJECT_ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_ROOT"
DO_HEALTH=0
BASE_URL="http://localhost:8000"
while [[ $# -gt 0 ]]; do
case "$1" in
--health)
DO_HEALTH=1; shift ;;
--url)
BASE_URL="$2"; shift 2 ;;
*) echo "Unknown option: $1" >&2; exit 1 ;;
esac
done
if [[ -d venv ]]; then
source venv/bin/activate
fi
if ! command -v pytest >/dev/null 2>&1; then
echo "Installing pytest..."
pip install pytest >/dev/null
fi
echo "Running tests with verbose output..."
pytest -vv --maxfail=1 --durations=5 || { echo "Tests failed" >&2; exit 1; }
if [[ "$DO_HEALTH" -eq 1 ]]; then
echo "Health check: ${BASE_URL}/"
set +e
curl -s -o /dev/null -w "%{http_code}\n" "${BASE_URL}/" | grep -E "^(200|302)$" >/dev/null
STATUS=$?
set -e
if [[ $STATUS -ne 0 ]]; then
echo "Health check failed. Is the server running? Try: ./run_voice.sh" >&2
exit 1
fi
echo "Health check passed."
fi