#!/bin/bash # Quick Test - Lab 03: Compute & EC2 # Fast validation for development (< 30 seconds) # Usage: bash labs/lab-03-compute/tests/quick-test.sh set -euo pipefail # Color definitions RED='\033[0;31m' GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' BOLD='\033[1m' NC='\033[0m' # Get script directory TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" LAB_DIR="$(cd "$TEST_DIR/.." && pwd)" # Quick checks (no verbose output) echo -e "${BLUE}Quick Test - Lab 03: Compute & EC2${NC}\n" # Check 1: File exists if [[ ! -f "$LAB_DIR/docker-compose.yml" ]]; then echo -e "${RED}✗ docker-compose.yml not found${NC}" exit 1 fi echo -e "${GREEN}✓${NC} docker-compose.yml exists" # Check 2: Syntax valid if ! docker compose config &> /dev/null; then echo -e "${RED}✗ docker-compose.yml syntax error${NC}" exit 1 fi echo -e "${GREEN}✓${NC} Syntax valid" # Check 3: Services defined SERVICES=$(docker compose config --services 2>/dev/null) SERVICE_COUNT=$(echo "$SERVICES" | wc -l) if [[ $SERVICE_COUNT -lt 3 ]]; then echo -e "${RED}✗ Only $SERVICE_COUNT services (need 3+)${NC}" exit 1 fi echo -e "${GREEN}✓${NC} $SERVICE_COUNT services defined" # Check 4: Resource limits (INF-03) NON_COMPLIANT=0 for service in $SERVICES; do has_cpu=$(docker compose config 2>/dev/null | grep -A 30 "^$service:" | grep -c "cpus:" || echo "0") has_mem=$(docker compose config 2>/dev/null | grep -A 30 "^$service:" | grep -c "memory:" || echo "0") if [[ $has_cpu -eq 0 || $has_mem -eq 0 ]]; then ((NON_COMPLIANT++)) || true fi done if [[ $NON_COMPLIANT -gt 0 ]]; then echo -e "${RED}✗ $NON_COMPLIANT services missing resource limits (INF-03)${NC}" exit 1 fi echo -e "${GREEN}✓${NC} INF-03 compliant (all services have limits)" # Check 5: Healthchecks MISSING_HC=0 for service in $SERVICES; do has_hc=$(docker compose config 2>/dev/null | grep -A 50 "^$service:" | grep -c "healthcheck:" || echo "0") if [[ $has_hc -eq 0 ]]; then ((MISSING_HC++)) || true fi done if [[ $MISSING_HC -gt 0 ]]; then echo -e "${YELLOW}⚠ $MISSING_HC services missing healthchecks${NC}" else echo -e "${GREEN}✓${NC} All services have healthchecks" fi # Summary echo -e "\n${GREEN}${BOLD}✓ Quick test PASSED${NC}\n" echo -e "For full verification, run:" echo -e " bash tests/run-all-tests.sh" echo -e " bash tests/99-final-verification.sh"