#!/usr/bin/env bash # # Orchestrateur des tests d'intégration : # 1. Build l'image proxy. # 2. Démarre la stack docker-compose.test.yml (upstream + client + proxy initial). # 3. Exécute chaque tests/cases/*.sh dans un sous-shell. # 4. Tear down systématique en fin (succès ou échec). set -euo pipefail PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$PROJECT_ROOT" # shellcheck source-path=SCRIPTDIR # shellcheck source=lib.sh source "$PROJECT_ROOT/tests/lib.sh" cleanup() { t_log "Tear down de la stack de tests..." "${COMPOSE[@]}" down --remove-orphans --volumes >/dev/null 2>&1 || true } trap cleanup EXIT t_log "Build de l'image maintenance-proxy:test..." "${COMPOSE[@]}" build --quiet proxy t_log "Démarrage initial de la stack..." MAINTENANCE_MODE="whitelist" \ MAINTENANCE_IP_LIST="172.28.5.50" \ "${COMPOSE[@]}" up -d >/dev/null # Attente que le client ait fini d'installer curl (entrypoint contient apk add). for _ in $(seq 1 30); do if "${COMPOSE[@]}" exec -T client sh -c 'command -v curl' >/dev/null 2>&1; then break fi sleep 1 done if ! "${COMPOSE[@]}" exec -T client sh -c 'command -v curl' >/dev/null 2>&1; then echo "[test] FAIL: curl indisponible dans le conteneur client" >&2 exit 1 fi shopt -s nullglob cases=("$PROJECT_ROOT/tests/cases/"*.sh) if [[ ${#cases[@]} -eq 0 ]]; then echo "[test] aucun cas trouvé dans tests/cases/" >&2 exit 1 fi passed=0 failed=0 failed_names=() for case_path in "${cases[@]}"; do case_name="$(basename "$case_path" .sh)" t_log "▶ $case_name" if bash "$case_path"; then t_log " ✓ OK" passed=$((passed + 1)) else t_log " ✗ FAIL" failed=$((failed + 1)) failed_names+=("$case_name") fi done echo echo "===============================================" echo " Résultats : $passed OK / $failed FAIL / $((passed + failed)) total" echo "===============================================" if [[ $failed -gt 0 ]]; then echo "Cas échoués :" >&2 for n in "${failed_names[@]}"; do echo " - $n" >&2 done exit 1 fi