184 lines
4.7 KiB
Bash
Executable File
184 lines
4.7 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Crumbforest Test Script
|
|
# Führt verschiedene Tests aus
|
|
#
|
|
|
|
set -e
|
|
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m'
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}✓${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}⚠${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}✗${NC} $1"
|
|
}
|
|
|
|
echo "============================================"
|
|
echo "🦉 Crumbforest Tests"
|
|
echo "============================================"
|
|
echo ""
|
|
|
|
# Check if system is running
|
|
if ! curl -s http://localhost:8000/health > /dev/null 2>&1; then
|
|
print_error "System läuft nicht!"
|
|
echo " Starte es mit: ./start.sh"
|
|
exit 1
|
|
fi
|
|
|
|
print_success "System läuft"
|
|
echo ""
|
|
|
|
# Test Selection
|
|
if [ -z "$1" ]; then
|
|
echo "Welche Tests sollen ausgeführt werden?"
|
|
echo ""
|
|
echo " 1) Quick Test - Basis-Tests (Health, API)"
|
|
echo " 2) Integration Test - Kompletter RAG Flow"
|
|
echo " 3) Alle Tests - Quick + Integration"
|
|
echo ""
|
|
read -p "Auswahl (1-3): " choice
|
|
else
|
|
choice=$1
|
|
fi
|
|
|
|
case $choice in
|
|
1|quick)
|
|
TEST_TYPE="quick"
|
|
;;
|
|
2|integration)
|
|
TEST_TYPE="integration"
|
|
;;
|
|
3|all)
|
|
TEST_TYPE="all"
|
|
;;
|
|
*)
|
|
print_error "Ungültige Auswahl"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Quick Tests
|
|
if [ "$TEST_TYPE" = "quick" ] || [ "$TEST_TYPE" = "all" ]; then
|
|
echo "=== Quick Tests ==="
|
|
echo ""
|
|
|
|
# Health Check
|
|
echo -n "Health Check... "
|
|
if curl -s http://localhost:8000/health | grep -q "ok"; then
|
|
print_success "OK"
|
|
else
|
|
print_error "FAILED"
|
|
fi
|
|
|
|
# Routes
|
|
echo -n "Routes Check... "
|
|
routes=$(curl -s http://localhost:8000/__routes | jq length 2>/dev/null || echo "0")
|
|
if [ "$routes" -gt 0 ]; then
|
|
print_success "OK ($routes routes)"
|
|
else
|
|
print_error "FAILED"
|
|
fi
|
|
|
|
# Database
|
|
echo -n "Database Check... "
|
|
if docker compose -f compose/docker-compose.yml exec -T db sh -c 'mariadb -u$MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE -e "SELECT COUNT(*) FROM users" 2>/dev/null' | grep -q "2"; then
|
|
print_success "OK"
|
|
else
|
|
print_warning "Users table check failed"
|
|
fi
|
|
|
|
# Qdrant
|
|
echo -n "Qdrant Check... "
|
|
if curl -s http://localhost:6333/collections > /dev/null 2>&1; then
|
|
print_success "OK"
|
|
else
|
|
print_error "FAILED"
|
|
fi
|
|
|
|
# Provider Status
|
|
echo -n "Provider Check... "
|
|
if curl -s http://localhost:8000/admin/rag/providers 2>/dev/null | grep -q "available"; then
|
|
print_success "OK"
|
|
else
|
|
print_warning "Keine Provider konfiguriert"
|
|
fi
|
|
|
|
echo ""
|
|
fi
|
|
|
|
# Integration Tests
|
|
if [ "$TEST_TYPE" = "integration" ] || [ "$TEST_TYPE" = "all" ]; then
|
|
echo "=== Integration Tests ==="
|
|
echo ""
|
|
|
|
# Check Python
|
|
if ! command -v python3 &> /dev/null; then
|
|
print_error "Python 3 nicht gefunden"
|
|
echo " Integration Tests benötigen Python 3"
|
|
exit 1
|
|
fi
|
|
|
|
# Check API Keys
|
|
if ! grep -v "^#" compose/.env | grep -q "API_KEY=sk"; then
|
|
print_warning "Keine API Keys in compose/.env gefunden"
|
|
echo ""
|
|
echo "Integration Tests benötigen mindestens einen API Key:"
|
|
echo " - OPENAI_API_KEY"
|
|
echo " - ANTHROPIC_API_KEY"
|
|
echo " - OPENROUTER_API_KEY"
|
|
echo ""
|
|
read -p "Trotzdem fortfahren? (y/n): " continue
|
|
if [ "$continue" != "y" ]; then
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Run Python integration test
|
|
echo "Führe Python Integration Test aus..."
|
|
echo ""
|
|
|
|
# Set API key from .env if available
|
|
if grep -q "OPENAI_API_KEY=sk" compose/.env; then
|
|
export OPENAI_API_KEY=$(grep "OPENAI_API_KEY=" compose/.env | cut -d'=' -f2)
|
|
export TEST_PROVIDER="openai"
|
|
elif grep -q "ANTHROPIC_API_KEY=sk" compose/.env; then
|
|
export ANTHROPIC_API_KEY=$(grep "ANTHROPIC_API_KEY=" compose/.env | cut -d'=' -f2)
|
|
export TEST_PROVIDER="claude"
|
|
elif grep -q "OPENROUTER_API_KEY=sk" compose/.env; then
|
|
export OPENROUTER_API_KEY=$(grep "OPENROUTER_API_KEY=" compose/.env | cut -d'=' -f2)
|
|
export TEST_PROVIDER="openrouter"
|
|
fi
|
|
|
|
if python3 tests/test_integration.py; then
|
|
echo ""
|
|
print_success "Integration Tests erfolgreich"
|
|
else
|
|
echo ""
|
|
print_error "Integration Tests fehlgeschlagen"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
fi
|
|
|
|
# Summary
|
|
echo "============================================"
|
|
print_success "Alle Tests erfolgreich!"
|
|
echo "============================================"
|
|
echo ""
|
|
echo "Weitere Tests:"
|
|
echo " curl http://localhost:8000/__routes - Alle Routes"
|
|
echo " curl http://localhost:8000/__whoami - Session Info"
|
|
echo " curl http://localhost:8000/admin/rag/providers - Provider Status"
|
|
echo ""
|