#!/bin/bash #========================================================================== # PyGuardian Test Script # Демонстрация возможностей системы установки # Author: SmartSolTech Team #========================================================================== set -e # Colors RED='\033[0;31m' GREEN='\033[0;32m' BLUE='\033[0;34m' YELLOW='\033[1;33m' NC='\033[0m' print_header() { echo -e "${BLUE}" echo "=================================================" echo " PyGuardian Installation Test Suite" echo "=================================================" echo -e "${NC}" } print_test() { echo -e "${YELLOW}[TEST] $1${NC}" } print_success() { echo -e "${GREEN}[PASS] $1${NC}" } print_info() { echo -e "${BLUE}[INFO] $1${NC}" } print_error() { echo -e "${RED}[FAIL] $1${NC}" } # Test 1: Check if all installation scripts exist test_scripts_exist() { print_test "Проверка существования скриптов установки" local scripts=( "install.sh" "scripts/install.sh" "scripts/docker-install.sh" "Makefile" ) for script in "${scripts[@]}"; do if [[ -f "$script" ]]; then print_success "Найден: $script" else print_error "Отсутствует: $script" return 1 fi done print_success "Все скрипты установки найдены" } # Test 2: Check if scripts are executable test_scripts_executable() { print_test "Проверка прав выполнения скриптов" local scripts=( "install.sh" "scripts/install.sh" "scripts/docker-install.sh" ) for script in "${scripts[@]}"; do if [[ -x "$script" ]]; then print_success "Исполняемый: $script" else print_error "Не исполняемый: $script" chmod +x "$script" 2>/dev/null && print_info "Исправлено: $script" fi done print_success "Все скрипты исполняемы" } # Test 3: Check Python requirements test_python_requirements() { print_test "Проверка Python требований" if command -v python3 &> /dev/null; then PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') print_success "Python version: $PYTHON_VERSION" if python3 -c 'import sys; exit(0 if sys.version_info >= (3, 10) else 1)'; then print_success "Python версия соответствует требованиям (>=3.10)" else print_error "Python версия не соответствует требованиям (требуется >=3.10)" return 1 fi else print_error "Python3 не найден" return 1 fi if command -v pip3 &> /dev/null; then print_success "pip3 доступен" else print_error "pip3 не найден" return 1 fi } # Test 4: Check dependencies in requirements.txt test_requirements_file() { print_test "Проверка файла requirements.txt" if [[ -f "requirements.txt" ]]; then print_success "Файл requirements.txt найден" local required_packages=( "telegram" "aiosqlite" "pyyaml" "cryptography" "psutil" ) for package in "${required_packages[@]}"; do if grep -q "$package" requirements.txt; then print_success "Зависимость найдена: $package" else print_error "Зависимость отсутствует: $package" fi done else print_error "Файл requirements.txt не найден" return 1 fi } # Test 5: Check configuration files test_config_files() { print_test "Проверка конфигурационных файлов" if [[ -f "config/config.yaml" ]]; then print_success "Основной конфиг найден: config/config.yaml" # Check for required sections local sections=("telegram" "security" "firewall" "storage") for section in "${sections[@]}"; do if grep -q "^${section}:" config/config.yaml; then print_success "Секция конфигурации: $section" else print_error "Отсутствует секция: $section" fi done else print_error "Основной конфиг не найден: config/config.yaml" return 1 fi # Check for cluster configuration if grep -q "cluster:" config/config.yaml; then print_success "Кластерная конфигурация найдена" else print_info "Кластерная конфигурация отсутствует (будет добавлена при установке)" fi } # Test 6: Check source code structure test_source_structure() { print_test "Проверка структуры исходного кода" local source_files=( "src/storage.py" "src/firewall.py" "src/monitor.py" "src/bot.py" "src/security.py" "src/sessions.py" "src/password_utils.py" "src/cluster.py" "main.py" ) for file in "${source_files[@]}"; do if [[ -f "$file" ]]; then print_success "Исходный файл: $file" else print_error "Отсутствует файл: $file" return 1 fi done print_success "Структура исходного кода корректна" } # Test 7: Check Makefile targets test_makefile_targets() { print_test "Проверка целей Makefile" if [[ -f "Makefile" ]]; then local targets=("install" "standalone" "controller" "agent" "help" "clean") for target in "${targets[@]}"; do if grep -q "^${target}:" Makefile; then print_success "Makefile цель: $target" else print_error "Отсутствует цель: $target" fi done else print_error "Makefile не найден" return 1 fi } # Test 8: Validate script syntax test_script_syntax() { print_test "Проверка синтаксиса скриптов" local scripts=( "install.sh" "scripts/install.sh" "scripts/docker-install.sh" ) for script in "${scripts[@]}"; do if bash -n "$script" 2>/dev/null; then print_success "Синтаксис корректен: $script" else print_error "Синтаксическая ошибка в: $script" return 1 fi done } # Test 9: Check documentation test_documentation() { print_test "Проверка документации" local docs=( "README.md" "docs/INSTALLATION.md" "docs/CLUSTER_SETUP.md" ) for doc in "${docs[@]}"; do if [[ -f "$doc" ]]; then print_success "Документация: $doc" else print_error "Отсутствует документация: $doc" fi done } # Test 10: Simulate installation steps (dry run) test_installation_simulation() { print_test "Симуляция процесса установки" # Test help output if ./install.sh --help >/dev/null 2>&1; then print_success "Справка install.sh работает" else print_error "Ошибка в справке install.sh" fi # Test make help if make help >/dev/null 2>&1; then print_success "Справка Makefile работает" else print_error "Ошибка в справке Makefile" fi print_success "Симуляция установки завершена" } # Run all tests run_all_tests() { print_header local tests=( "test_scripts_exist" "test_scripts_executable" "test_python_requirements" "test_requirements_file" "test_config_files" "test_source_structure" "test_makefile_targets" "test_script_syntax" "test_documentation" "test_installation_simulation" ) local passed=0 local total=${#tests[@]} for test in "${tests[@]}"; do echo "" if $test; then ((passed++)) fi done echo "" echo "=================================================" if [[ $passed -eq $total ]]; then print_success "Все тесты пройдены: $passed/$total ✅" echo "" print_info "Система готова к установке!" print_info "Используйте: sudo ./install.sh" print_info "Или: sudo make install" else print_error "Тесты не пройдены: $passed/$total ❌" echo "" print_info "Исправьте ошибки перед установкой" fi echo "=================================================" } # Main function main() { case "${1:-all}" in "all") run_all_tests ;; "scripts") test_scripts_exist && test_scripts_executable && test_script_syntax ;; "python") test_python_requirements && test_requirements_file ;; "config") test_config_files ;; "structure") test_source_structure ;; "docs") test_documentation ;; *) echo "Usage: $0 [all|scripts|python|config|structure|docs]" echo "" echo "Tests available:" echo " all - Run all tests (default)" echo " scripts - Test installation scripts" echo " python - Test Python requirements" echo " config - Test configuration files" echo " structure - Test source code structure" echo " docs - Test documentation" ;; esac } main "$@"