Add deployment testing scripts

- test-deployment.sh: Automated deployment testing script
- docker-compose.test.yml: Simplified compose file for testing
- Script tests dashboard accessibility and functionality
- Automated health checks and endpoint validation
This commit is contained in:
openhands 2025-10-30 07:43:28 +00:00
parent 6c8c83b7e5
commit 142e7cb075
2 changed files with 179 additions and 0 deletions

39
docker-compose.test.yml Normal file
View File

@ -0,0 +1,39 @@
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
environment:
- DB_HOST=localhost
- DB_PORT=5432
- DB_NAME=calejo
- DB_USER=calejo
- DB_PASSWORD=password
- OPCUA_ENABLED=true
- OPCUA_PORT=4840
- MODBUS_ENABLED=true
- MODBUS_PORT=502
- REST_API_ENABLED=true
- REST_API_PORT=8080
- HEALTH_MONITOR_PORT=9090
- LOG_LEVEL=INFO
volumes:
- ./static:/app/static
- ./logs:/app/logs
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
restart: unless-stopped
networks:
- calejo-network
networks:
calejo-network:
driver: bridge

140
test-deployment.sh Executable file
View File

@ -0,0 +1,140 @@
#!/bin/bash
# Calejo Control Adapter - Test Deployment Script
# This script tests the deployment of the dashboard and full application stack
echo "🚀 Starting Calejo Control Adapter Test Deployment"
echo "=================================================="
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
echo "❌ Docker is not running. Please start Docker and try again."
exit 1
fi
# Check if Docker Compose is available
if ! command -v docker-compose &> /dev/null; then
echo "❌ Docker Compose is not installed. Please install it first."
exit 1
fi
echo "✅ Docker and Docker Compose are available"
# Build the application
echo ""
echo "🔨 Building the application..."
docker-compose -f docker-compose.test.yml build app
if [ $? -ne 0 ]; then
echo "❌ Build failed"
exit 1
fi
echo "✅ Application built successfully"
# Start the services
echo ""
echo "🚀 Starting services..."
docker-compose -f docker-compose.test.yml up -d app
if [ $? -ne 0 ]; then
echo "❌ Failed to start services"
exit 1
fi
echo "✅ Services started successfully"
# Wait for the application to be ready
echo ""
echo "⏳ Waiting for application to be ready..."
for i in {1..30}; do
if curl -s http://localhost:8080/health > /dev/null 2>&1; then
echo "✅ Application is ready!"
break
fi
echo " Waiting... (attempt $i/30)"
sleep 2
if [ $i -eq 30 ]; then
echo "❌ Application failed to start within 60 seconds"
docker-compose -f docker-compose.test.yml logs app
exit 1
fi
done
# Test the dashboard
echo ""
echo "🧪 Testing dashboard access..."
DASHBOARD_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/dashboard)
if [ "$DASHBOARD_RESPONSE" = "200" ]; then
echo "✅ Dashboard is accessible (HTTP 200)"
else
echo "❌ Dashboard returned HTTP $DASHBOARD_RESPONSE"
fi
# Test the dashboard API
echo ""
echo "🧪 Testing dashboard API..."
API_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/api/v1/dashboard/status)
if [ "$API_RESPONSE" = "200" ]; then
echo "✅ Dashboard API is accessible (HTTP 200)"
else
echo "❌ Dashboard API returned HTTP $API_RESPONSE"
fi
# Test configuration endpoint
echo ""
echo "🧪 Testing configuration endpoint..."
CONFIG_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/api/v1/dashboard/config)
if [ "$CONFIG_RESPONSE" = "200" ]; then
echo "✅ Configuration endpoint is accessible (HTTP 200)"
else
echo "❌ Configuration endpoint returned HTTP $CONFIG_RESPONSE"
fi
# Display access information
echo ""
echo "🎉 Deployment Test Complete!"
echo "============================"
echo ""
echo "📊 Access URLs:"
echo " Dashboard: http://localhost:8080/dashboard"
echo " REST API: http://localhost:8080"
echo " Health Check: http://localhost:8080/health"
echo ""
echo "🔍 View logs:"
echo " docker-compose -f docker-compose.test.yml logs app"
echo ""
echo "🛑 Stop services:"
echo " docker-compose -f docker-compose.test.yml down"
echo ""
echo "📋 Full stack deployment:"
echo " docker-compose up -d"
echo ""
# Run a quick health check
echo "🏥 Running health check..."
HEALTH=$(curl -s http://localhost:8080/health | jq -r '.status' 2>/dev/null || echo "unknown")
echo " Application status: $HEALTH"
# Test dashboard functionality
echo ""
echo "🧪 Testing dashboard functionality..."
if curl -s http://localhost:8080/dashboard | grep -q "Calejo Control Adapter Dashboard"; then
echo "✅ Dashboard HTML is loading correctly"
else
echo "❌ Dashboard HTML may not be loading correctly"
fi
if curl -s http://localhost:8080/static/dashboard.js | grep -q "showTab"; then
echo "✅ Dashboard JavaScript is loading correctly"
else
echo "❌ Dashboard JavaScript may not be loading correctly"
fi
echo ""
echo "✅ Test deployment completed successfully!"
echo " The dashboard and application are running correctly."