160 lines
5.0 KiB
Bash
Executable File
160 lines
5.0 KiB
Bash
Executable File
#!/bin/bash
|
|
# Atlas API Test Script
|
|
# This script tests the API endpoints
|
|
|
|
BASE_URL="${ATLAS_URL:-http://localhost:8080}"
|
|
API_URL="${BASE_URL}/api/v1"
|
|
|
|
echo "=========================================="
|
|
echo "Atlas API Test Suite"
|
|
echo "=========================================="
|
|
echo "Base URL: $BASE_URL"
|
|
echo "API URL: $API_URL"
|
|
echo ""
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Test helper function
|
|
test_endpoint() {
|
|
local method=$1
|
|
local endpoint=$2
|
|
local data=$3
|
|
local description=$4
|
|
|
|
echo -e "${YELLOW}Testing: $description${NC}"
|
|
echo " $method $endpoint"
|
|
|
|
if [ -n "$data" ]; then
|
|
response=$(curl -s -w "\n%{http_code}" -X "$method" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$data" \
|
|
"$endpoint")
|
|
else
|
|
response=$(curl -s -w "\n%{http_code}" -X "$method" "$endpoint")
|
|
fi
|
|
|
|
http_code=$(echo "$response" | tail -n1)
|
|
body=$(echo "$response" | sed '$d')
|
|
|
|
if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
|
|
echo -e " ${GREEN}✓ Success (HTTP $http_code)${NC}"
|
|
echo "$body" | jq '.' 2>/dev/null || echo "$body"
|
|
elif [ "$http_code" -ge 400 ] && [ "$http_code" -lt 500 ]; then
|
|
echo -e " ${YELLOW}⚠ Client Error (HTTP $http_code)${NC}"
|
|
echo "$body" | jq '.' 2>/dev/null || echo "$body"
|
|
else
|
|
echo -e " ${RED}✗ Error (HTTP $http_code)${NC}"
|
|
echo "$body"
|
|
fi
|
|
echo ""
|
|
}
|
|
|
|
# Check if server is running
|
|
echo "Checking if server is running..."
|
|
if ! curl -s "$BASE_URL/healthz" > /dev/null; then
|
|
echo -e "${RED}Error: Server is not running at $BASE_URL${NC}"
|
|
echo "Start the server with: go run ./cmd/atlas-api/main.go"
|
|
exit 1
|
|
fi
|
|
echo -e "${GREEN}Server is running!${NC}"
|
|
echo ""
|
|
|
|
# Health & Metrics
|
|
echo "=========================================="
|
|
echo "1. Health & Metrics"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$BASE_URL/healthz" "" "Health check"
|
|
test_endpoint "GET" "$BASE_URL/metrics" "" "Prometheus metrics"
|
|
echo ""
|
|
|
|
# Disk Discovery
|
|
echo "=========================================="
|
|
echo "2. Disk Discovery"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/disks" "" "List available disks"
|
|
echo ""
|
|
|
|
# ZFS Pools
|
|
echo "=========================================="
|
|
echo "3. ZFS Pool Management"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/pools" "" "List ZFS pools"
|
|
test_endpoint "GET" "$API_URL/pools/testpool" "" "Get pool details (if exists)"
|
|
echo ""
|
|
|
|
# Datasets
|
|
echo "=========================================="
|
|
echo "4. Dataset Management"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/datasets" "" "List all datasets"
|
|
test_endpoint "GET" "$API_URL/datasets?pool=testpool" "" "List datasets in pool"
|
|
echo ""
|
|
|
|
# ZVOLs
|
|
echo "=========================================="
|
|
echo "5. ZVOL Management"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/zvols" "" "List all ZVOLs"
|
|
test_endpoint "GET" "$API_URL/zvols?pool=testpool" "" "List ZVOLs in pool"
|
|
echo ""
|
|
|
|
# Snapshots
|
|
echo "=========================================="
|
|
echo "6. Snapshot Management"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/snapshots" "" "List all snapshots"
|
|
test_endpoint "GET" "$API_URL/snapshots?dataset=testpool/test" "" "List snapshots for dataset"
|
|
echo ""
|
|
|
|
# Snapshot Policies
|
|
echo "=========================================="
|
|
echo "7. Snapshot Policies"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/snapshot-policies" "" "List snapshot policies"
|
|
|
|
# Create a test policy
|
|
test_endpoint "POST" "$API_URL/snapshot-policies" \
|
|
'{"dataset":"testpool/test","frequent":4,"hourly":24,"daily":7,"weekly":4,"monthly":12,"yearly":2,"autosnap":true,"autoprune":true}' \
|
|
"Create snapshot policy"
|
|
|
|
test_endpoint "GET" "$API_URL/snapshot-policies/testpool/test" "" "Get snapshot policy"
|
|
echo ""
|
|
|
|
# Storage Services
|
|
echo "=========================================="
|
|
echo "8. Storage Services"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/shares/smb" "" "List SMB shares"
|
|
test_endpoint "GET" "$API_URL/exports/nfs" "" "List NFS exports"
|
|
test_endpoint "GET" "$API_URL/iscsi/targets" "" "List iSCSI targets"
|
|
echo ""
|
|
|
|
# Jobs
|
|
echo "=========================================="
|
|
echo "9. Job Management"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/jobs" "" "List jobs"
|
|
echo ""
|
|
|
|
# Users & Auth
|
|
echo "=========================================="
|
|
echo "10. Authentication & Users"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/users" "" "List users"
|
|
echo ""
|
|
|
|
# Audit Logs
|
|
echo "=========================================="
|
|
echo "11. Audit Logs"
|
|
echo "=========================================="
|
|
test_endpoint "GET" "$API_URL/audit" "" "List audit logs"
|
|
echo ""
|
|
|
|
echo "=========================================="
|
|
echo "Test Suite Complete!"
|
|
echo "=========================================="
|