|
#!/bin/bash |
|
|
|
|
|
set -e |
|
|
|
echo "π€ Testing RobotHub TransportServer Transport Server Docker Setup" |
|
echo "==================================================" |
|
|
|
|
|
RED='\033[0;31m' |
|
GREEN='\033[0;32m' |
|
YELLOW='\033[1;33m' |
|
NC='\033[0m' |
|
|
|
|
|
CONTAINER_NAME="robothub-transport-server-test" |
|
PORT=7860 |
|
MAX_WAIT=60 |
|
|
|
|
|
cleanup() { |
|
echo -e "\n${YELLOW}Cleaning up...${NC}" |
|
docker stop $CONTAINER_NAME 2>/dev/null || true |
|
docker rm $CONTAINER_NAME 2>/dev/null || true |
|
} |
|
|
|
|
|
trap cleanup EXIT |
|
|
|
|
|
echo -e "\n${YELLOW}Step 1: Building Docker image...${NC}" |
|
docker build -t robothub-transport-server . || { |
|
echo -e "${RED}β Failed to build Docker image${NC}" |
|
exit 1 |
|
} |
|
echo -e "${GREEN}β
Docker image built successfully${NC}" |
|
|
|
|
|
echo -e "\n${YELLOW}Step 2: Starting container...${NC}" |
|
docker run -d \ |
|
--name $CONTAINER_NAME \ |
|
-p $PORT:7860 \ |
|
-e SERVE_FRONTEND=true \ |
|
robothub-transport-server || { |
|
echo -e "${RED}β Failed to start container${NC}" |
|
exit 1 |
|
} |
|
echo -e "${GREEN}β
Container started successfully${NC}" |
|
|
|
|
|
echo -e "\n${YELLOW}Step 3: Waiting for container to be ready...${NC}" |
|
COUNTER=0 |
|
while [ $COUNTER -lt $MAX_WAIT ]; do |
|
if curl -s http://localhost:$PORT/health > /dev/null 2>&1; then |
|
echo -e "${GREEN}β
Container is ready!${NC}" |
|
break |
|
fi |
|
echo "Waiting... ($COUNTER/$MAX_WAIT)" |
|
sleep 2 |
|
COUNTER=$((COUNTER + 2)) |
|
done |
|
|
|
if [ $COUNTER -ge $MAX_WAIT ]; then |
|
echo -e "${RED}β Container failed to start within $MAX_WAIT seconds${NC}" |
|
echo "Container logs:" |
|
docker logs $CONTAINER_NAME |
|
exit 1 |
|
fi |
|
|
|
|
|
echo -e "\n${YELLOW}Step 4: Testing endpoints...${NC}" |
|
|
|
|
|
echo "Testing /health endpoint..." |
|
HEALTH_RESPONSE=$(curl -s http://localhost:$PORT/health) |
|
if echo "$HEALTH_RESPONSE" | grep -q "healthy"; then |
|
echo -e "${GREEN}β
/health endpoint working${NC}" |
|
else |
|
echo -e "${RED}β /health endpoint failed${NC}" |
|
echo "Response: $HEALTH_RESPONSE" |
|
exit 1 |
|
fi |
|
|
|
|
|
echo "Testing /api/health endpoint..." |
|
API_HEALTH_RESPONSE=$(curl -s http://localhost:$PORT/api/health) |
|
if echo "$API_HEALTH_RESPONSE" | grep -q "healthy"; then |
|
echo -e "${GREEN}β
/api/health endpoint working${NC}" |
|
else |
|
echo -e "${RED}β /api/health endpoint failed${NC}" |
|
echo "Response: $API_HEALTH_RESPONSE" |
|
exit 1 |
|
fi |
|
|
|
|
|
echo "Testing frontend..." |
|
FRONTEND_RESPONSE=$(curl -s http://localhost:$PORT/) |
|
if echo "$FRONTEND_RESPONSE" | grep -q "<!doctype html>" && echo "$FRONTEND_RESPONSE" | grep -q "_app/immutable"; then |
|
echo -e "${GREEN}β
Frontend is served correctly${NC}" |
|
else |
|
echo -e "${RED}β Frontend test failed${NC}" |
|
echo "Response preview: $(echo "$FRONTEND_RESPONSE" | head -5)" |
|
exit 1 |
|
fi |
|
|
|
|
|
echo "Testing API documentation..." |
|
DOCS_RESPONSE=$(curl -s http://localhost:$PORT/api/docs) |
|
if echo "$DOCS_RESPONSE" | grep -q "swagger"; then |
|
echo -e "${GREEN}β
API documentation accessible${NC}" |
|
else |
|
echo -e "${RED}β API documentation test failed${NC}" |
|
exit 1 |
|
fi |
|
|
|
|
|
echo "Testing robotics API..." |
|
ROBOTICS_RESPONSE=$(curl -s http://localhost:$PORT/api/robotics/rooms) |
|
if [ $? -eq 0 ]; then |
|
echo -e "${GREEN}β
Robotics API accessible${NC}" |
|
else |
|
echo -e "${RED}β Robotics API test failed${NC}" |
|
exit 1 |
|
fi |
|
|
|
|
|
echo "Testing video API..." |
|
VIDEO_RESPONSE=$(curl -s http://localhost:$PORT/api/video/rooms) |
|
if [ $? -eq 0 ]; then |
|
echo -e "${GREEN}β
Video API accessible${NC}" |
|
else |
|
echo -e "${RED}β Video API test failed${NC}" |
|
exit 1 |
|
fi |
|
|
|
|
|
echo -e "\n${YELLOW}Step 5: Container information${NC}" |
|
echo "Container status:" |
|
docker ps | grep $CONTAINER_NAME |
|
|
|
echo -e "\nContainer resource usage:" |
|
docker stats --no-stream $CONTAINER_NAME |
|
|
|
|
|
echo -e "\n${GREEN}π All tests passed successfully!${NC}" |
|
echo "==================================================" |
|
echo "β
Docker image builds correctly" |
|
echo "β
Container starts and runs" |
|
echo "β
Health endpoints respond correctly" |
|
echo "β
Frontend is served" |
|
echo "β
API documentation is accessible" |
|
echo "β
Robotics API is working" |
|
echo "β
Video API is working" |
|
echo "" |
|
echo "π Access the application at: http://localhost:$PORT" |
|
echo "π API docs available at: http://localhost:$PORT/api/docs" |
|
echo "" |
|
echo "To manually test:" |
|
echo " docker run -p 7860:7860 -e SERVE_FRONTEND=true robothub-transport-server" |
|
echo "" |
|
echo -e "${YELLOW}Container will be cleaned up automatically.${NC}" |