Files
2026-01-10 20:24:11 +01:00

230 lines
6.4 KiB
Bash
Executable File

#!/bin/bash
# test.sh - Script de test rapide pour l'extension Pilot Control
set -e
echo "================================================"
echo " Pilot Control Extension - Tests"
echo "================================================"
echo ""
# Couleurs pour l'affichage
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Fonction pour afficher un test réussi
pass() {
echo -e "${GREEN}${NC} $1"
}
# Fonction pour afficher un test échoué
fail() {
echo -e "${RED}${NC} $1"
}
# Fonction pour afficher un warning
warn() {
echo -e "${YELLOW}${NC} $1"
}
# Test 1: Vérifier que GNOME Shell est installé
echo "Test 1: GNOME Shell installation"
if command -v gnome-shell &> /dev/null; then
VERSION=$(gnome-shell --version)
pass "GNOME Shell is installed: $VERSION"
else
fail "GNOME Shell is not installed"
exit 1
fi
echo ""
# Test 2: Vérifier la version de GNOME Shell
echo "Test 2: GNOME Shell version"
GNOME_VERSION=$(gnome-shell --version | grep -oP '\d+' | head -1)
if [ "$GNOME_VERSION" -ge 45 ]; then
pass "GNOME Shell version is compatible: $GNOME_VERSION"
else
warn "GNOME Shell version may not be compatible: $GNOME_VERSION (requires 45+)"
fi
echo ""
# Test 3: Vérifier que l'extension est installée
echo "Test 3: Extension installation"
EXTENSION_UUID="pilot-control@gnome-shell-extensions"
EXTENSION_DIR="$HOME/.local/share/gnome-shell/extensions/$EXTENSION_UUID"
if [ -d "$EXTENSION_DIR" ]; then
pass "Extension directory exists: $EXTENSION_DIR"
else
fail "Extension is not installed"
echo " Run: ./install.sh"
exit 1
fi
echo ""
# Test 4: Vérifier les fichiers essentiels
echo "Test 4: Essential files"
ESSENTIAL_FILES=("metadata.json" "extension.js" "yamlConfig.js" "serviceManager.js")
for file in "${ESSENTIAL_FILES[@]}"; do
if [ -f "$EXTENSION_DIR/$file" ]; then
pass "$file exists"
else
fail "$file is missing"
fi
done
echo ""
# Test 5: Vérifier que l'extension est activée
echo "Test 5: Extension activation"
if gnome-extensions list --enabled 2>/dev/null | grep -q "$EXTENSION_UUID"; then
pass "Extension is enabled"
else
warn "Extension is not enabled"
echo " Run: gnome-extensions enable $EXTENSION_UUID"
fi
echo ""
# Test 6: Vérifier que le fichier config.yaml existe
echo "Test 6: Pilot V2 configuration"
CONFIG_PATHS=(
"$HOME/app/pilot/pilot-v2/config.yaml"
"$HOME/.config/pilot/config.yaml"
"/etc/pilot/config.yaml"
)
CONFIG_FOUND=false
for config_path in "${CONFIG_PATHS[@]}"; do
if [ -f "$config_path" ]; then
pass "Config file found: $config_path"
CONFIG_FOUND=true
CONFIG_PATH="$config_path"
break
fi
done
if [ "$CONFIG_FOUND" = false ]; then
warn "Config file not found in standard locations"
echo " Checked:"
for config_path in "${CONFIG_PATHS[@]}"; do
echo " - $config_path"
done
fi
echo ""
# Test 7: Vérifier que le service systemd existe
echo "Test 7: Systemd service"
SERVICE_NAME="mqtt_pilot.service"
if systemctl --user list-unit-files 2>/dev/null | grep -q "$SERVICE_NAME"; then
pass "Service exists: $SERVICE_NAME"
# Vérifier le statut
if systemctl --user is-active --quiet "$SERVICE_NAME"; then
pass "Service is running"
else
warn "Service is not running"
echo " Run: systemctl --user start $SERVICE_NAME"
fi
# Vérifier si enabled
if systemctl --user is-enabled --quiet "$SERVICE_NAME" 2>/dev/null; then
pass "Service is enabled (auto-start)"
else
warn "Service is not enabled"
echo " Run: systemctl --user enable $SERVICE_NAME"
fi
else
warn "Service not found: $SERVICE_NAME"
echo " Make sure Pilot V2 is installed and configured"
fi
echo ""
# Test 8: Vérifier les permissions du config.yaml
if [ "$CONFIG_FOUND" = true ]; then
echo "Test 8: Configuration file permissions"
if [ -r "$CONFIG_PATH" ]; then
pass "Config file is readable"
else
fail "Config file is not readable"
fi
if [ -w "$CONFIG_PATH" ]; then
pass "Config file is writable"
else
warn "Config file is not writable (extension won't be able to save changes)"
fi
echo ""
fi
# Test 9: Vérifier les backups existants
if [ "$CONFIG_FOUND" = true ]; then
echo "Test 9: Configuration backups"
BACKUP_DIR=$(dirname "$CONFIG_PATH")
BACKUP_COUNT=$(ls -1 "$BACKUP_DIR"/config.yaml.backup_* 2>/dev/null | wc -l)
if [ "$BACKUP_COUNT" -gt 0 ]; then
pass "Found $BACKUP_COUNT backup(s)"
echo " Latest: $(ls -1t "$BACKUP_DIR"/config.yaml.backup_* 2>/dev/null | head -1)"
else
warn "No backups found (will be created when you save)"
fi
echo ""
fi
# Test 10: Vérifier les logs GNOME Shell (optionnel)
echo "Test 10: GNOME Shell logs (checking for errors)"
if journalctl -b -o cat /usr/bin/gnome-shell 2>/dev/null | grep -i "pilot.*error" | tail -5 | grep -q "pilot"; then
warn "Found potential errors in GNOME Shell logs"
echo " Check logs with: journalctl -f -o cat /usr/bin/gnome-shell | grep -i pilot"
else
pass "No recent errors in GNOME Shell logs"
fi
echo ""
# Résumé
echo "================================================"
echo " Test Summary"
echo "================================================"
echo ""
# Compter les tests réussis
PASSED_COUNT=0
TOTAL_TESTS=10
# Note: Cette approche simplifiée compte manuellement
# Dans un vrai script de test, on utiliserait des variables
echo "Tests completed!"
echo ""
echo "Next steps:"
echo "1. If extension is not enabled, run:"
echo " gnome-extensions enable $EXTENSION_UUID"
echo ""
echo "2. Restart GNOME Shell:"
echo " - On X11: Alt+F2, type 'r', press Enter"
echo " - On Wayland: Log out and log back in"
echo ""
echo "3. Look for the Pilot Control icon in the top panel"
echo ""
echo "4. Check logs for any errors:"
echo " journalctl -f -o cat /usr/bin/gnome-shell | grep -i pilot"
echo ""
# Test interactif optionnel
read -p "Would you like to view the last 20 lines of GNOME Shell logs? (y/N) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo ""
echo "Last 20 lines of GNOME Shell logs (filtering for 'pilot'):"
echo "-----------------------------------------------------------"
journalctl -b -o cat /usr/bin/gnome-shell 2>/dev/null | grep -i pilot | tail -20 || echo "No logs found"
fi
echo ""
echo "================================================"