#!/bin/bash # Test runner script for Uggla Drone Detection System # Automatically sets up environment and runs test scripts set -e # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}======================================${NC}" echo -e "${BLUE} Uggla Test Runner${NC}" echo -e "${BLUE}======================================${NC}" echo # Check if .env exists, if not suggest creating it if [ ! -f ".env" ]; then echo -e "${YELLOW}Warning: .env file not found.${NC}" echo "You can:" echo "1. Copy .env.test.example to .env and customize it" echo "2. Set environment variables manually" echo "3. Use default localhost settings" echo read -p "Continue with default localhost settings? (y/N): " CONTINUE if [[ ! $CONTINUE =~ ^[Yy]$ ]]; then echo "Please create .env file and try again." exit 1 fi # Set default environment variables export API_BASE_URL="http://localhost:3002/api" export VITE_BASE_PATH="" echo -e "${GREEN}Using default localhost configuration${NC}" else echo -e "${GREEN}Loading environment from .env file${NC}" # Load environment variables from .env file export $(grep -v '^#' .env | xargs) fi echo -e "${BLUE}Current configuration:${NC}" echo "API_BASE_URL: ${API_BASE_URL:-http://localhost:3002/api}" echo "VITE_BASE_PATH: ${VITE_BASE_PATH:-}" echo # Check which test to run if [ $# -eq 0 ]; then echo "Available tests:" echo "1. test_drone_data.py - Comprehensive drone simulation" echo "2. test_orlan_scenario.py - Military drone approach scenario" echo "3. test_orlan_detection.py - Long-range Orlan detection test" echo "4. test_drone_curl.sh - Simple curl-based API test" echo read -p "Select test (1-4): " TEST_CHOICE case $TEST_CHOICE in 1) TEST_SCRIPT="test_drone_data.py" ;; 2) TEST_SCRIPT="test_orlan_scenario.py" ;; 3) TEST_SCRIPT="test_orlan_detection.py" ;; 4) TEST_SCRIPT="test_drone_curl.sh" ;; *) echo "Invalid choice"; exit 1 ;; esac else TEST_SCRIPT=$1 fi echo -e "${YELLOW}Running test: $TEST_SCRIPT${NC}" echo # Check if script exists if [ ! -f "$TEST_SCRIPT" ]; then echo "Error: Test script $TEST_SCRIPT not found" exit 1 fi # Run the test script if [[ $TEST_SCRIPT == *.py ]]; then # Check if Python and required packages are available if ! command -v python3 &> /dev/null; then echo "Error: Python 3 is required to run Python test scripts" exit 1 fi # Check if requests module is available python3 -c "import requests" 2>/dev/null || { echo "Error: 'requests' module is required. Install with: pip install requests" exit 1 } python3 "$TEST_SCRIPT" elif [[ $TEST_SCRIPT == *.sh ]]; then # Make sure the script is executable chmod +x "$TEST_SCRIPT" ./"$TEST_SCRIPT" else echo "Error: Unknown script type for $TEST_SCRIPT" exit 1 fi echo echo -e "${GREEN}Test completed!${NC}"