diff options
Diffstat (limited to 'tests/unit/test_test_install.bats')
| -rw-r--r-- | tests/unit/test_test_install.bats | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/unit/test_test_install.bats b/tests/unit/test_test_install.bats index 52ea037..3fb7c19 100644 --- a/tests/unit/test_test_install.bats +++ b/tests/unit/test_test_install.bats @@ -15,6 +15,48 @@ setup() { } ############################# +# save_attempt_log +############################# +# The retry loop refetches the guest's newest /tmp/archangel-*.log on +# every failed attempt, so a retried install used to keep only the last +# attempt's log — the failure that triggered the retry was gone by the +# time anyone read test-logs/. save_attempt_log keeps each one. + +# Normal: a failed attempt's log lands under its own attempt-numbered name. +@test "save_attempt_log writes the attempt's log under an attempt-numbered name" { + local dir="$BATS_TEST_TMPDIR/logs" + mkdir -p "$dir" + run save_attempt_log "$dir" zfs-encrypt 1 $'line one\nline two' + [ "$status" -eq 0 ] + [ -f "$dir/zfs-encrypt-install-attempt1.log" ] + [ "$(cat "$dir/zfs-encrypt-install-attempt1.log")" = $'line one\nline two' ] +} + +# Boundary: an empty capture still writes a file, so "attempt ran, log +# was empty" stays distinguishable from "attempt never happened". +@test "save_attempt_log writes an empty file for an empty capture" { + local dir="$BATS_TEST_TMPDIR/logs" + mkdir -p "$dir" + run save_attempt_log "$dir" mirror 2 "" + [ "$status" -eq 0 ] + [ -f "$dir/mirror-install-attempt2.log" ] + [ ! -s "$dir/mirror-install-attempt2.log" ] +} + +# Error: an unwritable log dir fails the save without aborting the caller. +@test "save_attempt_log returns non-zero when the log dir is unwritable" { + [ "$EUID" -ne 0 ] || skip "running as root" + local dir="$BATS_TEST_TMPDIR/logs" + mkdir -p "$dir" + chmod 000 "$dir" + run save_attempt_log "$dir" mirror 1 "content" + chmod 755 "$dir" + [ "$status" -eq 1 ] + [ -z "$output" ] + [ ! -f "$dir/mirror-install-attempt1.log" ] +} + +############################# # is_transient_install_failure ############################# |
