diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-14 08:41:16 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-14 08:41:16 -0500 |
| commit | eada697a11da5db8446108fed7573af809d222cc (patch) | |
| tree | 93eb06fcdf16496167d342502984411236b20df9 /tests | |
| parent | 659e90ad1b85eddee4b1d64afbcc0b1e4e8eef9f (diff) | |
| download | archangel-eada697a11da5db8446108fed7573af809d222cc.tar.gz archangel-eada697a11da5db8446108fed7573af809d222cc.zip | |
feat: add --name flag to zfssnapshot rollback and delete
I added --name NAME to rollback (single name) and --name NAME[,NAME...] to delete (comma-separated for multi-select) so scripted callers can drive the wrapper without fzf. The upcoming VM verification step in scripts/test-install.sh needs this. fzf is now conditional, required only when --name is omitted.
The 10 new bats tests cover help-text mentions, parse success and failure modes (missing value, mutex with -s, unknown flag), fzf-bypass on both subcommands, and multi-name expansion on delete.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/test_zfssnapshot.bats | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/tests/unit/test_zfssnapshot.bats b/tests/unit/test_zfssnapshot.bats index 74e13cc..dc06483 100644 --- a/tests/unit/test_zfssnapshot.bats +++ b/tests/unit/test_zfssnapshot.bats @@ -151,3 +151,136 @@ setup() { [[ "$output" == *"not-a-subcommand"* ]] [[ "$output" == *"Usage:"* ]] } + +############################# +# show_help — flag documentation +############################# + +@test "show_help documents --name for rollback" { + run show_help + [ "$status" -eq 0 ] + [[ "$output" == *"rollback"* ]] + [[ "$output" == *"--name NAME"* ]] +} + +@test "show_help documents --name for delete" { + run show_help + [ "$status" -eq 0 ] + [[ "$output" == *"delete"* ]] + [[ "$output" == *"--name NAME[,NAME...]"* ]] +} + +############################# +# cmd_rollback --name +############################# +# These tests mock require_*, fzf, and zfs to exercise the arg-parse + +# fzf-bypass path without needing a real ZFS system. The destructive +# tail (zfs rollback) is exercised in scripts/test-install.sh against a +# real VM. Confirmation always answered "no" so the test stops at the +# gate without reaching the rollback step. + +@test "cmd_rollback --name bypasses fzf and reaches the confirmation gate" { + require_root() { :; } + require_zfs() { :; } + require_fzf() { echo "FZF REQUIRED" >&2; return 1; } + fzf() { echo "FZF INVOKED" >&2; return 1; } + zfs() { + case "$1" in + list) printf 'zroot/ROOT/default@target\nzroot/home@target\n' ;; + *) echo "zfs $*" ;; + esac + } + + run cmd_rollback --name target <<< "no" + + [ "$status" -eq 0 ] + [[ "$output" != *"FZF REQUIRED"* ]] + [[ "$output" != *"FZF INVOKED"* ]] + [[ "$output" == *"@target"* ]] + [[ "$output" == *"cancelled"* ]] +} + +@test "cmd_rollback --name without a value errors out" { + require_root() { :; } + require_zfs() { :; } + run cmd_rollback --name + [ "$status" -ne 0 ] + [[ "$output" == *"requires an argument"* ]] +} + +@test "cmd_rollback --name combined with -s errors out" { + require_root() { :; } + require_zfs() { :; } + run cmd_rollback --name foo -s + [ "$status" -ne 0 ] + [[ "$output" == *"cannot be combined"* ]] +} + +@test "cmd_rollback rejects an unknown flag" { + require_root() { :; } + require_zfs() { :; } + run cmd_rollback --bogus + [ "$status" -ne 0 ] + [[ "$output" == *"Invalid option"* ]] +} + +############################# +# cmd_delete --name +############################# + +@test "cmd_delete --name bypasses fzf and reaches the confirmation gate" { + require_root() { :; } + require_zfs() { :; } + require_fzf() { echo "FZF REQUIRED" >&2; return 1; } + fzf() { echo "FZF INVOKED" >&2; return 1; } + zfs() { + case "$1" in + list) printf 'zroot/ROOT/default@target\nzroot/home@target\n' ;; + *) echo "zfs $*" ;; + esac + } + + run cmd_delete --name target <<< "no" + + [ "$status" -eq 0 ] + [[ "$output" != *"FZF REQUIRED"* ]] + [[ "$output" != *"FZF INVOKED"* ]] + [[ "$output" == *"@target"* ]] + [[ "$output" == *"cancelled"* ]] +} + +@test "cmd_delete --name expands comma-separated names to multiple targets" { + require_root() { :; } + require_zfs() { :; } + require_fzf() { :; } + zfs() { + case "$1" in + list) printf 'zroot/ROOT/default@a\nzroot/home@a\nzroot/ROOT/default@b\n' ;; + *) echo "zfs $*" ;; + esac + } + + run cmd_delete --name a,b <<< "no" + + [ "$status" -eq 0 ] + [[ "$output" == *"zroot/ROOT/default@a"* ]] + [[ "$output" == *"zroot/home@a"* ]] + [[ "$output" == *"zroot/ROOT/default@b"* ]] + [[ "$output" == *"3 snapshot(s) will be destroyed"* ]] +} + +@test "cmd_delete --name without a value errors out" { + require_root() { :; } + require_zfs() { :; } + run cmd_delete --name + [ "$status" -ne 0 ] + [[ "$output" == *"requires an argument"* ]] +} + +@test "cmd_delete rejects an unknown flag" { + require_root() { :; } + require_zfs() { :; } + run cmd_delete --bogus + [ "$status" -ne 0 ] + [[ "$output" == *"Invalid option"* ]] +} |
