#!/bin/bash # Configuration API_URL="http://127.0.0.1:3001/api/v1" # Colors for output GREEN='\033[0;32m' RED='\033[0;31m' NC='\033[0m' echo "Starting Backend API tests..." echo "----------------------------" test_endpoint() { local method=$1 local endpoint=$2 local expected_status=$3 local description=$4 echo -n "Test: $description... " # Execute curl and capture http status code local response=$(curl -s -o /dev/null -w "%{http_code}" -X "$method" "$API_URL$endpoint") if [ "$response" -eq "$expected_status" ]; then echo -e "${GREEN}PASS${NC} (Status: $response)" else echo -e "${RED}FAIL${NC} (Expected: $expected_status, Got: $response)" return 1 fi } # 1. Test GET /services test_endpoint "GET" "/services" 200 "GET services list" # 2. Test POST redis start test_endpoint "POST" "/services/redis/start" 200 "POST start redis" # 3. Test POST redis stop test_endpoint "POST" "/services/redis/stop" 200 "POST stop redis" # 4. Test POST redis restart test_endpoint "POST" "/services/redis/restart" 200 "POST restart redis" # 5. Test Whitelist Enforcement (Invalid Service) test_endpoint "POST" "/services/rm-rf-slash/start" 400 "Reject non-whitelisted service" # 6. Test 404 test_endpoint "GET" "/non-existent" 404 "Handle non-existent endpoint" echo "----------------------------" echo "Tests completed."