@@ -26,38 +26,153 @@ 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 PostgreSQL (taiga-l02-db, up to 90s)..."
52+ for i in $( seq 1 18) ; do
53+ if docker exec taiga-l02-db pg_isready -U taiga -d taiga > /dev/null 2>&1 ; then
54+ pass " External PostgreSQL healthy"
55+ break
56+ fi
57+ [[ $i -eq 18 ]] && fail " External PostgreSQL timed out after 90s"
58+ sleep 5
59+ done
60+
61+ info " Waiting for external Redis (taiga-l02-redis, up to 60s)..."
62+ for i in $( seq 1 12) ; do
63+ if docker exec taiga-l02-redis redis-cli ping 2> /dev/null | grep -q ' PONG' ; then
64+ pass " External Redis healthy"
65+ break
66+ fi
67+ [[ $i -eq 12 ]] && fail " External Redis timed out after 60s"
68+ sleep 5
69+ done
70+
71+ info " Waiting for Mailhog (taiga-l02-mail, up to 60s)..."
72+ for i in $( seq 1 12) ; do
73+ if curl -sf http://localhost:8710/api/v2/messages > /dev/null 2>&1 ; then
74+ pass " Mailhog API reachable"
75+ break
76+ fi
77+ [[ $i -eq 12 ]] && fail " Mailhog timed out after 60s"
78+ sleep 5
79+ done
80+
81+ info " Waiting for Taiga backend API (taiga-l02-back, up to 180s)..."
82+ for i in $( seq 1 36) ; do
83+ http_code=$( curl -o /dev/null -sw ' %{http_code}' http://localhost:8011/api/v1/ 2> /dev/null || echo " 000" )
84+ if [[ " ${http_code} " =~ ^[234] ]]; then
85+ pass " Taiga backend API responding (HTTP ${http_code} )"
86+ break
87+ fi
88+ [[ $i -eq 36 ]] && fail " Taiga backend timed out after 180s"
89+ sleep 5
90+ done
91+
92+ info " Waiting for Taiga frontend (taiga-l02-front, up to 120s)..."
93+ for i in $( seq 1 24) ; do
94+ if curl -sf http://localhost:8410/ 2> /dev/null | grep -qi ' taiga\|doctype\|html' ; then
95+ pass " Taiga frontend serving HTML"
96+ break
97+ fi
98+ [[ $i -eq 24 ]] && fail " Taiga frontend timed out after 120s"
99+ sleep 5
100+ done
101+
102+ # ── PHASE 3: Functional Tests ─────────────────────────────────────────────────
103+ info " Phase 3: Functional Tests (Lab 15-02 — External Dependencies)"
104+
105+ # Container states
106+ for svc in taiga-l02-db taiga-l02-redis taiga-l02-mail taiga-l02-back taiga-l02-front; do
107+ state=$( docker inspect --format=' {{.State.Status}}' " ${svc} " 2> /dev/null || echo " missing" )
108+ if [[ " ${state} " == " running" ]]; then
109+ pass " Container ${svc} is running"
110+ else
111+ fail " Container ${svc} state: ${state} "
112+ fi
113+ done
114+
115+ # DB connectivity from back container
116+ if docker exec taiga-l02-back bash -c ' python -c "import psycopg2; psycopg2.connect(host=\"taiga-l02-db\",dbname=\"taiga\",user=\"taiga\",password=\"TaigaLab02!\"); print(\"ok\")"' 2> /dev/null | grep -q ' ok' ; then
117+ pass " Backend can connect to external PostgreSQL"
40118else
41- fail " Container is not running"
119+ warn " psycopg2 direct test skipped (may not be installed separately); checking via pg_isready"
120+ if docker exec taiga-l02-db psql -U taiga -d taiga -c ' \dt' 2> /dev/null | grep -qi ' row\|table\|schema' ; then
121+ pass " PostgreSQL taiga database has schema tables"
122+ else
123+ warn " PostgreSQL schema check inconclusive (migrations may not have run yet)"
124+ fi
42125fi
43126
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 15-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"
127+ # Redis connectivity from back container
128+ if docker exec taiga-l02-back bash -c ' python -c "import redis; r=redis.Redis(host=\"taiga-l02-redis\"); r.ping(); print(\"ok\")"' 2> /dev/null | grep -q ' ok' ; then
129+ pass " Backend can connect to external Redis"
130+ else
131+ # Fallback: redis-cli from Redis container itself
132+ if docker exec taiga-l02-redis redis-cli ping 2> /dev/null | grep -q ' PONG' ; then
133+ pass " External Redis is healthy (redis-cli ping)"
134+ else
135+ fail " External Redis not responding"
136+ fi
137+ fi
138+
139+ # Mailhog API format check
140+ mailhog_resp=$( curl -sf http://localhost:8710/api/v2/messages 2> /dev/null || echo " {}" )
141+ if echo " ${mailhog_resp} " | grep -q ' total\|items\|count' ; then
142+ pass " Mailhog API returns valid JSON message list"
143+ else
144+ fail " Mailhog API response unexpected: ${mailhog_resp} "
145+ fi
146+
147+ # HTTP status checks
148+ for url_port in " 8011/api/v1/" " 8410/" ; do
149+ port=$( echo " ${url_port} " | cut -d/ -f1)
150+ path=$( echo " ${url_port} " | cut -d/ -f2-)
151+ http_code=$( curl -o /dev/null -sw ' %{http_code}' " http://localhost:${url_port} " 2> /dev/null || echo " 000" )
152+ if [[ " ${http_code} " =~ ^[234] ]]; then
153+ pass " HTTP GET http://localhost:${url_port} -> ${http_code} "
154+ else
155+ fail " HTTP GET http://localhost:${url_port} -> ${http_code} "
156+ fi
157+ done
158+
159+ # Key env vars present in back container
160+ for var in POSTGRES_HOST TAIGA_SECRET_KEY TAIGA_REDIS_URL EMAIL_HOST; do
161+ if docker exec taiga-l02-back printenv " ${var} " 2> /dev/null | grep -q ' .' ; then
162+ pass " Env var ${var} set in taiga-l02-back"
163+ else
164+ fail " Env var ${var} missing in taiga-l02-back"
165+ fi
166+ done
167+
168+ # Volume existence
169+ for vol in taiga-l02-db-data taiga-l02-static taiga-l02-media; do
170+ if docker volume ls --format ' {{.Name}}' | grep -q " ${vol} " ; then
171+ pass " Volume ${vol} exists"
172+ else
173+ fail " Volume ${vol} missing"
174+ fi
175+ done
61176
62177# ── Results ───────────────────────────────────────────────────────────────────
63178echo " "
0 commit comments