refactor: update French comments and variable names in test-endpoints script for consistency

This commit is contained in:
mirage
2026-03-26 15:20:27 +01:00
parent 4301cd0f72
commit 45b91d4c98

View File

@@ -1,13 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# ============================================================================= # =============================================================================
# test-endpoints.sh # test-endpoints.sh
# Tests all Webzine endpoints and reports which ones exceed the threshold. # Teste tous les endpoints du Webzine et signale ceux qui dépassent le seuil.
# #
# Usage: # Usage :
# ./scripts/test-endpoints.sh [BASE_URL] [MAX_MS] # ./scripts/test-endpoints.sh [URL_BASE] [MAX_MS]
# #
# Examples: # Exemples :
# ./scripts/test-endpoints.sh # defaults: localhost:5038, 1000ms # ./scripts/test-endpoints.sh # défauts : localhost:5038, 1000ms
# ./scripts/test-endpoints.sh http://localhost:5038 500 # ./scripts/test-endpoints.sh http://localhost:5038 500
# ============================================================================= # =============================================================================
@@ -15,207 +15,213 @@ set -euo pipefail
BASE_URL="${1:-http://localhost:5038}" BASE_URL="${1:-http://localhost:5038}"
MAX_MS="${2:-1000}" MAX_MS="${2:-1000}"
REPORT_FILE="/tmp/webzine_endpoint_report.txt" RAPPORT_FICHIER="/tmp/webzine_rapport_endpoints.txt"
FAILED=0 ECHECS=0
TOTAL=0 TOTAL=0
# ── Colours ────────────────────────────────────────────────────────────────── # ── Couleurs ──────────────────────────────────────────────────────────────────
RED='\033[0;31m' ROUGE='\033[0;31m'
YELLOW='\033[1;33m' JAUNE='\033[1;33m'
GREEN='\033[0;32m' VERT='\033[0;32m'
CYAN='\033[0;36m' CYAN='\033[0;36m'
BOLD='\033[1m' GRAS='\033[1m'
RESET='\033[0m' RESET='\033[0m'
# ── Helpers ────────────────────────────────────────────────────────────────── # ── Fonctions utilitaires ──────────────────────────────────────────────────────
log() { echo -e "$*"; } log() { echo -e "$*"; }
pass() { log "${GREEN}[PASS]${RESET} $*"; } succes() { log "${VERT}[OK]${RESET} $*"; }
fail() { log "${RED}[FAIL]${RESET} $*"; FAILED=$((FAILED + 1)); } echec() { log "${ROUGE}[ÉCHEC]${RESET} $*"; ECHECS=$((ECHECS + 1)); }
slow() { log "${YELLOW}[SLOW]${RESET} $*"; FAILED=$((FAILED + 1)); } lent() { log "${JAUNE}[LENT]${RESET} $*"; ECHECS=$((ECHECS + 1)); }
info() { log "${CYAN}$*${RESET}"; } info() { log "${CYAN}$*${RESET}"; }
# ── check_endpoint ──────────────────────────────────────────────────────────── # ── verifier_endpoint ─────────────────────────────────────────────────────────
# Arguments: # Arguments :
# $1 HTTP method (GET | POST) # $1 Méthode HTTP (GET | POST)
# $2 URL (absolute) # $2 URL (absolue)
# $3 Label (human-readable) # $3 Libel (texte lisible)
# $4 Body data (optional, for POST) # $4 Corps (optionnel, pour POST)
# $5 Content-Type (optional, default: application/x-www-form-urlencoded) # $5 Content-Type (optionnel, défaut : application/x-www-form-urlencoded)
# ───────────────────────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────────────────────
check_endpoint() { verifier_endpoint() {
local METHOD="${1:-GET}" local METHODE="${1:-GET}"
local URL="$2" local URL="$2"
local LABEL="$3" local LIBELLE="$3"
local BODY="${4:-}" local CORPS="${4:-}"
local CONTENT_TYPE="${5:-application/x-www-form-urlencoded}" local TYPE_CONTENU="${5:-application/x-www-form-urlencoded}"
TOTAL=$((TOTAL + 1)) TOTAL=$((TOTAL + 1))
if [ "$METHOD" = "POST" ] && [ -n "$BODY" ]; then # Exécution de la requête selon la méthode HTTP
RESPONSE=$(curl -s -o /dev/null \ if [ "$METHODE" = "POST" ] && [ -n "$CORPS" ]; then
REPONSE=$(curl -s -o /dev/null \
-w "%{http_code}|%{time_total}" \ -w "%{http_code}|%{time_total}" \
-X POST \ -X POST \
-H "Content-Type: $CONTENT_TYPE" \ -H "Content-Type: $TYPE_CONTENU" \
-d "$BODY" \ -d "$CORPS" \
--max-time 10 \ --max-time 10 \
"$URL" 2>&1) || RESPONSE="000|9.999" "$URL" 2>&1) || REPONSE="000|9.999"
else else
RESPONSE=$(curl -s -o /dev/null \ REPONSE=$(curl -s -o /dev/null \
-w "%{http_code}|%{time_total}" \ -w "%{http_code}|%{time_total}" \
-X GET \ -X GET \
--max-time 10 \ --max-time 10 \
--location \ --location \
"$URL" 2>&1) || RESPONSE="000|9.999" "$URL" 2>&1) || REPONSE="000|9.999"
fi fi
HTTP_CODE=$(echo "$RESPONSE" | cut -d'|' -f1) # Extraction du code HTTP et du temps de réponse
TIME_TOTAL=$(echo "$RESPONSE" | cut -d'|' -f2) CODE_HTTP=$(echo "$REPONSE" | cut -d'|' -f1)
TEMPS_TOTAL=$(echo "$REPONSE" | cut -d'|' -f2)
# Convert to integer milliseconds — awk is locale-safe, no bc/printf decimal issues # Conversion en millisecondes entières — awk évite les problèmes de locale décimale
TIME_MS=$(awk "BEGIN {printf \"%.0f\", $TIME_TOTAL * 1000}") TEMPS_MS=$(awk "BEGIN {printf \"%.0f\", $TEMPS_TOTAL * 1000}")
# Evaluate result # Évaluation du résultat : erreur serveur, dépassement de seuil ou succès
if [ "${HTTP_CODE:-0}" -ge 500 ] 2>/dev/null; then if [ "${CODE_HTTP:-0}" -ge 500 ] 2>/dev/null; then
slow "$LABEL → HTTP $HTTP_CODE (${TIME_MS}ms)" echec "$LIBELLE → HTTP $CODE_HTTP (${TEMPS_MS}ms)"
echo "[FAIL] $LABEL → HTTP $HTTP_CODE (${TIME_MS}ms)" >> "$REPORT_FILE" echo "[ÉCHEC] $LIBELLE → HTTP $CODE_HTTP (${TEMPS_MS}ms)" >> "$RAPPORT_FICHIER"
elif [ "${TIME_MS:-99999}" -gt "$MAX_MS" ] 2>/dev/null; then elif [ "${TEMPS_MS:-99999}" -gt "$MAX_MS" ] 2>/dev/null; then
slow "$LABEL${TIME_MS}ms exceeds ${MAX_MS}ms threshold" lent "$LIBELLE${TEMPS_MS}ms dépasse le seuil de ${MAX_MS}ms"
echo "[SLOW] $LABEL${TIME_MS}ms (limit: ${MAX_MS}ms)" >> "$REPORT_FILE" echo "[LENT] $LIBELLE${TEMPS_MS}ms (limite : ${MAX_MS}ms)" >> "$RAPPORT_FICHIER"
else else
pass "$LABEL${TIME_MS}ms" succes "$LIBELLE${TEMPS_MS}ms"
echo "[OK] $LABEL${TIME_MS}ms" >> "$REPORT_FILE" echo "[OK] $LIBELLE${TEMPS_MS}ms" >> "$RAPPORT_FICHIER"
fi fi
} }
# ============================================================================= # =============================================================================
# MAIN # PROGRAMME PRINCIPAL
# ============================================================================= # =============================================================================
# Initialise report # Initialisation du fichier de rapport
> "$REPORT_FILE" > "$RAPPORT_FICHIER"
cat >> "$REPORT_FILE" <<EOF cat >> "$RAPPORT_FICHIER" <<EOF
=== Webzine Endpoint Performance Report === === Rapport de performance des endpoints Webzine ===
Base URL : $BASE_URL URL de base : $BASE_URL
Threshold: ${MAX_MS}ms Seuil : ${MAX_MS}ms
Date : $(date -u +"%Y-%m-%dT%H:%M:%SZ") Date : $(date -u +"%Y-%m-%dT%H:%M:%SZ")
EOF EOF
log "" log ""
info "╔══════════════════════════════════════════════════════════╗" info "╔══════════════════════════════════════════════════════════╗"
info "║ Webzine Endpoint Performance Test ║" info "║ Webzine Test de performance des endpoints ║"
info "╚══════════════════════════════════════════════════════════╝" info "╚══════════════════════════════════════════════════════════╝"
info " Base URL : $BASE_URL" info " URL de base : $BASE_URL"
info " Threshold: ${MAX_MS}ms" info " Seuil : ${MAX_MS}ms"
log "" log ""
# ── PUBLIC SECTION ──────────────────────────────────────────────────────────── # ── SECTION PUBLIQUE ──────────────────────────────────────────────────────────
info "── Public endpoints ─────────────────────────────────────" info "── Endpoints publics ─────────────────────────────────────"
check_endpoint GET "$BASE_URL/" "GET / (Accueil)" verifier_endpoint GET "$BASE_URL/" "GET / (Accueil)"
check_endpoint GET "$BASE_URL/Accueil" "GET /Accueil" verifier_endpoint GET "$BASE_URL/Accueil" "GET /Accueil"
check_endpoint GET "$BASE_URL/Contact" "GET /Contact" verifier_endpoint GET "$BASE_URL/Contact" "GET /Contact"
log "" log ""
info "── Titre Détails ───────────────────────────────────────" info "── Titre Détails ───────────────────────────────────────"
# Test des pages de détail pour les 5 premiers titres
for ID in 1 2 3 4 5; do for ID in 1 2 3 4 5; do
check_endpoint GET "$BASE_URL/titre/$ID" "GET /titre/$ID" verifier_endpoint GET "$BASE_URL/titre/$ID" "GET /titre/$ID"
done done
log "" log ""
info "── Titre Par style ─────────────────────────────────────" info "── Titre Par style ─────────────────────────────────────"
# Test du filtrage par style musical
STYLES=("Rock" "Pop" "Rap" "Jazz" "Metal" "Electronic" "Hip-Hop" "Soul" "Funk") STYLES=("Rock" "Pop" "Rap" "Jazz" "Metal" "Electronic" "Hip-Hop" "Soul" "Funk")
for STYLE in "${STYLES[@]}"; do for STYLE in "${STYLES[@]}"; do
ENCODED=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$STYLE'))" 2>/dev/null || echo "$STYLE") ENCODE=$(python3 -c "import urllib.parse; print(urllib.parse.quote('$STYLE'))" 2>/dev/null || echo "$STYLE")
check_endpoint GET "$BASE_URL/titre/style/$ENCODED" "GET /titre/style/$STYLE" verifier_endpoint GET "$BASE_URL/titre/style/$ENCODE" "GET /titre/style/$STYLE"
done done
log "" log ""
info "── Artiste ───────────────────────────────────────────────" info "── Artiste ───────────────────────────────────────────────"
# Test des pages artiste avec des noms en kebab-case
ARTISTES=("fatal-bazooka" "daft-punk" "justice" "kraftwerk") ARTISTES=("fatal-bazooka" "daft-punk" "justice" "kraftwerk")
for ARTISTE in "${ARTISTES[@]}"; do for ARTISTE in "${ARTISTES[@]}"; do
check_endpoint GET "$BASE_URL/artiste/$ARTISTE" "GET /artiste/$ARTISTE" verifier_endpoint GET "$BASE_URL/artiste/$ARTISTE" "GET /artiste/$ARTISTE"
done done
log "" log ""
info "── Recherche (POST) ──────────────────────────────────────" info "── Recherche (POST) ──────────────────────────────────────"
# Test de la recherche plein texte par mots-clés
MOTS=("rock" "jazz" "pop" "metal") MOTS=("rock" "jazz" "pop" "metal")
for MOT in "${MOTS[@]}"; do for MOT in "${MOTS[@]}"; do
check_endpoint POST "$BASE_URL/recherche" \ verifier_endpoint POST "$BASE_URL/recherche" \
"POST /recherche (mot=$MOT)" \ "POST /recherche (mot=$MOT)" \
"mot=$MOT" "mot=$MOT"
done done
log "" log ""
# ── ADMINISTRATION SECTION ──────────────────────────────────────────────────── # ── SECTION ADMINISTRATION ────────────────────────────────────────────────────
info "── Administration Dashboard ────────────────────────────" info "── Administration Tableau de bord ──────────────────────"
check_endpoint GET "$BASE_URL/Administration/Dashboard" "GET /Administration/Dashboard" verifier_endpoint GET "$BASE_URL/Administration/Dashboard" "GET /Administration/Dashboard"
log "" log ""
info "── Administration Artiste ──────────────────────────────" info "── Administration Artiste ──────────────────────────────"
check_endpoint GET "$BASE_URL/Administration/Artiste" "GET /Administration/Artiste (Index)" verifier_endpoint GET "$BASE_URL/Administration/Artiste" "GET /Administration/Artiste (liste)"
check_endpoint GET "$BASE_URL/Administration/Artiste/Create" "GET /Administration/Artiste/Create" verifier_endpoint GET "$BASE_URL/Administration/Artiste/Create" "GET /Administration/Artiste/Create"
check_endpoint GET "$BASE_URL/Administration/Artiste/Edit/1" "GET /Administration/Artiste/Edit/1" verifier_endpoint GET "$BASE_URL/Administration/Artiste/Edit/1" "GET /Administration/Artiste/Edit/1"
check_endpoint GET "$BASE_URL/Administration/Artiste/Delete/1" "GET /Administration/Artiste/Delete/1" verifier_endpoint GET "$BASE_URL/Administration/Artiste/Delete/1" "GET /Administration/Artiste/Delete/1"
log "" log ""
info "── Administration Commentaire ──────────────────────────" info "── Administration Commentaire ──────────────────────────"
check_endpoint GET "$BASE_URL/Administration/Commentaire" "GET /Administration/Commentaire (Index)" verifier_endpoint GET "$BASE_URL/Administration/Commentaire" "GET /Administration/Commentaire (liste)"
check_endpoint GET "$BASE_URL/Administration/Commentaire/Delete/1" \ verifier_endpoint GET "$BASE_URL/Administration/Commentaire/Delete/1" "GET /Administration/Commentaire/Delete/1"
"GET /Administration/Commentaire/Delete/1"
log "" log ""
info "── Administration Style ────────────────────────────────" info "── Administration Style ────────────────────────────────"
check_endpoint GET "$BASE_URL/Administration/Style" "GET /Administration/Style (Index)" verifier_endpoint GET "$BASE_URL/Administration/Style" "GET /Administration/Style (liste)"
check_endpoint GET "$BASE_URL/Administration/Style/Create" "GET /Administration/Style/Create" verifier_endpoint GET "$BASE_URL/Administration/Style/Create" "GET /Administration/Style/Create"
check_endpoint GET "$BASE_URL/Administration/Style/Edit/1" "GET /Administration/Style/Edit/1" verifier_endpoint GET "$BASE_URL/Administration/Style/Edit/1" "GET /Administration/Style/Edit/1"
check_endpoint GET "$BASE_URL/Administration/Style/Delete/1" "GET /Administration/Style/Delete/1" verifier_endpoint GET "$BASE_URL/Administration/Style/Delete/1" "GET /Administration/Style/Delete/1"
log "" log ""
info "── Administration Titre ────────────────────────────────" info "── Administration Titre ────────────────────────────────"
check_endpoint GET "$BASE_URL/Administration/Titre" "GET /Administration/Titre (Index)" verifier_endpoint GET "$BASE_URL/Administration/Titre" "GET /Administration/Titre (liste)"
check_endpoint GET "$BASE_URL/Administration/Titre/Create" "GET /Administration/Titre/Create" verifier_endpoint GET "$BASE_URL/Administration/Titre/Create" "GET /Administration/Titre/Create"
check_endpoint GET "$BASE_URL/Administration/Titre/Edit/1" "GET /Administration/Titre/Edit/1" verifier_endpoint GET "$BASE_URL/Administration/Titre/Edit/1" "GET /Administration/Titre/Edit/1"
check_endpoint GET "$BASE_URL/Administration/Titre/Delete/1" "GET /Administration/Titre/Delete/1" verifier_endpoint GET "$BASE_URL/Administration/Titre/Delete/1" "GET /Administration/Titre/Delete/1"
# ── SUMMARY ─────────────────────────────────────────────────────────────────── # ── RÉCAPITULATIF ─────────────────────────────────────────────────────────────
PASSED=$((TOTAL - FAILED)) REUSSIS=$((TOTAL - ECHECS))
log "" log ""
info "╔══════════════════════════════════════════════════════════╗" info "╔══════════════════════════════════════════════════════════╗"
info "║ Results ║" info "║ Résultats ║"
info "╚══════════════════════════════════════════════════════════╝" info "╚══════════════════════════════════════════════════════════╝"
log " Total : ${TOTAL}" log " Total : ${TOTAL}"
log " ${GREEN}Passed${RESET} : ${PASSED}" log " ${VERT}Réussis${RESET} : ${REUSSIS}"
if [ "$FAILED" -gt 0 ]; then if [ "$ECHECS" -gt 0 ]; then
log " ${RED}Failed${RESET} : ${FAILED}" log " ${ROUGE}Échecs${RESET} : ${ECHECS}"
log "" log ""
log "${RED}${BOLD} FAILED ENDPOINTS:${RESET}" log "${ROUGE}${GRAS}❌ ENDPOINTS EN ÉCHEC :${RESET}"
grep -E "^\[(FAIL|SLOW)\]" "$REPORT_FILE" | while IFS= read -r line; do # Affichage de tous les endpoints ayant échoué ou dépassé le seuil
log " ${RED}${RESET} $line" grep -E "^\[(ÉCHEC|LENT)\]" "$RAPPORT_FICHIER" | while IFS= read -r ligne; do
log " ${ROUGE}${RESET} $ligne"
done done
log "" log ""
log "${RED}PR should be rejected. Fix the endpoints above.${RESET}" log "${ROUGE}La PR doit être rejetée. Corrigez les endpoints ci-dessus.${RESET}"
else else
log " ${GREEN}Failed${RESET} : 0" log " ${VERT}Échecs${RESET} : 0"
log "" log ""
log "${GREEN}${BOLD}All endpoints are within the ${MAX_MS}ms threshold.${RESET}" log "${VERT}${GRAS}Tous les endpoints respectent le seuil de ${MAX_MS}ms.${RESET}"
fi fi
log "" log ""
log "Full report saved to: ${REPORT_FILE}" log "Rapport complet enregistré dans : ${RAPPORT_FICHIER}"
log "" log ""
# Write summary to report # Écriture du récapitulatif dans le rapport
cat >> "$REPORT_FILE" <<EOF cat >> "$RAPPORT_FICHIER" <<EOF
=== Summary === === Récapitulatif ===
Total : $TOTAL Total : $TOTAL
Passed: $PASSED Réussis : $REUSSIS
Failed: $FAILED Échecs : $ECHECS
EOF EOF
# Exit with failure code so CI picks it up # Code de sortie non nul si des échecs ont été détectés — permet à la CI de bloquer
exit "$FAILED" exit "$ECHECS"