Add bash completion for pkica
Static completion rules for all pkica commands, options and option values, plus unit, interactive (tmux) and --help reconciliation tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
81404a24cc
commit
11283c573a
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
# Интерактивные тесты pkica.bash-completion: реальный bash + readline в tmux,
|
||||
# нажатие TAB и проверка содержимого строки ввода.
|
||||
# Запуск (из WSL/Linux, нужен tmux): bash tests/test_interactive.sh
|
||||
|
||||
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
||||
command -v tmux >/dev/null || { echo "tmux not found"; exit 1; }
|
||||
|
||||
sess=pkica-compl-$$
|
||||
tmp=$(mktemp -d)
|
||||
trap 'tmux kill-session -t "$sess" 2>/dev/null; rm -rf "$tmp"' EXIT
|
||||
|
||||
mkdir "$tmp/outdir"
|
||||
touch "$tmp/request.req"
|
||||
cat >"$tmp/rc" <<EOF
|
||||
source /usr/share/bash-completion/bash_completion
|
||||
source "$root/pkica.bash-completion"
|
||||
bind 'set bell-style none'
|
||||
PS1='$ '
|
||||
cd "$tmp"
|
||||
EOF
|
||||
|
||||
tmux new-session -d -s "$sess" -x 200 -y 50 "bash --rcfile '$tmp/rc' -i"
|
||||
sleep 1
|
||||
|
||||
pass=0 fail=0
|
||||
|
||||
# check "ввод" "ожидаемая строка после TAB" (после TAB вводится маркер "#",
|
||||
# т.к. capture-pane обрезает концевые пробелы)
|
||||
check()
|
||||
{
|
||||
local input=$1 expected="$ $2#" got
|
||||
tmux send-keys -t "$sess" C-u "$input" Tab "#"
|
||||
sleep 0.5
|
||||
got=$(tmux capture-pane -p -t "$sess" | sed '/^$/d' | tail -1)
|
||||
if [[ $got == "$expected" ]]; then
|
||||
pass=$((pass + 1))
|
||||
printf 'PASS %s<TAB>\n' "$input"
|
||||
else
|
||||
fail=$((fail + 1))
|
||||
printf 'FAIL %s<TAB>\n expected: [%s]\n got: [%s]\n' "$input" "$expected" "$got"
|
||||
fi
|
||||
tmux send-keys -t "$sess" C-u
|
||||
tmux send-keys -t "$sess" C-l
|
||||
sleep 0.2
|
||||
}
|
||||
|
||||
check "pkica ce" "pkica cert-registry "
|
||||
check "pkica ca sig" "pkica ca signing-key "
|
||||
check "pkica ca signing-key cha" "pkica ca signing-key change-usage "
|
||||
check "pkica ca authority show --fo" "pkica ca authority show --format "
|
||||
check "pkica ca authority show --format Y" "pkica ca authority show --format Yaml "
|
||||
check "pkica ca authority show --format=J" "pkica ca authority show --format=Json "
|
||||
check "pkica ca new-root-cert -v Y" "pkica ca new-root-cert -v Years:"
|
||||
check "pkica ca template add -d Su" "pkica ca template add -d SubCa "
|
||||
check "pkica ca issue-cert -f " "pkica ca issue-cert -f "
|
||||
check "pkica ca issue-cert -f req" "pkica ca issue-cert -f request.req "
|
||||
check "pkica ca crl get -o " "pkica ca crl get -o outdir/"
|
||||
check "./pkica ra fo" "./pkica ra folder "
|
||||
|
||||
# Пустое слово: при TAB TAB в списке должны быть и файлы, и каталоги.
|
||||
tmux send-keys -t "$sess" C-u "pkica ca issue-cert -f " Tab Tab
|
||||
sleep 0.5
|
||||
screen=$(tmux capture-pane -p -t "$sess")
|
||||
if [[ $screen == *request.req* && $screen == *outdir/* ]]; then
|
||||
pass=$((pass + 1))
|
||||
echo "PASS pkica ca issue-cert -f <TAB><TAB> lists files"
|
||||
else
|
||||
fail=$((fail + 1))
|
||||
printf 'FAIL pkica ca issue-cert -f <TAB><TAB> lists files\n%s\n' "$screen"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "passed: $pass, failed: $fail"
|
||||
((fail == 0))
|
||||
Reference in New Issue
Block a user