Implement Lab 02 with Docker bridge networks simulating VPC/Subnets. Test Infrastructure (RED phase): - 6 bash test scripts for network creation, isolation, INF-02 compliance - Fail-fast orchestration with run-all-tests.sh - Quick validation script for development Documentation (Diátaxis framework): - 3 tutorials: VPC creation, container deployment, isolation verification - 4 how-to guides: create network, inspect config, test isolation, cleanup - 3 reference docs: Docker network commands, Compose syntax, VPC mapping - 1 explanation: Docker ↔ VPC parallels (PARA-01/02/03/04) Infrastructure (GREEN phase): - docker-compose.yml with VPC networks (10.0.1.0/24, 10.0.2.0/24) - 5 services: web, app, db, test-public, test-private - INF-02 compliant: 127.0.0.1 bindings only, no 0.0.0.0 - Private network with --internal flag - Multi-homed app container (public + private networks) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
147 lines
4.4 KiB
Bash
Executable File
147 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Test Orchestration: Run All Tests
|
|
# Executes all Lab 02 test scripts with fail-fast behavior
|
|
# Usage: bash labs/lab-02-network/tests/run-all-tests.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)"
|
|
|
|
# Change to test directory
|
|
cd "$TEST_DIR"
|
|
|
|
# Counter helpers
|
|
pass_count=0
|
|
fail_count=0
|
|
skip_count=0
|
|
|
|
inc_pass() { ((pass_count++)) || true; }
|
|
inc_fail() { ((fail_count++)) || true; }
|
|
inc_skip() { ((skip_count++)) || true; }
|
|
|
|
# Print header
|
|
print_header() {
|
|
echo ""
|
|
echo -e "${BLUE}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
|
echo -e "${BLUE}║${NC} ${BOLD}$1${NC}"
|
|
echo -e "${BLUE}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
|
echo ""
|
|
}
|
|
|
|
# Print test header
|
|
print_test_header() {
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
echo -e "${BLUE}Running:${NC} $1"
|
|
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
|
}
|
|
|
|
# Main header
|
|
print_header "Lab 02: Network & VPC - Test Suite"
|
|
|
|
# Test array - all test scripts in order
|
|
declare -a tests=(
|
|
"01-network-creation-test.sh"
|
|
"02-isolation-verification-test.sh"
|
|
"03-inf02-compliance-test.sh"
|
|
)
|
|
|
|
# Track first failure
|
|
first_failure=""
|
|
|
|
# Run each test
|
|
for test_script in "${tests[@]}"; do
|
|
test_path="$TEST_DIR/$test_script"
|
|
|
|
# Check if test file exists
|
|
if [[ ! -f "$test_path" ]]; then
|
|
echo -e "${YELLOW}[SKIP]${NC} $test_script not found"
|
|
inc_skip
|
|
continue
|
|
fi
|
|
|
|
# Check if test file is executable
|
|
if [[ ! -x "$test_path" ]]; then
|
|
echo -e "${YELLOW}[SKIP]${NC} $test_script not executable"
|
|
inc_skip
|
|
continue
|
|
fi
|
|
|
|
print_test_header "$test_script"
|
|
|
|
# Run test and capture exit code
|
|
if bash "$test_path"; then
|
|
echo -e "${GREEN}[✓]${NC} $test_script passed"
|
|
inc_pass
|
|
echo ""
|
|
else
|
|
exit_code=$?
|
|
echo -e "${RED}[✗]${NC} $test_script failed (exit code: $exit_code)"
|
|
inc_fail
|
|
|
|
# Record first failure for summary
|
|
if [[ -z "$first_failure" ]]; then
|
|
first_failure="$test_script"
|
|
fi
|
|
|
|
# Fail-fast: stop on first failure
|
|
echo ""
|
|
echo -e "${RED}[FATAL]${NC} Test failed. Stopping test suite (fail-fast mode)."
|
|
echo ""
|
|
break
|
|
fi
|
|
done
|
|
|
|
# Print summary
|
|
print_header "Test Suite Summary"
|
|
|
|
echo -e "Total tests run: ${BOLD}$((pass_count + fail_count + skip_count))${NC}"
|
|
echo -e " ${GREEN}Passed:${NC} $pass_count"
|
|
if [[ $fail_count -gt 0 ]]; then
|
|
echo -e " ${RED}Failed:${NC} $fail_count"
|
|
fi
|
|
if [[ $skip_count -gt 0 ]]; then
|
|
echo -e " ${YELLOW}Skipped:${NC} $skip_count"
|
|
fi
|
|
echo ""
|
|
|
|
# Final verdict
|
|
if [[ $fail_count -eq 0 && $skip_count -eq 0 ]]; then
|
|
echo -e "${GREEN}${BOLD}✓ ALL TESTS PASSED${NC}"
|
|
echo ""
|
|
echo -e "Next step: Run final verification"
|
|
echo -e " ${CYAN}bash labs/lab-02-network/tests/99-final-verification.sh${NC}"
|
|
echo ""
|
|
exit 0
|
|
elif [[ $fail_count -eq 0 ]]; then
|
|
echo -e "${YELLOW}Some tests were skipped${NC}"
|
|
echo ""
|
|
echo -e "Note: Skipped tests are expected during RED phase (before implementation)."
|
|
echo -e " These tests will pass after completing GREEN phase (implementation)."
|
|
echo ""
|
|
exit 0
|
|
else
|
|
echo -e "${RED}${BOLD}✗ TESTS FAILED${NC}"
|
|
echo ""
|
|
echo -e "First failure: ${RED}$first_failure${NC}"
|
|
echo ""
|
|
echo -e "To debug:"
|
|
echo -e " 1. Run the failed test directly to see detailed output:"
|
|
echo -e " ${CYAN}bash labs/lab-02-network/tests/$first_failure${NC}"
|
|
echo ""
|
|
echo -e " 2. Check infrastructure setup:"
|
|
echo -e " ${CYAN}cd labs/lab-02-network && docker compose config${NC}"
|
|
echo ""
|
|
echo -e " 3. Review test logs for specific failures"
|
|
echo ""
|
|
exit 1
|
|
fi
|