This commit is contained in:
@@ -4,7 +4,7 @@ set -euo pipefail
|
||||
|
||||
BASE="${1:-http://127.0.0.1:18080}"
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
MISSION_ID="${TEST_MISSION_ID:-testmission00001}"
|
||||
MISSION_ID="${TEST_MISSION_ID:-}"
|
||||
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
@@ -67,7 +67,6 @@ TMP="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
echo "API smoke tests → $BASE"
|
||||
echo "Fixture mission id: $MISSION_ID"
|
||||
echo
|
||||
|
||||
# --- Health & static ---
|
||||
@@ -80,8 +79,30 @@ assert_code "GET /missions.js" 200 "$TMP/missions.js" -X GET "$BASE/missions.js"
|
||||
assert_code "GET /api/state" 200 "$TMP/state.json" -X GET "$BASE/api/state"
|
||||
|
||||
assert_code "GET /api/missions" 200 "$TMP/missions.json" -X GET "$BASE/api/missions"
|
||||
assert_json_true "missions fixture present" "$TMP/missions.json" \
|
||||
'any(m.get("id") == "'"$MISSION_ID"'" for m in doc.get("missions", []))'
|
||||
|
||||
if [[ -z "$MISSION_ID" ]]; then
|
||||
MISSION_ID="$(python3 -c "
|
||||
import json
|
||||
doc = json.load(open('$TMP/missions.json'))
|
||||
missions = doc.get('missions', [])
|
||||
preferred = 'testmission00001'
|
||||
ids = [m.get('id') for m in missions if isinstance(m, dict)]
|
||||
if preferred in ids:
|
||||
print(preferred)
|
||||
elif ids:
|
||||
print(ids[0])
|
||||
")"
|
||||
fi
|
||||
|
||||
if [[ -z "$MISSION_ID" ]]; then
|
||||
log_fail "no mission available for queue tests"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Mission id: $MISSION_ID"
|
||||
echo
|
||||
|
||||
assert_json_true "missions available" "$TMP/missions.json" 'len(doc.get("missions", [])) >= 1'
|
||||
|
||||
# --- Queue pause/continue (chạy sớm, trước các test enqueue khác) ---
|
||||
curl -s -X DELETE "$BASE/api/mission_queue" -o /dev/null || true
|
||||
@@ -153,6 +174,13 @@ assert_json_true "v2 queue entry mission_id" "$TMP/v2q.json" \
|
||||
'doc.get("mission_id") == "'"$MISSION_ID"'"'
|
||||
|
||||
assert_code "GET /api/v2.0.0/mission_queue" 200 "$TMP/v2list.json" -X GET "$BASE/api/v2.0.0/mission_queue"
|
||||
for _ in $(seq 1 15); do
|
||||
curl -s "$BASE/api/v2.0.0/mission_queue" -o "$TMP/v2list.json"
|
||||
if python3 -c "import json; d=json.load(open('$TMP/v2list.json')); exit(0 if isinstance(d,list) and len(d)>=1 else 1)" 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
sleep 0.2
|
||||
done
|
||||
assert_json_true "v2 queue non-empty" "$TMP/v2list.json" 'isinstance(doc, list) and len(doc) >= 1'
|
||||
|
||||
assert_code "GET /api/v2.0.0/status" 200 "$TMP/v2status.json" -X GET "$BASE/api/v2.0.0/status"
|
||||
|
||||
41
scripts/docker-test.sh
Executable file
41
scripts/docker-test.sh
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build image, start container, chạy smoke + pytest trên port 8080.
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
cd "$ROOT"
|
||||
# shellcheck source=docker-lib.sh
|
||||
source "$ROOT/scripts/docker-lib.sh"
|
||||
|
||||
docker_cmd
|
||||
|
||||
BASE="${TEST_BASE_URL:-http://127.0.0.1:8080}"
|
||||
|
||||
echo "==> Docker compose up --build -d"
|
||||
"${DOCKER[@]}" compose up --build -d
|
||||
|
||||
echo "==> Đợi server sẵn sàng ($BASE)"
|
||||
for i in $(seq 1 40); do
|
||||
if curl -sf "$BASE/api/health" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
if ! curl -sf "$BASE/api/health" >/dev/null 2>&1; then
|
||||
echo "Container không phản hồi tại $BASE" >&2
|
||||
"${DOCKER[@]}" logs --tail 30 lidar-manager-limited 2>&1 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "==> Unit + integration tests (local build)"
|
||||
./scripts/run-tests.sh
|
||||
|
||||
echo "==> API smoke (container $BASE)"
|
||||
./scripts/api-smoke.sh "$BASE"
|
||||
|
||||
echo "==> pytest (container $BASE)"
|
||||
TEST_BASE_URL="$BASE" python3 -m pytest tests/test_api_integration.py -q
|
||||
|
||||
echo
|
||||
echo "Docker + tests OK."
|
||||
Reference in New Issue
Block a user