prole/tests/etc/test_init_kong_tmp_unbound.sh
chrisfu 909e92109e Refactor shell layout; add shellspec + authority
- Introduce lib/shell helpers and keep etc/* scripts thin via compatibility shims

- Move Kerberos validation to scripts/validation/check_kerberos.sh and update callers

- Add deterministic shellspec unit tests under tests/shellspec/ and wire Maven to run them

- Add minimal Spring Boot authority module with startup + /health endpoint and Maven wiring

- Document the new layout in docs/layout.md

Co-authored-by: Junie <junie@jetbrains.com>
2026-03-13 09:19:56 -07:00

108 lines
2.6 KiB
Bash

#!/usr/bin/env bash
# Regression test: etc/init_kong.sh should not leak a RETURN trap that later
# triggers `tmp: unbound variable` under `set -u`.
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PROLE_HOME=$(cd "$SCRIPT_DIR/../.." && pwd)
SOURCE_ETC_DIR="$PROLE_HOME/etc"
SOURCE_LIB_SHELL_DIR="$PROLE_HOME/lib/shell"
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
WORK_DIR="$TMP_DIR/work"
BIN_DIR="$TMP_DIR/bin"
mkdir -p "$WORK_DIR/etc" "$WORK_DIR/conf" "$WORK_DIR/lib/shell" "$BIN_DIR"
cp "$SOURCE_ETC_DIR/init_kong.sh" "$WORK_DIR/etc/init_kong.sh"
cp "$SOURCE_ETC_DIR/common_core_lib.sh" "$WORK_DIR/etc/common_core_lib.sh"
cp "$SOURCE_LIB_SHELL_DIR/common_core_lib.sh" "$WORK_DIR/lib/shell/common_core_lib.sh"
cp "$SOURCE_ETC_DIR/prole_cfg.sh" "$WORK_DIR/etc/prole_cfg.sh"
chmod +x "$WORK_DIR/etc/init_kong.sh"
cat <<EOF > "$WORK_DIR/conf/prole.cfg"
[globals]
prole.home = $WORK_DIR
prole.mode = k3s
NAMESPACE = prole-db-a0001
SERVICE_NAMESPACE = knoe-system
EOF
export KUBECTL_LOG="$TMP_DIR/kubectl.log"
cat <<'EOF' > "$BIN_DIR/kubectl"
#!/usr/bin/env bash
set -euo pipefail
args=("$@")
printf '%s\n' "${args[*]}" >> "${KUBECTL_LOG}"
# Skip global options like --request-timeout=...
while [[ "${1:-}" == --* ]]; do
shift
done
sub="${1:-}"
case "$sub" in
config)
case "${2:-}" in
current-context)
printf '%s' "default"
exit 0
;;
use-context|get-contexts)
exit 0
;;
esac
exit 0
;;
get|create|apply|rollout|wait|exec|delete|describe|logs|patch)
# Always succeed; this test focuses on avoiding trap/unbound-variable issues.
if [[ "$sub" == "create" && "${2:-}" == "configmap" ]]; then
# init_kong.sh expects YAML on stdout when using --dry-run=client -o yaml.
cat <<YAML
apiVersion: v1
kind: ConfigMap
metadata:
name: dummy
YAML
fi
exit 0
;;
*)
exit 0
;;
esac
EOF
chmod +x "$BIN_DIR/kubectl"
export PATH="$BIN_DIR:$PATH"
export PROLE_HOME="$WORK_DIR"
export PROLE_CONF="$WORK_DIR/conf"
export PROLE_MODE="k3s"
if "$WORK_DIR/etc/init_kong.sh" -n "knoe-system" update >"$TMP_DIR/stdout" 2>"$TMP_DIR/stderr"; then
:
else
echo "FAILURE: init_kong.sh update exited non-zero" >&2
cat "$TMP_DIR/stderr" >&2
exit 1
fi
if grep -q "unbound variable" "$TMP_DIR/stderr"; then
echo "FAILURE: stderr contains an unbound-variable error" >&2
cat "$TMP_DIR/stderr" >&2
exit 1
fi
if grep -q "tmp: unbound variable" "$TMP_DIR/stderr"; then
echo "FAILURE: stderr contains 'tmp: unbound variable'" >&2
cat "$TMP_DIR/stderr" >&2
exit 1
fi
echo "SUCCESS"