From f3009620f19c839891df9062c3d75319b860aeb6 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 16 Oct 2025 22:38:21 +0200 Subject: [PATCH] push testcase --- install/debian-install.sh | 31 ++-- misc/test-tools-func.sh | 302 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 313 insertions(+), 20 deletions(-) create mode 100644 misc/test-tools-func.sh diff --git a/install/debian-install.sh b/install/debian-install.sh index 57ce1658..4ee6dbab 100644 --- a/install/debian-install.sh +++ b/install/debian-install.sh @@ -4,7 +4,7 @@ # Author: Test Suite for tools.func # License: MIT # https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE -# Purpose: Comprehensive test of all setup_* functions from tools.func +# Purpose: Run comprehensive test suite for all setup_* functions from tools.func source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" color @@ -15,29 +15,20 @@ network_check update_os msg_info "Installing Base Dependencies" -$STD apt-get install -y curl wget gpg jq git build-essential +$STD apt-get install -y curl wget ca-certificates msg_ok "Installed Base Dependencies" -# Helper function to test and validate installation -test_and_validate() { - local test_name="$1" - local command_check="$2" - local version_cmd="$3" +msg_info "Downloading and executing tools.func test suite" +bash <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/test-tools-func.sh) +msg_ok "Test suite completed" - echo -e "\n${GN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${CL}" - echo -e "${GN}Testing: ${test_name}${CL}" - echo -e "${GN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${CL}\n" +motd_ssh +customize - if command -v "$command_check" &>/dev/null; then - local version_output - version_output=$($version_cmd 2>&1 | head -n1) - msg_ok "${test_name} installed: ${version_output}" - return 0 - else - msg_error "${test_name} validation FAILED - command not found: $command_check" - return 1 - fi -} +msg_info "Cleaning up" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned" # ============================================================================== # 1. YQ - YAML Processor diff --git a/misc/test-tools-func.sh b/misc/test-tools-func.sh new file mode 100644 index 00000000..b843f39e --- /dev/null +++ b/misc/test-tools-func.sh @@ -0,0 +1,302 @@ +#!/usr/bin/env bash + +# ============================================================================== +# TEST SUITE FOR tools.func +# ============================================================================== +# This script tests all setup_* functions from tools.func +# Can be run standalone in any Debian-based system +# +# Usage: +# bash <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/test-tools-func.sh) +# ============================================================================== + +set -euo pipefail + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +# Counters +TESTS_PASSED=0 +TESTS_FAILED=0 +TESTS_SKIPPED=0 + +# Log file +TEST_LOG="/tmp/tools-func-test-$(date +%Y%m%d-%H%M%S).log" + +echo -e "${CYAN}═══════════════════════════════════════════════════════════${NC}" +echo -e "${CYAN} TOOLS.FUNC TEST SUITE${NC}" +echo -e "${CYAN}═══════════════════════════════════════════════════════════${NC}" +echo -e "Log file: ${TEST_LOG}\n" + +# Source tools.func from repository +echo -e "${BLUE}► Sourcing tools.func from repository...${NC}" +if ! source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/tools.func); then + echo -e "${RED}✖ Failed to source tools.func${NC}" + exit 1 +fi +echo -e "${GREEN}✔ tools.func loaded${NC}\n" + +# Source core functions if available +if curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/core.func &>/dev/null; then + source <(curl -fsSL https://git.community-scripts.org/community-scripts/ProxmoxVED/raw/branch/main/misc/core.func) || true +fi + +# Define STD if not already defined +STD="${STD:-&>/dev/null}" + +# Helper functions +msg_info() { echo -e "${BLUE}ℹ ${1}${NC}"; } +msg_ok() { echo -e "${GREEN}✔ ${1}${NC}"; } +msg_error() { echo -e "${RED}✖ ${1}${NC}"; } +msg_warn() { echo -e "${YELLOW}⚠ ${1}${NC}"; } + +# Test validation function +test_function() { + local test_name="$1" + local test_command="$2" + local validation_cmd="${3:-}" + + echo -e "\n${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${CYAN}Testing: ${test_name}${NC}" + echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + + { + echo "=== Test: ${test_name} ===" + echo "Command: ${test_command}" + echo "Started: $(date)" + } >>"$TEST_LOG" + + if eval "$test_command" >>"$TEST_LOG" 2>&1; then + if [[ -n "$validation_cmd" ]]; then + if eval "$validation_cmd" >>"$TEST_LOG" 2>&1; then + local output + output=$(eval "$validation_cmd" 2>&1 | head -n1) + msg_ok "${test_name} - ${output}" + ((TESTS_PASSED++)) + else + msg_error "${test_name} - Installation succeeded but validation failed" + ((TESTS_FAILED++)) + fi + else + msg_ok "${test_name}" + ((TESTS_PASSED++)) + fi + else + msg_error "${test_name} - Installation failed" + ((TESTS_FAILED++)) + fi + + echo "Completed: $(date)" >>"$TEST_LOG" + echo "" >>"$TEST_LOG" +} + +# Skip test with reason +skip_test() { + local test_name="$1" + local reason="$2" + + echo -e "\n${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + echo -e "${CYAN}Testing: ${test_name}${NC}" + echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" + msg_warn "Skipped: ${reason}" + ((TESTS_SKIPPED++)) +} + +# Update system +msg_info "Updating system packages" +apt-get update &>/dev/null && msg_ok "System updated" + +# Install base dependencies +msg_info "Installing base dependencies" +apt-get install -y curl wget gpg jq git build-essential ca-certificates &>/dev/null && msg_ok "Base dependencies installed" + +# ============================================================================== +# TEST 1: YQ - YAML Processor +# ============================================================================== +test_function "YQ" \ + "setup_yq" \ + "yq --version" + +# ============================================================================== +# TEST 2: ADMINER - Database Management +# ============================================================================== +test_function "Adminer" \ + "setup_adminer" \ + "test -f /usr/share/adminer/latest.php && echo 'Adminer installed'" + +# ============================================================================== +# TEST 3: LOCAL IP HELPER +# ============================================================================== +test_function "Local IP Helper" \ + "setup_local_ip_helper" \ + "systemctl is-enabled local-ip-helper.service &>/dev/null && echo 'Service enabled'" + +# ============================================================================== +# TEST 4: CLICKHOUSE +# ============================================================================== +test_function "ClickHouse" \ + "setup_clickhouse" \ + "clickhouse-server --version" + +# ============================================================================== +# TEST 5: POSTGRESQL +# ============================================================================== +test_function "PostgreSQL 17" \ + "PG_VERSION=17 setup_postgresql" \ + "psql --version" + +# ============================================================================== +# TEST 6: MARIADB +# ============================================================================== +test_function "MariaDB 11.4" \ + "MARIADB_VERSION=11.4 setup_mariadb" \ + "mariadb --version" + +# ============================================================================== +# TEST 7: MYSQL (Remove MariaDB first) +# ============================================================================== +msg_info "Removing MariaDB before MySQL installation" +systemctl stop mariadb &>/dev/null || true +apt-get purge -y mariadb-server mariadb-client mariadb-common &>/dev/null || true +apt-get autoremove -y &>/dev/null +rm -rf /etc/mysql /var/lib/mysql +msg_ok "MariaDB removed" + +test_function "MySQL 8.0" \ + "MYSQL_VERSION=8.0 setup_mysql" \ + "mysql --version" + +# ============================================================================== +# TEST 8: MONGODB (Check AVX support) +# ============================================================================== +if grep -q avx /proc/cpuinfo; then + test_function "MongoDB 8.0" \ + "MONGO_VERSION=8.0 setup_mongodb" \ + "mongod --version" +else + skip_test "MongoDB 8.0" "CPU does not support AVX" +fi + +# ============================================================================== +# TEST 9: NODE.JS +# ============================================================================== +test_function "Node.js 22 with modules" \ + "NODE_VERSION=22 NODE_MODULE='yarn,pnpm@10.1.0,pm2' setup_nodejs" \ + "node --version && npm --version && yarn --version && pnpm --version && pm2 --version" + +# ============================================================================== +# TEST 10: PYTHON (UV) +# ============================================================================== +test_function "Python 3.12 via uv" \ + "PYTHON_VERSION=3.12 setup_uv" \ + "uv --version" + +# ============================================================================== +# TEST 11: PHP +# ============================================================================== +test_function "PHP 8.3 with FPM" \ + "PHP_VERSION=8.3 PHP_FPM=YES PHP_MODULE='redis,imagick,apcu,zip,mbstring' setup_php" \ + "php --version" + +# ============================================================================== +# TEST 12: COMPOSER +# ============================================================================== +test_function "Composer" \ + "setup_composer" \ + "composer --version" + +# ============================================================================== +# TEST 13: JAVA +# ============================================================================== +test_function "Java Temurin 21" \ + "JAVA_VERSION=21 setup_java" \ + "java --version" + +# ============================================================================== +# TEST 14: GO +# ============================================================================== +test_function "Go (latest)" \ + "GO_VERSION=latest setup_go" \ + "go version" + +# ============================================================================== +# TEST 15: RUBY +# ============================================================================== +test_function "Ruby 3.4.1 with Rails" \ + "RUBY_VERSION=3.4.1 RUBY_INSTALL_RAILS=true setup_ruby" \ + "ruby --version" + +# ============================================================================== +# TEST 16: RUST +# ============================================================================== +test_function "Rust (stable)" \ + "RUST_TOOLCHAIN=stable RUST_CRATES='cargo-edit' setup_rust" \ + "source \$HOME/.cargo/env && rustc --version" + +# ============================================================================== +# TEST 17: GHOSTSCRIPT +# ============================================================================== +test_function "Ghostscript" \ + "setup_gs" \ + "gs --version" + +# ============================================================================== +# TEST 18: IMAGEMAGICK +# ============================================================================== +test_function "ImageMagick" \ + "setup_imagemagick" \ + "magick --version" + +# ============================================================================== +# TEST 19: FFMPEG +# ============================================================================== +test_function "FFmpeg n7.1.1 (full)" \ + "FFMPEG_VERSION=n7.1.1 FFMPEG_TYPE=full setup_ffmpeg" \ + "ffmpeg -version" + +# ============================================================================== +# FINAL SUMMARY +# ============================================================================== +echo -e "\n${CYAN}═══════════════════════════════════════════════════════════${NC}" +echo -e "${CYAN} TEST SUMMARY${NC}" +echo -e "${CYAN}═══════════════════════════════════════════════════════════${NC}" +echo -e "${GREEN}✔ Passed: ${TESTS_PASSED}${NC}" +echo -e "${RED}✖ Failed: ${TESTS_FAILED}${NC}" +echo -e "${YELLOW}⚠ Skipped: ${TESTS_SKIPPED}${NC}" +echo -e "\nDetailed log: ${TEST_LOG}" + +# Generate summary report +{ + echo "" + echo "=== FINAL SUMMARY ===" + echo "Tests Passed: ${TESTS_PASSED}" + echo "Tests Failed: ${TESTS_FAILED}" + echo "Tests Skipped: ${TESTS_SKIPPED}" + echo "" + echo "=== Installed Versions ===" + command -v yq &>/dev/null && echo "yq: $(yq --version 2>&1)" + command -v clickhouse-server &>/dev/null && echo "ClickHouse: $(clickhouse-server --version 2>&1 | head -n1)" + command -v psql &>/dev/null && echo "PostgreSQL: $(psql --version)" + command -v mysql &>/dev/null && echo "MySQL: $(mysql --version)" + command -v mongod &>/dev/null && echo "MongoDB: $(mongod --version 2>&1 | head -n1)" + command -v node &>/dev/null && echo "Node.js: $(node --version)" + command -v php &>/dev/null && echo "PHP: $(php --version | head -n1)" + command -v java &>/dev/null && echo "Java: $(java --version 2>&1 | head -n1)" + command -v go &>/dev/null && echo "Go: $(go version)" + command -v ruby &>/dev/null && echo "Ruby: $(ruby --version)" + command -v rustc &>/dev/null && echo "Rust: $(rustc --version)" + command -v ffmpeg &>/dev/null && echo "FFmpeg: $(ffmpeg -version 2>&1 | head -n1)" +} >>"$TEST_LOG" + +if [ $TESTS_FAILED -eq 0 ]; then + echo -e "\n${GREEN}All tests completed successfully!${NC}" + exit 0 +else + echo -e "\n${RED}Some tests failed. Check the log for details.${NC}" + exit 1 +fi