test: add a local Docker test environment for all features
testenv/ starts two real NetBox 4.7 instances (v2 and v1 token), SSH targets on public, mgmt, and prod networks, a jump host, an IPv6-only host, a static host, and a client with ssh, sftp, scp, tmux, zellij, bash, zsh, and fish. A seed script fills NetBox through the REST API. 141 end-to-end checks cover cache and refresh filters, connecting, all resolver strategies, multiple instances, shortcuts and rewrites, SSH options and rules, static hosts, sftp/scp incl. IPv6 and jump hosts, tunnels, local notes and NetBox comments, completion and shell hooks, the TUI (driven through tmux), the configurator, and uninstall. Local only: testenv/up.sh, test.sh, shell.sh, down.sh. Not part of CI/CD. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
55e7a5106b
commit
dbb99bdded
34 files changed
+1215
No files matched your search
@@ -0,0 +1,78 @@
|
||||
# Helpers for the netssh test environment. Sourced by run.sh, the tests, and
|
||||
# shell.sh inside the client container.
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
. /state/env
|
||||
RESULTS=${RESULTS:-/tmp/netssh-results}
|
||||
|
||||
# new_home gives each test file its own netssh config, cache, notes, and rc files.
|
||||
new_home() {
|
||||
HOME=$(mktemp -d /tmp/home.XXXXXX)
|
||||
export HOME XDG_CONFIG_HOME="$HOME/.config" XDG_CACHE_HOME="$HOME/.cache" SHELL=/bin/bash
|
||||
mkdir -p "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME"
|
||||
unset TMUX ZELLIJ NETSSH_NETBOX_URL NETSSH_NETBOX_TOKEN
|
||||
cd "$HOME" || exit 1
|
||||
}
|
||||
|
||||
# base_config prints both NetBox instances followed by stdin.
|
||||
base_config() { cat /state/netssh.yaml -; }
|
||||
|
||||
# config writes the netssh config: both NetBox instances plus stdin.
|
||||
config() { base_config >"$XDG_CONFIG_HOME/netssh.yaml"; }
|
||||
|
||||
# config_only writes stdin as the whole config (no NetBox).
|
||||
config_only() { cat >"$XDG_CONFIG_HOME/netssh.yaml"; }
|
||||
|
||||
ok() {
|
||||
echo "ok $CURRENT: $1" >>"$RESULTS"
|
||||
printf ' \033[32mok\033[0m %s\n' "$1"
|
||||
}
|
||||
bad() {
|
||||
echo "FAIL $CURRENT: $1" >>"$RESULTS"
|
||||
printf ' \033[31mFAIL\033[0m %s\n' "$1"
|
||||
printf '%s\n' "$2" | sed 's/^/ /'
|
||||
}
|
||||
|
||||
# check NAME CMD... — CMD must succeed.
|
||||
check() {
|
||||
local name=$1 out
|
||||
shift
|
||||
if out=$("$@" 2>&1); then ok "$name"; else bad "$name" "exit $?: $out"; fi
|
||||
}
|
||||
|
||||
# expect_out NAME WANT CMD... — CMD must succeed and print WANT (substring).
|
||||
expect_out() {
|
||||
local name=$1 want=$2 out rc
|
||||
shift 2
|
||||
out=$("$@" 2>&1) && rc=0 || rc=$?
|
||||
if [ "$rc" = 0 ] && [[ $out == *"$want"* ]]; then ok "$name"; else bad "$name" "want: $want
|
||||
got (exit $rc): $out"; fi
|
||||
}
|
||||
|
||||
# expect_eq NAME WANT CMD... — CMD must succeed and print exactly WANT.
|
||||
expect_eq() {
|
||||
local name=$1 want=$2 out rc
|
||||
shift 2
|
||||
out=$("$@" 2>&1) && rc=0 || rc=$?
|
||||
if [ "$rc" = 0 ] && [ "$out" = "$want" ]; then ok "$name"; else bad "$name" "want: $want
|
||||
got (exit $rc): $out"; fi
|
||||
}
|
||||
|
||||
# expect_fail NAME WANT CMD... — CMD must fail and print WANT (substring).
|
||||
expect_fail() {
|
||||
local name=$1 want=$2 out rc
|
||||
shift 2
|
||||
out=$("$@" 2>&1) && rc=0 || rc=$?
|
||||
if [ "$rc" != 0 ] && [[ $out == *"$want"* ]]; then ok "$name"; else bad "$name" "want failure with: $want
|
||||
got (exit $rc): $out"; fi
|
||||
}
|
||||
|
||||
# wait_for TIMEOUT CMD... — retry CMD every 0.2 s until it succeeds.
|
||||
wait_for() {
|
||||
local deadline=$((SECONDS + $1))
|
||||
shift
|
||||
until "$@" >/dev/null 2>&1; do
|
||||
[ $SECONDS -ge $deadline ] && return 1
|
||||
sleep 0.2
|
||||
done
|
||||
}
|
||||
Reference in new issue
Block a user