الملفات
ahmedgamalyousef efa5d907c9 Updating Files
2025-10-01 00:05:36 +03:00

40 أسطر
1.1 KiB
Bash
ملف تنفيذي

#!/usr/bin/bash
set -e
echo "🚀 Running API tests at $(date)"
echo "======================================"
BASE_URL="http://localhost:5000"
LOG_FILE="test_results.log"
check_status() {
local status=$1
if [[ "$status" == "200" || "$status" == "201" ]]; then
echo "✅ Status: $status"
else
echo "❌ Status: $status"
fi
}
# Health
status=$(curl -s -o /dev/null -w "%{http_code}" $BASE_URL/health)
echo "🔹 Testing /health"
check_status $status | tee -a $LOG_FILE
# GET fruits
status=$(curl -s -o /dev/null -w "%{http_code}" $BASE_URL/fruits)
echo "🔹 Testing GET /fruits"
check_status $status | tee -a $LOG_FILE
# GET fruit 1
status=$(curl -s -o /dev/null -w "%{http_code}" $BASE_URL/fruits/1)
echo "🔹 Testing GET /fruits/1"
check_status $status | tee -a $LOG_FILE
# POST fruit
status=$(curl -s -o /dev/null -w "%{http_code}" -X POST $BASE_URL/fruits \
-H "Content-Type: application/json" \
-d '{"name":"Mango","color":"Yellow","price":2.5,"quantity":50,"category":"Tropical"}')
echo "🔹 Testing POST /fruits"
check_status $status | tee -a $LOG_FILE