#!/usr/bin/env bash # Verifies the clusev host CLI template renders and behaves. No docker needed — only the # help / version / unknown-command paths are exercised. Run from the repo root: # bash tests/scripts/test-clusev-cli.sh set -euo pipefail cd "$(dirname "$0")/../.." REPO="$(pwd)" TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT fail() { printf 'FAIL: %s\n' "$1" >&2; exit 1; } # Render the template the way install.sh does. sed "s|__CLUSEV_DIR__|${REPO}|g" docker/clusev/clusev > "${TMP}/clusev" chmod +x "${TMP}/clusev" CLI="${TMP}/clusev" # 1. Valid bash syntax. bash -n "$CLI" || fail "syntax error in rendered clusev" # 2. help lists the key subcommands. out="$("$CLI" help)" for needle in "clusev update" "clusev reset-admin" "clusev logs" "clusev ps" "clusev migrate"; do printf '%s' "$out" | grep -qF "$needle" || fail "help missing: $needle" done # 3. bare invocation and --help also show usage. "$CLI" | grep -qF "clusev reset-admin" || fail "bare invocation did not show usage" "$CLI" --help | grep -qF "clusev reset-admin" || fail "--help did not show usage" # 4. unknown command exits 64 and warns on stderr. set +e "$CLI" definitely-not-a-command >/dev/null 2>"${TMP}/err"; rc=$? set -e [ "$rc" -eq 64 ] || fail "unknown command exit = $rc (want 64)" grep -qF "Unbekannter Befehl" "${TMP}/err" || fail "unknown command did not warn" # 5. version reads config/clusev.php (no docker). want="$(grep -oE "'version' => '[^']+'" config/clusev.php | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1)" got="$("$CLI" version)" [ "$got" = "$want" ] || fail "version = '$got' (want '$want')" # 6. install.sh wires the CLI into PATH. grep -qF "/usr/local/bin/clusev" install.sh || fail "install.sh does not install /usr/local/bin/clusev" # 7. usage text must NOT leak the long compose filename. printf '%s' "$out" | grep -qF "docker-compose.prod.yml" && fail "usage leaks docker-compose.prod.yml" printf 'ok — clusev CLI checks passed\n'