mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 13:16:47 +00:00
refactor: clean_local_snapshots now uses an array for snapshot processing and includes a read_key fallback, with new tests.
This commit is contained in:
@@ -108,6 +108,104 @@ EOF
|
||||
[[ "$output" == *"No incomplete backups found"* ]]
|
||||
}
|
||||
|
||||
@test "clean_local_snapshots skips in non-interactive mode" {
|
||||
run bash --noprofile --norc <<'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/system.sh"
|
||||
|
||||
tmutil() {
|
||||
if [[ "$1" == "listlocalsnapshots" ]]; then
|
||||
printf '%s\n' \
|
||||
"com.apple.TimeMachine.2023-10-25-120000" \
|
||||
"com.apple.TimeMachine.2023-10-24-120000"
|
||||
return 0
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
start_section_spinner(){ :; }
|
||||
stop_section_spinner(){ :; }
|
||||
|
||||
DRY_RUN="false"
|
||||
clean_local_snapshots
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"skipping non-interactive mode"* ]]
|
||||
[[ "$output" != *"Removed snapshot"* ]]
|
||||
}
|
||||
|
||||
@test "clean_local_snapshots keeps latest in dry-run" {
|
||||
run bash --noprofile --norc <<'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/system.sh"
|
||||
|
||||
tmutil() {
|
||||
if [[ "$1" == "listlocalsnapshots" ]]; then
|
||||
printf '%s\n' \
|
||||
"com.apple.TimeMachine.2023-10-25-120000" \
|
||||
"com.apple.TimeMachine.2023-10-25-130000" \
|
||||
"com.apple.TimeMachine.2023-10-24-120000"
|
||||
return 0
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
start_section_spinner(){ :; }
|
||||
stop_section_spinner(){ :; }
|
||||
note_activity(){ :; }
|
||||
|
||||
DRY_RUN="true"
|
||||
clean_local_snapshots
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Local snapshot: com.apple.TimeMachine.2023-10-25-120000"* ]]
|
||||
[[ "$output" == *"Local snapshot: com.apple.TimeMachine.2023-10-24-120000"* ]]
|
||||
[[ "$output" != *"Local snapshot: com.apple.TimeMachine.2023-10-25-130000"* ]]
|
||||
}
|
||||
|
||||
@test "clean_local_snapshots uses read fallback when read_key missing" {
|
||||
if ! command -v script > /dev/null 2>&1; then
|
||||
skip "script not available"
|
||||
fi
|
||||
|
||||
local tmp_script="$BATS_TEST_TMPDIR/clean_local_snapshots_fallback.sh"
|
||||
cat > "$tmp_script" <<'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/system.sh"
|
||||
|
||||
tmutil() {
|
||||
if [[ "$1" == "listlocalsnapshots" ]]; then
|
||||
printf '%s\n' \
|
||||
"com.apple.TimeMachine.2023-10-25-120000" \
|
||||
"com.apple.TimeMachine.2023-10-24-120000"
|
||||
return 0
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
start_section_spinner(){ :; }
|
||||
stop_section_spinner(){ :; }
|
||||
note_activity(){ :; }
|
||||
|
||||
unset -f read_key
|
||||
|
||||
CALL_LOG="$HOME/snapshot_calls.log"
|
||||
> "$CALL_LOG"
|
||||
sudo() { echo "sudo:$*" >> "$CALL_LOG"; return 0; }
|
||||
|
||||
DRY_RUN="false"
|
||||
clean_local_snapshots
|
||||
cat "$CALL_LOG"
|
||||
EOF
|
||||
|
||||
run bash --noprofile --norc -c "printf '\n' | script -q /dev/null bash \"$tmp_script\""
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Skipped"* ]]
|
||||
}
|
||||
|
||||
|
||||
@test "clean_homebrew skips when cleaned recently" {
|
||||
run bash --noprofile --norc <<'EOF'
|
||||
@@ -1088,5 +1186,3 @@ EOF
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Spotlight index already optimal"* ]]
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user