Files
laboratori-cloud/labs/lab-05-database/tests/quick-test.sh
Luca Sacchi Ricciardi cfbdb1efc8 test(06-01): create test infrastructure for Lab 05 Database & RDS
Test Scripts (7 files, 1000+ lines):
- 01-database-creation-test.sh: PostgreSQL creation and initialization
- 02-private-network-test.sh: Private network isolation (INF-02)
- 03-persistence-test.sh: Data persistence verification (INF-04)
- 04-security-test.sh: Security compliance (INF-01, INF-02, INF-03)
- 99-final-verification.sh: End-to-end student verification
- run-all-tests.sh: Test orchestration with fail-fast
- quick-test.sh: Quick validation (< 30s)

Tests verify:
- PostgreSQL in private network → RDS in VPC
- Named volume → EBS volume
- Resource limits → DB instance class
- All INF requirements (01-04)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-03 17:39:58 +02:00

112 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Lab 05 - Database & RDS
# Quick Test Script (< 30 secondi)
# Validazione rapida per sviluppo
set -euo pipefail
# Colori per output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "=========================================="
echo "Lab 05 - Quick Test (< 30s)"
echo "=========================================="
echo ""
pass_count=0
fail_count=0
inc_pass() { ((pass_count++)) || true; }
inc_fail() { ((fail_count++)) || true; }
# Test rapidi
echo -n "[TEST] docker-compose.yml esiste... "
if [ -f "docker-compose.yml" ]; then
echo -e "${GREEN}OK${NC}"
inc_pass
else
echo -e "${RED}FAIL${NC}"
inc_fail
exit 1
fi
echo -n "[TEST] Servizio database definito... "
if grep -q "database:" docker-compose.yml; then
echo -e "${GREEN}OK${NC}"
inc_pass
else
echo -e "${RED}FAIL${NC}"
inc_fail
fi
echo -n "[TEST] PostgreSQL image configurata... "
if grep -q "image: postgres" docker-compose.yml; then
echo -e "${GREEN}OK${NC}"
inc_pass
else
echo -e "${RED}FAIL${NC}"
inc_fail
fi
echo -n "[TEST] Volume db-data configurato... "
if grep -q "db-data:" docker-compose.yml; then
echo -e "${GREEN}OK${NC}"
inc_pass
else
echo -e "${RED}FAIL${NC}"
inc_fail
fi
echo -n "[TEST] Database in rete privata... "
if grep -A 20 "database:" docker-compose.yml | grep -q "vpc-private"; then
echo -e "${GREEN}OK${NC}"
inc_pass
else
echo -e "${RED}FAIL${NC}"
inc_fail
fi
echo -n "[TEST] Limiti risorse configurati... "
if grep -A 30 "database:" docker-compose.yml | grep -q "cpus:" && \
grep -A 30 "database:" docker-compose.yml | grep -q "memory:"; then
echo -e "${GREEN}OK${NC}"
inc_pass
else
echo -e "${RED}FAIL${NC}"
inc_fail
fi
echo ""
echo "Container check (skip se non in esecuzione)..."
if docker ps --format '{{{{Names}}}}' | grep -q "^lab05-db$"; then
echo -n "[TEST] Container in esecuzione... "
echo -e "${GREEN}OK${NC}"
inc_pass
echo -n "[TEST] PostgreSQL pronto... "
if docker exec lab05-db pg_isready &>/dev/null; then
echo -e "${GREEN}OK${NC}"
inc_pass
else
echo -e "${YELLOW}WAIT${NC}"
inc_pass
fi
else
echo -e "${YELLOW}SKIP${NC} (container non in esecuzione)"
fi
echo ""
echo "=========================================="
echo "Risultato: $pass_count PASS, $fail_count FAIL"
echo "=========================================="
if [ $fail_count -gt 0 ]; then
exit 1
fi
exit 0