49 lines
1.4 KiB
Bash
49 lines
1.4 KiB
Bash
#!/bin/bash
|
|
# backend/test-system.sh — Test system monitoring endpoints
|
|
|
|
# Configuration
|
|
API_URL="http://127.0.0.1:3001/api/v1/system"
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m'
|
|
|
|
echo "Starting System Monitoring API tests..."
|
|
echo "---------------------------------------"
|
|
|
|
test_endpoint() {
|
|
local endpoint=$1
|
|
local description=$2
|
|
|
|
echo -n "Test: $description... "
|
|
|
|
# Execute curl and capture response + status code
|
|
local response=$(curl -s -X GET "$API_URL$endpoint")
|
|
local status=$(curl -s -o /dev/null -w "%{http_code}" -X GET "$API_URL$endpoint")
|
|
|
|
if [ "$status" -eq 200 ]; then
|
|
echo -e "${GREEN}PASS${NC} (Status: $status)"
|
|
# Basic JSON validation (check if success: true is present)
|
|
if echo "$response" | grep -q '"success":true'; then
|
|
echo " Data: $response"
|
|
else
|
|
echo -e " ${RED}ERROR: Invalid JSON response${NC}"
|
|
return 1
|
|
fi
|
|
else
|
|
echo -e "${RED}FAIL${NC} (Status: $status)"
|
|
echo " Error: $response"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Run tests
|
|
test_endpoint "/cpu" "GET CPU Usage"
|
|
test_endpoint "/memory" "GET Memory Info"
|
|
test_endpoint "/disk" "GET Disk Usage"
|
|
test_endpoint "/uptime" "GET System Uptime"
|
|
test_endpoint "/load" "GET Load Averages"
|
|
|
|
echo "---------------------------------------"
|
|
echo "Tests completed."
|