Files

53 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Checks the two shapes of help output: `dokku help` must get a single summary
# line (so the plugin doesn't spam the global command list), while
# `dokku google-auth:help` documents every subcommand the plugin ships.
set -eo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
fail() {
echo "FAIL: $*" 1>&2
exit 1
}
# --- `dokku help`: exactly one "name, description" line ---
top="$("$ROOT/commands" help)"
[[ "$(wc -l <<<"$top")" -eq 1 ]] ||
fail "plain 'dokku help' should emit one summary line, got $(wc -l <<<"$top")"
[[ "$top" =~ ^[[:space:]]+google-auth,\ .+ ]] ||
fail "summary line should read ' google-auth, <description>', got: $top"
echo "ok: dokku help shows one line"
# --- `dokku google-auth:help`: the full list ---
full="$("$ROOT/commands" google-auth:help)"
grep -q 'Usage: dokku google-auth\[:COMMAND\]' <<<"$full" || fail "help should print a usage line"
# Every subcommand file (except the no-argument default) must be documented.
for path in "$ROOT"/subcommands/*; do
sub="$(basename "$path")"
[[ "$sub" == "default" ]] && continue
grep -q "google-auth:$sub" <<<"$full" ||
fail "google-auth:$sub exists in subcommands/ but is undocumented in google-auth:help"
done
echo "ok: every subcommand is documented"
# Descriptions must not contain commas: the table is rendered with
# `column -s,` so a comma splits the line into a bogus third column.
while IFS= read -r line; do
[[ "$line" =~ ^[[:space:]]+google-auth: ]] || continue
[[ "$(tr -cd ',' <<<"$line" | wc -c)" -le 1 ]] ||
fail "help entry has more than one comma, which breaks the column layout: $line"
done < <(sed -n '/^help_content$/q;p' "$ROOT/commands")
echo "ok: help entries have no stray commas"
# --- unknown subcommands still fall through to dokku's dispatcher ---
set +e
"$ROOT/commands" google-auth:does-not-exist >/dev/null 2>&1
code=$?
set -e
[[ "$code" -eq 10 ]] || fail "unknown command should exit 10 (DOKKU_NOT_IMPLEMENTED_EXIT), got $code"
echo "ok: unknown subcommand exits 10"
echo "ALL HELP TESTS PASSED"