#!/bin/bash # Particle-OS Complete Testing Suite # Tests all components from installation to full integration set -euo pipefail # Source configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CONFIG_FILE="/usr/local/etc/particle-config.sh" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Logging functions log_info() { echo -e "${BLUE}[INFO]${NC} $1" } log_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } log_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } # Test results tracking TESTS_PASSED=0 TESTS_FAILED=0 TESTS_SKIPPED=0 record_test() { local result=$1 local test_name=$2 case $result in "PASS") log_success "✓ $test_name" ((TESTS_PASSED++)) ;; "FAIL") log_error "✗ $test_name" ((TESTS_FAILED++)) ;; "SKIP") log_warning "⚠ $test_name (skipped)" ((TESTS_SKIPPED++)) ;; esac } # Check if running as root check_root() { if [[ $EUID -ne 0 ]]; then log_error "This script must be run as root (use sudo)" exit 1 fi } # Check if configuration exists check_config() { if [[ -f "$CONFIG_FILE" ]]; then log_success "Configuration file found: $CONFIG_FILE" source "$CONFIG_FILE" return 0 else log_warning "Configuration file not found: $CONFIG_FILE" return 1 fi } # Phase 1: Installation Testing test_installation() { log_info "=== Phase 1: Installation Testing ===" # Test 1: Check if tools are installed local tools=("apt-layer" "composefs-alternative" "bootc-alternative" "bootupd-alternative" "particle-orchestrator") for tool in "${tools[@]}"; do if command -v "$tool" >/dev/null 2>&1; then record_test "PASS" "Tool installed: $tool" else record_test "FAIL" "Tool not found: $tool" fi done # Test 2: Check if tools are executable for tool in "${tools[@]}"; do local tool_path=$(command -v "$tool" 2>/dev/null || echo "") if [[ -n "$tool_path" && -x "$tool_path" ]]; then record_test "PASS" "Tool executable: $tool" else record_test "FAIL" "Tool not executable: $tool" fi done # Test 3: Test basic commands for tool in "${tools[@]}"; do if command -v "$tool" >/dev/null 2>&1; then if timeout 10s "$tool" --help >/dev/null 2>&1; then record_test "PASS" "Help command works: $tool" else record_test "FAIL" "Help command failed: $tool" fi else record_test "SKIP" "Help command test: $tool" fi done # Test 4: Verify configuration if check_config; then record_test "PASS" "Configuration loaded successfully" else record_test "FAIL" "Configuration loading failed" fi } # Phase 2: Component Testing test_components() { log_info "=== Phase 2: Component Testing ===" # Test apt-layer if command -v apt-layer >/dev/null 2>&1; then log_info "Testing apt-layer..." # Test initialization if apt-layer --init >/dev/null 2>&1; then record_test "PASS" "apt-layer initialization" else record_test "FAIL" "apt-layer initialization" fi # Test status command if apt-layer status >/dev/null 2>&1; then record_test "PASS" "apt-layer status command" else record_test "FAIL" "apt-layer status command" fi else record_test "SKIP" "apt-layer component tests" fi # Test composefs-alternative if command -v composefs-alternative >/dev/null 2>&1; then log_info "Testing composefs-alternative..." # Test help command if composefs-alternative --help >/dev/null 2>&1; then record_test "PASS" "composefs-alternative help command" else record_test "FAIL" "composefs-alternative help command" fi else record_test "SKIP" "composefs-alternative component tests" fi # Test bootc-alternative if command -v bootc-alternative >/dev/null 2>&1; then log_info "Testing bootc-alternative..." # Test help command if bootc-alternative --help >/dev/null 2>&1; then record_test "PASS" "bootc-alternative help command" else record_test "FAIL" "bootc-alternative help command" fi else record_test "SKIP" "bootc-alternative component tests" fi # Test bootupd-alternative if command -v bootupd-alternative >/dev/null 2>&1; then log_info "Testing bootupd-alternative..." # Test help command if bootupd-alternative --help >/dev/null 2>&1; then record_test "PASS" "bootupd-alternative help command" else record_test "FAIL" "bootupd-alternative help command" fi else record_test "SKIP" "bootupd-alternative component tests" fi } # Phase 3: Integration Testing test_integration() { log_info "=== Phase 3: Integration Testing ===" # Test orchestrator if command -v particle-orchestrator >/dev/null 2>&1; then log_info "Testing particle-orchestrator..." # Test help command if particle-orchestrator help >/dev/null 2>&1; then record_test "PASS" "particle-orchestrator help command" else record_test "FAIL" "particle-orchestrator help command" fi # Test status command if particle-orchestrator status >/dev/null 2>&1; then record_test "PASS" "particle-orchestrator status command" else record_test "FAIL" "particle-orchestrator status command" fi else record_test "SKIP" "particle-orchestrator integration tests" fi # Test OCI integration if command -v oci-integration >/dev/null 2>&1; then log_info "Testing OCI integration..." # Test help command if oci-integration --help >/dev/null 2>&1; then record_test "PASS" "OCI integration help command" else record_test "FAIL" "OCI integration help command" fi else record_test "SKIP" "OCI integration tests" fi } # Phase 4: System Testing test_system() { log_info "=== Phase 4: System Testing ===" # Test directory structure local dirs=("/var/lib/particle-os" "/var/log/particle-os" "/var/cache/particle-os") for dir in "${dirs[@]}"; do if [[ -d "$dir" ]]; then record_test "PASS" "Directory exists: $dir" else record_test "FAIL" "Directory missing: $dir" fi done # Test log directory permissions if [[ -w "/var/log/particle-os" ]]; then record_test "PASS" "Log directory writable" else record_test "FAIL" "Log directory not writable" fi # Test workspace directory permissions if [[ -w "/var/lib/particle-os" ]]; then record_test "PASS" "Workspace directory writable" else record_test "FAIL" "Workspace directory not writable" fi } # Phase 5: Dependency Testing test_dependencies() { log_info "=== Phase 5: Dependency Testing ===" # Check system dependencies local deps=("squashfs-tools" "jq" "coreutils" "util-linux" "podman" "skopeo") for dep in "${deps[@]}"; do if command -v "$dep" >/dev/null 2>&1 || dpkg -l | grep -q "^ii.*$dep"; then record_test "PASS" "Dependency available: $dep" else record_test "FAIL" "Dependency missing: $dep" fi done # Check kernel modules if modprobe -n squashfs >/dev/null 2>&1; then record_test "PASS" "Kernel module available: squashfs" else record_test "FAIL" "Kernel module missing: squashfs" fi } # Main test runner main() { log_info "Starting Particle-OS Complete Testing Suite" log_info "Date: $(date)" log_info "System: $(uname -a)" # Check if running as root check_root # Run all test phases test_installation test_components test_integration test_system test_dependencies # Print summary log_info "=== Test Summary ===" log_info "Tests Passed: $TESTS_PASSED" log_info "Tests Failed: $TESTS_FAILED" log_info "Tests Skipped: $TESTS_SKIPPED" local total=$((TESTS_PASSED + TESTS_FAILED + TESTS_SKIPPED)) if [[ $total -gt 0 ]]; then local pass_rate=$((TESTS_PASSED * 100 / total)) log_info "Pass Rate: ${pass_rate}%" fi if [[ $TESTS_FAILED -eq 0 ]]; then log_success "All tests completed successfully!" exit 0 else log_error "Some tests failed. Please review the output above." exit 1 fi } # Run main function main "$@"