#!/usr/bin/env bash # # Tests for server/shared/components/stackctl, against a throwaway stack root and a stub # `docker` that records what it was asked to do instead of doing it. # # scripts/test-stackctl.sh # # Run by scripts/check.sh. Needs nothing but bash. set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT root="$work/stacks" bin="$work/bin" log="$work/calls" mkdir -p "$root" "$bin" cp "$repo_root/server/shared/components/stackctl" "$root/stackctl" for s in reverse-proxy openbao webapp grafana prometheus static-site wiki; do mkdir -p "$root/$s" touch "$root/$s/docker-compose.yml" done mkdir -p "$root/not-a-stack" cat > "$root/stack-groups" <<'EOF' # a comment order: reverse-proxy openbao confirm: openbao system: openbao webapp monitoring: grafana prometheus monitoring: ghost sites: static-site EOF # Records " " and fails for any stack named in $FAIL. cat > "$bin/docker" <<'EOF' #!/usr/bin/env bash stack="$(basename "$PWD")" echo "$stack $*" >> "$STACKCTL_TEST_LOG" case " ${FAIL:-} " in *" $stack "*) exit 1 ;; esac if [ "$2" = ps ]; then printf 'running\nexited\n'; fi EOF chmod +x "$bin/docker" export PATH="$bin:$PATH" STACKCTL_TEST_LOG="$log" failures=0 run() { : > "$log"; set +e; out="$("$root/stackctl" "$@" 2>&1