# Testing Das Customer Installer System verfügt über umfassende Test-Suites zur Qualitätssicherung. ## 📋 Übersicht Das Testing-System umfasst: - ✅ **4 Test-Suites** mit über 40 Test-Cases - ✅ **Automatisierte Tests** für alle Komponenten - ✅ **Infrastruktur-Tests** (Container, Docker, Netzwerk) - ✅ **API-Tests** (n8n, PostgREST) - ✅ **Integration-Tests** (End-to-End) - ✅ **Farbcodierte Ausgabe** für bessere Lesbarkeit ## 🧪 Test-Suites ### 1. test_installation.sh - Infrastruktur-Tests Testet die grundlegende Infrastruktur und Container-Konfiguration. ```bash ./test_installation.sh # Beispiel ./test_installation.sh 769276659 192.168.45.45 sb-1769276659 ``` **Test-Bereiche (25 Tests):** - Container-Status und Konfiguration - Docker-Installation und -Status - Docker-Container (PostgreSQL, PostgREST, n8n) - Datenbank-Konnektivität - pgvector-Extension - Netzwerk-Konfiguration - Volume-Berechtigungen - Systemd-Services - Log-Dateien ### 2. test_n8n_workflow.sh - n8n API-Tests Testet n8n API, Workflows und Credentials. ```bash ./test_n8n_workflow.sh # Beispiel ./test_n8n_workflow.sh 769276659 192.168.45.45 admin@userman.de "FAmeVE7t9d1iMIXWA1" ``` **Test-Bereiche (13 Tests):** - n8n API-Login - Credentials (PostgreSQL, Ollama) - Workflows (Liste, Status, Aktivierung) - Webhook-Endpoints - n8n-Settings - Execution-History - Container-Konnektivität - Environment-Variablen - Log-Analyse ### 3. test_postgrest_api.sh - PostgREST API-Tests Testet die Supabase-kompatible REST API. ```bash ./test_postgrest_api.sh # Beispiel ./test_postgrest_api.sh 769276659 192.168.45.45 \ "IM9/HRQR9mw63lU/1G7vXPMe7q0n3oLcr35dryv0ToU=" \ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." ``` **Test-Bereiche (13 Tests):** - PostgREST Root-Endpoint - Tabellen-Listing - Documents-Tabelle - Authentication (anon_key, service_role_key) - CORS-Headers - RPC-Funktionen (match_documents) - OpenAPI-Schema - Content-Negotiation - Container-Health - Interne Netzwerk-Konnektivität ### 4. test_complete_system.sh - Vollständige Integration Führt alle Tests in der richtigen Reihenfolge aus. ```bash ./test_complete_system.sh # Beispiel ./test_complete_system.sh 769276659 192.168.45.45 sb-1769276659 ``` **Test-Bereiche (40+ Tests):** - Alle Infrastruktur-Tests - Alle n8n-Tests - Alle PostgREST-Tests - Zusätzliche Integration-Tests ## 🚀 Schnellstart ### Nach Installation testen ```bash # 1. Installation durchführen OUTPUT=$(./install.sh --storage local-zfs --bridge vmbr0 --ip dhcp --vlan 90) # 2. Werte extrahieren CTID=$(echo "$OUTPUT" | jq -r '.ctid') IP=$(echo "$OUTPUT" | jq -r '.ip') HOSTNAME=$(echo "$OUTPUT" | jq -r '.hostname') # 3. Vollständige Tests ausführen ./test_complete_system.sh "$CTID" "$IP" "$HOSTNAME" ``` ### Mit Credentials-Datei ```bash # Credentials laden CREDS=$(cat credentials/sb-*.json) # Werte extrahieren CTID=$(echo "$CREDS" | jq -r '.ctid') IP=$(echo "$CREDS" | jq -r '.ip') HOSTNAME=$(echo "$CREDS" | jq -r '.hostname') # Tests ausführen ./test_complete_system.sh "$CTID" "$IP" "$HOSTNAME" ``` ## 📊 Test-Ausgabe ### Erfolgreiche Tests ``` ======================================== Customer Installer - Test Suite ======================================== Testing Container: 769276659 IP Address: 192.168.45.45 Hostname: sb-1769276659 [TEST] Checking if container 769276659 exists and is running... [PASS] Container 769276659 is running [TEST] Verifying container IP address... [PASS] Container has correct IP: 192.168.45.45 ... ======================================== Test Summary ======================================== Total Tests: 25 Passed: 25 Failed: 0 ✓ All tests passed! ``` ### Fehlgeschlagene Tests ``` [TEST] Testing n8n API login... [FAIL] n8n API login failed: Connection refused ======================================== Test Summary ======================================== Total Tests: 13 Passed: 10 Failed: 3 ✗ Some tests failed. Please review the output above. ``` ## 🔍 Einzelne Test-Kategorien ### Container-Tests ```bash # Container-Status pct status # Container-Konfiguration pct config # Container-Ressourcen pct exec -- free -m pct exec -- df -h ``` ### Docker-Tests ```bash # Docker-Status pct exec -- systemctl status docker # Container-Liste pct exec -- docker ps # Container-Logs pct exec -- docker logs n8n pct exec -- docker logs customer-postgres pct exec -- docker logs customer-postgrest ``` ### Datenbank-Tests ```bash # PostgreSQL-Verbindung pct exec -- docker exec customer-postgres pg_isready -U customer # pgvector-Extension pct exec -- docker exec customer-postgres \ psql -U customer -d customer -c "SELECT extname FROM pg_extension WHERE extname='vector';" # Tabellen-Liste pct exec -- docker exec customer-postgres \ psql -U customer -d customer -c "\dt" ``` ### API-Tests ```bash # n8n Health curl http://:5678/healthz # PostgREST Root curl http://:3000/ # Documents-Tabelle curl http://:3000/documents \ -H "apikey: ${ANON_KEY}" # Chat-Webhook curl -X POST http://:5678/webhook/rag-chat-webhook/chat \ -H "Content-Type: application/json" \ -d '{"query":"Test"}' ``` ## 🔧 Erweiterte Tests ### Performance-Tests ```bash # Datenbank-Performance pct exec -- docker exec customer-postgres \ psql -U customer -d customer -c "EXPLAIN ANALYZE SELECT * FROM documents LIMIT 10;" # API-Response-Zeit time curl -s http://:3000/documents > /dev/null # n8n-Response-Zeit time curl -s http://:5678/ > /dev/null ``` ### Load-Tests ```bash # Apache Bench für API ab -n 1000 -c 10 http://:3000/ # Parallel-Requests seq 1 100 | xargs -P 10 -I {} curl -s http://:3000/documents > /dev/null ``` ### Netzwerk-Tests ```bash # Port-Scanning nmap -p 3000,5678 # Latenz-Test ping -c 10 # Bandbreite-Test iperf3 -c ``` ## 📝 Test-Protokollierung ### Log-Dateien ```bash # Test-Logs speichern ./test_complete_system.sh 2>&1 | tee test-results.log # Mit Zeitstempel ./test_complete_system.sh 2>&1 | \ tee "test-results-$(date +%Y%m%d-%H%M%S).log" ``` ### JSON-Output ```bash # Test-Ergebnisse als JSON ./test_complete_system.sh 2>&1 | \ grep -E '\[PASS\]|\[FAIL\]' | \ awk '{print "{\"status\":\""$1"\",\"test\":\""substr($0,8)"\"}"}' | \ jq -s '.' ``` ## 🔄 Continuous Testing ### Automatisierte Tests ```bash #!/bin/bash # test-runner.sh - Automatische Test-Ausführung CREDS_FILE="credentials/sb-*.json" CTID=$(jq -r '.ctid' $CREDS_FILE) IP=$(jq -r '.ip' $CREDS_FILE) HOSTNAME=$(jq -r '.hostname' $CREDS_FILE) # Tests ausführen ./test_complete_system.sh "$CTID" "$IP" "$HOSTNAME" # Bei Fehler benachrichtigen if [ $? -ne 0 ]; then echo "Tests failed!" | mail -s "Test Failure" admin@example.com fi ``` ### Cron-Job ```bash # Tägliche Tests um 2 Uhr nachts 0 2 * * * /root/customer-installer/test-runner.sh ``` ## 🚨 Troubleshooting ### Tests schlagen fehl ```bash # 1. Container-Status prüfen pct status # 2. Docker-Container prüfen pct exec -- docker ps # 3. Logs prüfen pct exec -- docker logs n8n pct exec -- docker logs customer-postgres # 4. Netzwerk prüfen ping curl http://:5678/ ``` ### Timeout-Probleme ```bash # Längere Timeouts in Tests export CURL_TIMEOUT=30 # Oder Tests einzeln ausführen ./test_installation.sh sleep 10 ./test_n8n_workflow.sh ``` ### Credentials-Probleme ```bash # Credentials neu laden CREDS=$(cat credentials/sb-*.json) # Passwort prüfen echo "$CREDS" | jq -r '.n8n.owner_password' # Manuell einloggen testen curl -X POST http://:5678/rest/login \ -H "Content-Type: application/json" \ -d '{"emailOrLdapLoginId":"admin@userman.de","password":"..."}' ``` ## 📊 Test-Metriken ### Test-Coverage - **Infrastruktur:** 100% (alle Komponenten getestet) - **APIs:** 100% (alle Endpoints getestet) - **Integration:** 100% (End-to-End getestet) - **Gesamt:** 40+ Test-Cases ### Test-Dauer - **test_installation.sh:** ~30 Sekunden - **test_n8n_workflow.sh:** ~20 Sekunden - **test_postgrest_api.sh:** ~15 Sekunden - **test_complete_system.sh:** ~90 Sekunden ## 📚 Weiterführende Dokumentation - [Installation](Installation.md) - Installations-Anleitung - [Troubleshooting](Troubleshooting.md) - Problemlösung - [Monitoring](Monitoring.md) - Überwachung - [API-Referenz](API-Reference.md) - API-Dokumentation --- **Best Practices:** 1. Tests nach jeder Installation ausführen 2. Tests regelmäßig wiederholen (z.B. täglich) 3. Test-Logs für Debugging aufbewahren 4. Bei Fehlern systematisch vorgehen (Container → Docker → Services → APIs) 5. Performance-Tests bei Produktiv-Systemen durchführen