#!/bin/bash # ══════════════════════════════════════════════════════════════════════════════ # Volt CLI End-to-End Tests # Comprehensive test suite for every command and subcommand # ══════════════════════════════════════════════════════════════════════════════ set -uo pipefail VOLT="${VOLT:-$(cd "$(dirname "$0")/.." && pwd)/volt}" PASS=0 FAIL=0 ERRORS="" TOTAL=0 # ── Test Helpers ────────────────────────────────────────────────────────────── # Test that command succeeds (exit 0) test_cmd() { local desc="$1" shift TOTAL=$((TOTAL + 1)) if output=$("$@" 2>&1); then PASS=$((PASS + 1)) echo " ✓ $desc" else FAIL=$((FAIL + 1)) ERRORS="$ERRORS\n ✗ $desc: $(echo "$output" | head -3)" echo " ✗ $desc" fi } # Test that command produces output containing expected string test_output() { local desc="$1" local expected="$2" shift 2 TOTAL=$((TOTAL + 1)) if output=$("$@" 2>&1) && echo "$output" | grep -qi "$expected"; then PASS=$((PASS + 1)) echo " ✓ $desc" else FAIL=$((FAIL + 1)) ERRORS="$ERRORS\n ✗ $desc (expected '$expected')" echo " ✗ $desc" fi } # Test that command fails (non-zero exit) test_fail() { local desc="$1" shift TOTAL=$((TOTAL + 1)) if "$@" >/dev/null 2>&1; then FAIL=$((FAIL + 1)) ERRORS="$ERRORS\n ✗ $desc (should have failed but succeeded)" echo " ✗ $desc (should fail)" else PASS=$((PASS + 1)) echo " ✓ $desc (correctly fails)" fi } # Test that command output is valid JSON test_json() { local desc="$1" shift TOTAL=$((TOTAL + 1)) if output=$("$@" 2>&1) && echo "$output" | python3 -m json.tool >/dev/null 2>&1; then PASS=$((PASS + 1)) echo " ✓ $desc" else FAIL=$((FAIL + 1)) ERRORS="$ERRORS\n ✗ $desc (invalid JSON)" echo " ✗ $desc (invalid JSON)" fi } # ══════════════════════════════════════════════════════════════════════════════ echo "⚡ Volt CLI End-to-End Tests" echo "════════════════════════════════════════════════════════════════" echo "" # ── 1. Help Tests (top-level) ──────────────────────────────────────────────── echo "📋 Help Tests — Top-Level Commands" test_output "volt --help" "Unified Linux" $VOLT --help for cmd in container vm desktop service task net volume image cas ps logs top events compose cluster daemon system config tune get describe delete ssh exec run status connect version; do test_cmd "volt $cmd --help" $VOLT $cmd --help done # ── 2. Help Tests (service subcommands) ────────────────────────────────────── echo "" echo "📋 Help Tests — Service Subcommands" for sub in list start stop restart reload enable disable status create edit show deps delete template mask unmask inspect logs; do test_cmd "volt service $sub --help" $VOLT service $sub --help done # ── 3. Help Tests (container subcommands) ──────────────────────────────────── echo "" echo "📋 Help Tests — Container Subcommands" for sub in create start stop restart kill exec attach list inspect logs cp delete shell; do test_cmd "volt container $sub --help" $VOLT container $sub --help done # ── 4. Help Tests (net subcommands) ────────────────────────────────────────── echo "" echo "📋 Help Tests — Net Subcommands" for sub in create list inspect delete connect disconnect status bridge firewall dns port policy; do test_cmd "volt net $sub --help" $VOLT net $sub --help done # ── 5. Help Tests (compose subcommands) ────────────────────────────────────── echo "" echo "📋 Help Tests — Compose Subcommands" for sub in up down start stop restart ps logs build pull exec config; do test_cmd "volt compose $sub --help" $VOLT compose $sub --help done # ── 6. Help Tests (tune subcommands) ───────────────────────────────────────── echo "" echo "📋 Help Tests — Tune Subcommands" for sub in profile cpu memory io net sysctl show; do test_cmd "volt tune $sub --help" $VOLT tune $sub --help done # ── 7. Help Tests (other subcommands) ──────────────────────────────────────── echo "" echo "📋 Help Tests — Other Subcommands" for sub in status info gc pull push verify dedup sync; do test_cmd "volt cas $sub --help" $VOLT cas $sub --help done for sub in create list run status enable disable logs edit delete; do test_cmd "volt task $sub --help" $VOLT task $sub --help done for sub in start stop restart status reload config; do test_cmd "volt daemon $sub --help" $VOLT daemon $sub --help done for sub in info health update backup restore reset; do test_cmd "volt system $sub --help" $VOLT system $sub --help done for sub in show get set edit validate reset; do test_cmd "volt config $sub --help" $VOLT config $sub --help done # ── 8. System Commands ────────────────────────────────────────────────────── echo "" echo "🔧 System Commands" test_output "volt system info" "Hostname:" $VOLT system info test_output "volt system info" "Kernel:" $VOLT system info test_output "volt system info" "CPU:" $VOLT system info test_output "volt system info" "Memory" $VOLT system info test_output "volt system info" "Disk" $VOLT system info test_output "volt system info" "Uptime:" $VOLT system info test_cmd "volt system health" $VOLT system health test_output "volt system health" "systemd" $VOLT system health test_output "volt status" "Hostname:" $VOLT status # ── 9. Service Commands ────────────────────────────────────────────────────── echo "" echo "📦 Service Commands" test_output "volt service list" "UNIT" $VOLT service list test_output "volt service list" ".service" $VOLT service list test_output "volt service status ssh" "ssh.service" $VOLT service status ssh test_output "volt service status ssh" "Active:" $VOLT service status ssh test_output "volt service status cron" "cron.service" $VOLT service status cron test_output "volt service show ssh" "ExecStart" $VOLT service show ssh test_cmd "volt service deps ssh" $VOLT service deps ssh test_cmd "volt service inspect ssh" $VOLT service inspect ssh # ── 10. Process Listing (ps) ──────────────────────────────────────────────── echo "" echo "📊 Process Listing (ps)" test_output "volt ps" "NAME" $VOLT ps --no-color test_output "volt ps" "TYPE" $VOLT ps --no-color test_output "volt ps" "STATUS" $VOLT ps --no-color test_output "volt ps" "service" $VOLT ps --no-color test_cmd "volt ps services" $VOLT ps services test_cmd "volt ps svc" $VOLT ps svc test_cmd "volt ps con" $VOLT ps con test_cmd "volt ps containers" $VOLT ps containers test_cmd "volt ps vms" $VOLT ps vms test_cmd "volt ps vm" $VOLT ps vm test_cmd "volt ps --all" $VOLT ps --all # ── 11. Logging ────────────────────────────────────────────────────────────── echo "" echo "📝 Logging" test_cmd "volt logs ssh --tail 5" $VOLT logs ssh --tail 5 test_cmd "volt logs cron --tail 5" $VOLT logs cron --tail 5 # ── 12. Shortcuts ──────────────────────────────────────────────────────────── echo "" echo "🔗 Shortcuts" test_cmd "volt get services" $VOLT get services test_cmd "volt get vms" $VOLT get vms test_cmd "volt get containers" $VOLT get containers test_cmd "volt describe service ssh" $VOLT describe service ssh # ── 13. Network Commands ──────────────────────────────────────────────────── echo "" echo "🌐 Network Commands" test_cmd "volt net status" $VOLT net status test_output "volt net status" "Bridges" $VOLT net status test_cmd "volt net bridge list" $VOLT net bridge list test_cmd "volt net list" $VOLT net list # ── 14. Tune Commands ──────────────────────────────────────────────────────── echo "" echo "🔧 Tune Commands" test_cmd "volt tune show" $VOLT tune show test_output "volt tune show" "Swappiness" $VOLT tune show test_cmd "volt tune sysctl list" $VOLT tune sysctl list test_output "volt tune sysctl get net.core.somaxconn" "somaxconn" $VOLT tune sysctl get net.core.somaxconn test_cmd "volt tune profile list" $VOLT tune profile list # ── 15. Task Commands ──────────────────────────────────────────────────────── echo "" echo "⏱️ Task Commands" test_cmd "volt task list" $VOLT task list test_output "volt task list" "NEXT" $VOLT task list # ── 16. Image Commands ─────────────────────────────────────────────────────── echo "" echo "🖼️ Image Commands" test_cmd "volt image list" $VOLT image list # ── 17. Config Commands ────────────────────────────────────────────────────── echo "" echo "⚙️ Config Commands" test_cmd "volt config show" $VOLT config show # ── 18. Daemon Commands ────────────────────────────────────────────────────── echo "" echo "🤖 Daemon Commands" test_cmd "volt daemon status" $VOLT daemon status # ── 19. Version ────────────────────────────────────────────────────────────── echo "" echo "📦 Version" test_output "volt --version" "0.2.0" $VOLT --version test_output "volt version" "volt version" $VOLT version test_output "volt version" "Build Date" $VOLT version # ── 20. Output Formats ────────────────────────────────────────────────────── echo "" echo "📄 Output Formats" test_json "volt ps -o json" $VOLT ps -o json test_json "volt ps services -o json" $VOLT ps services -o json test_cmd "volt ps -o yaml" $VOLT ps -o yaml test_output "volt ps -o yaml" "name:" $VOLT ps -o yaml # ── 21. Edge Cases — Missing Arguments ─────────────────────────────────────── echo "" echo "🔒 Edge Cases — Missing Arguments" test_fail "volt service start (no name)" $VOLT service start test_fail "volt ssh (no name)" $VOLT ssh test_fail "volt exec (no name)" $VOLT exec test_fail "volt delete (no args)" $VOLT delete test_fail "volt get (no args)" $VOLT get test_fail "volt describe (no args)" $VOLT describe # ── 22. Edge Cases — Unknown/Invalid ───────────────────────────────────────── echo "" echo "🔒 Edge Cases — Unknown/Invalid" test_fail "volt doesnotexist" $VOLT doesnotexist test_fail "volt ps unknown (invalid filter)" $VOLT ps unknown test_fail "volt get invalidresource" $VOLT get invalidresource # ── 23. Edge Cases — Help Variants ─────────────────────────────────────────── echo "" echo "🔒 Edge Cases — Help Variants" test_cmd "volt help" $VOLT help test_cmd "volt help help" $VOLT help help test_cmd "volt service help" $VOLT service help test_cmd "volt container help" $VOLT container help # ── 24. Shell Completion ───────────────────────────────────────────────────── echo "" echo "🐚 Shell Completion" test_output "volt completion bash" "bash completion" $VOLT completion bash test_output "volt completion zsh" "zsh completion" $VOLT completion zsh test_cmd "volt completion fish" $VOLT completion fish # ── 25. Alias Tests ────────────────────────────────────────────────────────── echo "" echo "🔀 Alias Tests" test_cmd "volt svc list --help" $VOLT svc list --help test_cmd "volt con list --help" $VOLT con list --help test_cmd "volt network list --help" $VOLT network list --help test_cmd "volt vol list --help" $VOLT vol list --help test_cmd "volt img list --help" $VOLT img list --help # ── 26. Global Flags ───────────────────────────────────────────────────────── echo "" echo "🏳️ Global Flags" test_cmd "volt ps --no-color" $VOLT ps --no-color test_cmd "volt ps --quiet" $VOLT ps --quiet test_cmd "volt system info --no-color" $VOLT system info --no-color # ── 27. Security Commands ───────────────────────────────────────────────────── echo "" echo "🔒 Security Commands" test_cmd "volt security --help" $VOLT security --help test_cmd "volt security profile --help" $VOLT security profile --help test_cmd "volt security profile list --help" $VOLT security profile list --help test_cmd "volt security profile show --help" $VOLT security profile show --help test_cmd "volt security audit --help" $VOLT security audit --help test_output "volt security profile list" "default" $VOLT security profile list test_output "volt security profile list" "strict" $VOLT security profile list test_output "volt security profile list" "webserver" $VOLT security profile list test_output "volt security profile list" "database" $VOLT security profile list test_output "volt security profile list" "minimal" $VOLT security profile list test_output "volt security profile show webserver" "Landlock" $VOLT security profile show webserver test_output "volt security profile show strict" "Seccomp" $VOLT security profile show strict test_output "volt security audit" "Kernel version" $VOLT security audit test_output "volt security audit" "Security Score" $VOLT security audit test_fail "volt security profile show nonexistent" $VOLT security profile show nonexistent # ── 28. System Harden/Mode Commands ────────────────────────────────────────── echo "" echo "🛡️ System Harden/Mode Commands" test_cmd "volt system harden --help" $VOLT system harden --help test_cmd "volt system mode --help" $VOLT system mode --help test_output "volt system harden --dry-run" "DRY RUN" $VOLT system harden --dry-run test_output "volt system harden --dry-run --profile development" "skipped" $VOLT system harden --dry-run --profile development test_output "volt system mode" "mode" $VOLT system mode test_cmd "volt system mode production" $VOLT system mode production test_output "volt system mode" "production" $VOLT system mode test_cmd "volt system mode development" $VOLT system mode development test_output "volt system mode" "development" $VOLT system mode test_cmd "volt system mode standalone" $VOLT system mode standalone test_fail "volt system mode invalid" $VOLT system mode invalid # ── 29. Registration & Licensing ───────────────────────────────────────────── echo "" echo "📜 Registration & Licensing" test_cmd "volt system register --help" $VOLT system register --help test_cmd "volt system license --help" $VOLT system license --help test_cmd "volt system deactivate --help" $VOLT system deactivate --help # Ensure clean state $VOLT system deactivate >/dev/null 2>&1 || true test_output "volt system license (unregistered)" "unregistered" $VOLT system license test_fail "volt system register (bad key)" $VOLT system register --license BAD-FORMAT test_fail "volt system register (no key)" $VOLT system register test_cmd "volt system register (valid key)" $VOLT system register --license VOLT-TEST-0000-0000 --org "Test Corp" test_output "volt system license (registered)" "registered" $VOLT system license test_output "volt system license (tier)" "Community" $VOLT system license test_output "volt system license (org)" "Test Corp" $VOLT system license test_output "volt system license (features)" "containers" $VOLT system license test_fail "volt system register (already registered)" $VOLT system register --license VOLT-AAAA-BBBB-CCCC test_cmd "volt system deactivate" $VOLT system deactivate test_output "volt system license (after deactivate)" "unregistered" $VOLT system license # Re-register to verify version shows tier test_cmd "volt system register (re-register)" $VOLT system register --license VOLT-REGS-TEST-0001 test_output "volt version (shows tier)" "Community" $VOLT version test_output "volt system info (shows tier)" "Community" $VOLT system info # Clean up $VOLT system deactivate >/dev/null 2>&1 || true # ══════════════════════════════════════════════════════════════════════════════ echo "" echo "════════════════════════════════════════════════════════════════" echo "Results: $PASS passed, $FAIL failed out of $TOTAL tests" if [ $FAIL -gt 0 ]; then echo "" echo "Failures:" echo -e "$ERRORS" exit 1 fi echo "" echo "All tests passed! ✅" exit 0