49 lines
1.9 KiB
Bash
49 lines
1.9 KiB
Bash
# test_rvoice.sh — unit tests for rvoice's pure helpers.
|
|
#
|
|
# Strategy: rvoice's CLI dispatch runs at the bottom of the file; we source
|
|
# it with $1 set to a no-op subcommand so the case statement falls through
|
|
# without firing start/stop/etc. Helpers defined above the case are then
|
|
# callable.
|
|
|
|
# Stub the case-statement input. The "noop" pattern matches nothing → no
|
|
# subcommand runs, but every function definition has been loaded.
|
|
(
|
|
set --
|
|
# rvoice expects to be invoked with `rvoice <sub>`; with no args it
|
|
# prints usage and exits 2. We trap that exit so sourcing succeeds.
|
|
set +e
|
|
RVOICE_LIB_ONLY=1 . "$ROOT/bin/rvoice" 2>/dev/null
|
|
) >/dev/null 2>&1 || true
|
|
|
|
# We need the helpers in the *current* shell to test them. Re-source with
|
|
# the guard expected by rvoice (added in the matching rvoice edit).
|
|
RVOICE_LIB_ONLY=1 . "$ROOT/bin/rvoice" 2>/dev/null || true
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# is_local_host
|
|
# ---------------------------------------------------------------------------
|
|
|
|
test_rvoice_is_local_keywords() {
|
|
assert_exit 0 is_local_host "local"
|
|
assert_exit 0 is_local_host "localhost"
|
|
assert_exit 0 is_local_host "127.0.0.1"
|
|
assert_exit 0 is_local_host "::1"
|
|
}
|
|
|
|
test_rvoice_is_local_remote() {
|
|
assert_exit 1 is_local_host "definitely-not-a-real-host-12345"
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# resolve_target — env override path
|
|
# ---------------------------------------------------------------------------
|
|
|
|
test_resolve_target_env_override() {
|
|
RVOICE_HOST=apricot.lan RVOICE_SESSION=claude-test-1 \
|
|
_out=$(resolve_target)
|
|
# tab-separated host\tsession
|
|
_host=$(printf %s "$_out" | cut -f1)
|
|
_sess=$(printf %s "$_out" | cut -f2)
|
|
assert_eq "apricot.lan" "$_host" || return 1
|
|
assert_eq "claude-test-1" "$_sess" || return 1
|
|
}
|