@@ -26,38 +26,120 @@ echo -e "${CYAN} Module: ${MODULE}${NC}"
2626echo -e " ${CYAN} ======================================${NC} "
2727echo " "
2828
29+ # ── Cleanup control ───────────────────────────────────────────────────────────
30+ CLEANUP=true
31+ [[ " ${1:- } " == " --no-cleanup" ]] && CLEANUP=false
32+
33+ cleanup () {
34+ if [[ " ${CLEANUP} " == " true" ]]; then
35+ info " Phase 4: Cleanup"
36+ docker compose -f " ${COMPOSE_FILE} " down -v --remove-orphans 2> /dev/null || true
37+ info " Cleanup complete"
38+ else
39+ info " Skipping cleanup (--no-cleanup)"
40+ fi
41+ }
42+ trap cleanup EXIT
43+
2944# ── PHASE 1: Setup ────────────────────────────────────────────────────────────
3045info " Phase 1: Setup"
3146docker compose -f " ${COMPOSE_FILE} " up -d
32- info " Waiting 30s for ${MODULE} to initialize..."
33- sleep 30
3447
3548# ── PHASE 2: Health Checks ────────────────────────────────────────────────────
3649info " Phase 2: Health Checks"
3750
38- if docker compose -f " ${COMPOSE_FILE} " ps | grep -q " running\|Up" ; then
39- pass " Container is running"
51+ info " Waiting for external MariaDB (glpi-l02-db, up to 90s)..."
52+ for i in $( seq 1 18) ; do
53+ if docker exec glpi-l02-db mysqladmin ping -uroot -pRootLab02! --silent 2> /dev/null; then
54+ pass " External MariaDB healthy"
55+ break
56+ fi
57+ [[ $i -eq 18 ]] && fail " External MariaDB timed out after 90s"
58+ sleep 5
59+ done
60+
61+ info " Waiting for Mailhog (glpi-l02-mail, up to 60s)..."
62+ for i in $( seq 1 12) ; do
63+ if curl -sf http://localhost:8712/api/v2/messages > /dev/null 2>&1 ; then
64+ pass " Mailhog API reachable"
65+ break
66+ fi
67+ [[ $i -eq 12 ]] && fail " Mailhog timed out after 60s"
68+ sleep 5
69+ done
70+
71+ info " Waiting for GLPI web (glpi-l02-app, up to 300s)..."
72+ for i in $( seq 1 30) ; do
73+ if curl -sf http://localhost:8412/ 2> /dev/null | grep -qi ' glpi\|login\|doctype\|html' ; then
74+ pass " GLPI web serving HTML"
75+ break
76+ fi
77+ [[ $i -eq 30 ]] && fail " GLPI web timed out after 300s"
78+ sleep 10
79+ done
80+
81+ # ── PHASE 3: Functional Tests ─────────────────────────────────────────────────
82+ info " Phase 3: Functional Tests (Lab 17-02 — External Dependencies)"
83+
84+ # Container states
85+ for svc in glpi-l02-db glpi-l02-mail glpi-l02-app; do
86+ state=$( docker inspect --format=' {{.State.Status}}' " ${svc} " 2> /dev/null || echo " missing" )
87+ if [[ " ${state} " == " running" ]]; then
88+ pass " Container ${svc} is running"
89+ else
90+ fail " Container ${svc} state: ${state} "
91+ fi
92+ done
93+
94+ # DB connectivity from app container
95+ table_count=$( docker exec glpi-l02-db \
96+ mysql -uglpi -pGlpiLab02! glpidb -e ' SHOW TABLES;' 2> /dev/null | wc -l | tr -d ' ' )
97+ if [[ " ${table_count} " -gt 10 ]]; then
98+ pass " GLPI database has ${table_count} tables (setup ran)"
4099else
41- fail " Container is not running"
100+ warn " GLPI database tables: ${table_count} (setup may still be running) "
42101fi
43102
44- # ── PHASE 3: Functional Tests ─────────────────────────────────────────────────
45- info " Phase 3: Functional Tests (Lab 02 — External Dependencies)"
46-
47- # TODO: Add module-specific functional tests here
48- # Example:
49- # if curl -sf http://localhost:80/health > /dev/null 2>&1; then
50- # pass "Health endpoint responds"
51- # else
52- # fail "Health endpoint not reachable"
53- # fi
54-
55- warn " Functional tests for Lab 17-02 pending implementation"
56-
57- # ── PHASE 4: Cleanup ──────────────────────────────────────────────────────────
58- info " Phase 4: Cleanup"
59- docker compose -f " ${COMPOSE_FILE} " down -v --remove-orphans
60- info " Cleanup complete"
103+ # Mailhog API format check
104+ mailhog_resp=$( curl -sf http://localhost:8712/api/v2/messages 2> /dev/null || echo " {}" )
105+ if echo " ${mailhog_resp} " | grep -q ' total\|items\|count' ; then
106+ pass " Mailhog API returns valid JSON message list"
107+ else
108+ fail " Mailhog API response unexpected: ${mailhog_resp} "
109+ fi
110+
111+ # HTTP status check
112+ http_code=$( curl -o /dev/null -sw ' %{http_code}' -L http://localhost:8412/ 2> /dev/null || echo " 000" )
113+ if [[ " ${http_code} " =~ ^[234] ]]; then
114+ pass " GLPI HTTP GET / -> ${http_code} "
115+ else
116+ fail " GLPI HTTP GET / -> ${http_code} "
117+ fi
118+
119+ # Login page present
120+ if curl -sf -L http://localhost:8412/ 2> /dev/null | grep -qi ' glpi\|login\|glpikey\|password' ; then
121+ pass " GLPI login page rendered"
122+ else
123+ warn " GLPI login page check inconclusive"
124+ fi
125+
126+ # Key env vars present in app container
127+ for var in MARIADB_HOST MARIADB_DATABASE MARIADB_USER; do
128+ if docker exec glpi-l02-app printenv " ${var} " 2> /dev/null | grep -q ' .' ; then
129+ pass " Env var ${var} set in glpi-l02-app"
130+ else
131+ fail " Env var ${var} missing in glpi-l02-app"
132+ fi
133+ done
134+
135+ # Volume existence
136+ for vol in glpi-l02-db-data glpi-l02-files glpi-l02-plugins; do
137+ if docker volume ls --format ' {{.Name}}' | grep -q " ${vol} " ; then
138+ pass " Volume ${vol} exists"
139+ else
140+ fail " Volume ${vol} missing"
141+ fi
142+ done
61143
62144# ── Results ───────────────────────────────────────────────────────────────────
63145echo " "
0 commit comments