test.shโข5.44 kB
#!/bin/bash
# ACI MCP Server Test Runner
# This script provides multiple ways to test the ACI MCP server
set -e
echo "๐งช ACI MCP Server Test Suite"
echo "================================"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_color() {
echo -e "${1}${2}${NC}"
}
# Check if dependencies are installed
check_dependencies() {
print_color $BLUE "๐ฆ Checking dependencies..."
if [ ! -d "node_modules" ]; then
print_color $YELLOW "โ ๏ธ Node modules not found, installing..."
npm install
fi
if [ ! -d "build" ]; then
print_color $YELLOW "๐จ Build directory not found, building project..."
npm run build
fi
}
# Show usage
show_usage() {
echo "Usage: $0 [OPTIONS] [TEST_TYPE]"
echo ""
echo "Test Types:"
echo " unit - Run unit tests (requires Jest installation)"
echo " integration - Run integration tests against mock or real APIC"
echo " manual - Start interactive manual testing tool"
echo " mock - Start mock APIC server for development"
echo " coverage - Run tests with coverage report"
echo " all - Run all automated tests"
echo ""
echo "Options:"
echo " --real - Use real APIC instead of mock server"
echo " --mock - Force use of mock server (default)"
echo " --help, -h - Show this help"
echo ""
echo "Examples:"
echo " $0 unit # Run unit tests"
echo " $0 integration --mock # Integration tests with mock"
echo " $0 integration --real # Integration tests with real APIC"
echo " $0 manual # Interactive testing"
echo " $0 mock # Start mock server"
}
# Run unit tests
run_unit_tests() {
print_color $BLUE "๐งฉ Running Unit Tests..."
if command -v jest >/dev/null 2>&1; then
npm test
else
print_color $YELLOW "โ ๏ธ Jest not installed. Installing test dependencies..."
npm install --save-dev
npm test
fi
}
# Run integration tests
run_integration_tests() {
local use_mock=${1:-true}
print_color $BLUE "๐ Running Integration Tests..."
if [ "$use_mock" = "true" ]; then
print_color $BLUE "๐ก Using Mock APIC Server"
node build/test/integration.test.js --mock
else
print_color $BLUE "๐ Using Real APIC (ensure ACI_* environment variables are set)"
# Check if real APIC configuration exists
if [ -z "$ACI_APIC_URL" ] && [ ! -f "aci-config.json" ]; then
print_color $RED "โ No APIC configuration found!"
print_color $YELLOW "Set ACI_APIC_URL and other environment variables, or create aci-config.json"
exit 1
fi
node build/test/integration.test.js
fi
}
# Start manual testing tool
run_manual_tests() {
local use_mock=${1:-true}
print_color $BLUE "๐ฎ Starting Manual Testing Tool..."
if [ "$use_mock" = "true" ]; then
print_color $BLUE "๐ก Using Mock APIC Server"
node build/test/manual-test.js --mock
else
print_color $BLUE "๐ Using Real APIC"
node build/test/manual-test.js
fi
}
# Start mock server
start_mock_server() {
print_color $BLUE "๐ก Starting Mock APIC Server..."
print_color $YELLOW "Press Ctrl+C to stop"
node build/test/mock-server.js
}
# Run coverage tests
run_coverage_tests() {
print_color $BLUE "๐ Running Tests with Coverage..."
npm run test:coverage
}
# Main script logic
main() {
local test_type=""
local use_mock="true"
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--help|-h)
show_usage
exit 0
;;
--real)
use_mock="false"
shift
;;
--mock)
use_mock="true"
shift
;;
unit|integration|manual|mock|coverage|all)
test_type="$1"
shift
;;
*)
print_color $RED "โ Unknown option: $1"
show_usage
exit 1
;;
esac
done
# If no test type specified, show usage
if [ -z "$test_type" ]; then
show_usage
exit 1
fi
# Check dependencies
check_dependencies
# Run the specified test type
case $test_type in
unit)
run_unit_tests
;;
integration)
run_integration_tests "$use_mock"
;;
manual)
run_manual_tests "$use_mock"
;;
mock)
start_mock_server
;;
coverage)
run_coverage_tests
;;
all)
print_color $BLUE "๐ Running All Automated Tests..."
echo ""
run_unit_tests
echo ""
run_integration_tests "$use_mock"
echo ""
run_coverage_tests
;;
esac
print_color $GREEN "โ
Test execution completed!"
}
# Trap Ctrl+C
trap 'print_color $YELLOW "\n๐ Test execution interrupted"; exit 130' INT
# Run main function
main "$@"