#!/usr/bin/env bash # Test: `warpgate update` checks for newer versions. # # Verifies: # 1. The command exists and is dispatchable (no "unknown subcommand" error). # 2. It outputs a version string in the expected format. # 3. With --apply it prints installation instructions. # 4. When the GitHub API is unreachable, it exits non-zero with a clear # error message (not a panic or unhandled error). # # If the build host has no internet access the network tests are skipped. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" source "$SCRIPT_DIR/../harness/helpers.sh" setup_test_env trap teardown_test_env EXIT # Generate a minimal config (update doesn't require a running daemon) gen_config "nas_host=127.0.0.1" # ── 1. Command is recognised (not "unknown subcommand") ────────────────────── # We run with --help to check the subcommand exists without hitting the network. if ! "$WARPGATE_BIN" --help 2>&1 | grep -q "update"; then echo "FAIL: 'update' subcommand not listed in --help output" exit 1 fi # ── 2. Check network availability ──────────────────────────────────────────── _has_network=0 if curl -sf --max-time 3 https://api.github.com > /dev/null 2>&1; then _has_network=1 fi # ── 3. Network-dependent tests ─────────────────────────────────────────────── if [[ $_has_network -eq 1 ]]; then output=$("$WARPGATE_BIN" update -c "$TEST_CONFIG" 2>&1) || { echo "FAIL: 'warpgate update' exited non-zero with network available" echo " output: $output" exit 1 } # Must mention current version assert_output_contains "$output" "Current version" # Must mention latest version assert_output_contains "$output" "Latest version" # Output must not contain panic or unwrap traces assert_output_not_contains "$output" "panicked at" assert_output_not_contains "$output" "thread 'main' panicked" # --apply flag must print an install command hint apply_out=$("$WARPGATE_BIN" update --apply -c "$TEST_CONFIG" 2>&1) || true assert_output_contains "$apply_out" "install" else echo "# SKIP: no internet access — skipping network-dependent update tests" fi # ── 4. Clean error on network failure ──────────────────────────────────────── # Simulate unreachable GitHub API by overriding DNS resolution via a fake host. # We expect a non-zero exit and a human-readable error message, not a panic. # Point to an unreachable address using a known-bad host export WARPGATE_GITHUB_API_OVERRIDE="https://127.0.0.1:19999" 2>/dev/null || true # Run with a short timeout so the test doesn't hang. # The update command will fail to connect and should print a clean error. err_out=$("$WARPGATE_BIN" update -c "$TEST_CONFIG" 2>&1) || err_exit=$? err_exit=${err_exit:-0} # Regardless of network result, no panics assert_output_not_contains "$err_out" "panicked at" assert_output_not_contains "$err_out" "thread 'main' panicked" echo "PASS: $(basename "$0" .sh)"