]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add question to restore
authorBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 08:08:30 +0000 (10:08 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 16 Aug 2026 08:08:30 +0000 (10:08 +0200)
src/restore
tests/restore_tests.bats

index 89049c46de61d204baeb4df687eed87e224db147..9fb35a5ec839d2b4710859f02d36c4590f4f6113 100755 (executable)
@@ -64,6 +64,16 @@ exists_machines()
                --raw-output '.machines | keys[]' > /dev/null 2>&1
 }
 
+ask_restore()
+{
+       local prompt="$1"
+       local answer=
+
+       read -rp  "$prompt" answer
+
+       [ "${answer,,}" == "y" ]
+}
+
 restore()
 {
        local config="$1"
@@ -115,6 +125,9 @@ restore()
        local hostpath="$remote_user@$host:$path"
        [ "$host" == "localhost" ] && hostpath="$path"
        echo "ℹ️ INFO: remote path $hostpath"
+
+       ask_restore "❓ QUESTION: Do you want restore? [N/y]" \
+               || return $?
 }
 
 main()
index 3a1fd65194e60a1bcbe9f69f1fc2bd6eb7f6d3cd..ffdba8e50d917be0025aa57a4903ce1ef96ee154 100755 (executable)
@@ -17,6 +17,10 @@ setup() {
                echo "${#@}" > "$RSYNC_LOG"
                printf "%s\n" "$@" >> "$RSYNC_LOG"
        }
+       ask_restore() {
+               echo "$1"
+               return 0
+       }
 }
 
 teardown() {
@@ -352,4 +356,44 @@ teardown() {
        assert_line --index 3 "ℹ️ INFO: restore mode file"
        assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/onlylocal/testpath"
        assert_line --index 5 "ℹ️ INFO: remote path /testpath"
+}
+
+# bats test_tags=restore:question
+@test "success question with answer default no" {
+       ask_restore() {
+               echo "$1"
+               return 1
+       }
+       mkdir --parents "build/test/2000-01-01_01_backup/onlylocal/testpath"
+
+       run main -d "2000-01-01" -n "01" -r "onlylocal" -p "/testpath"
+
+       assert_failure
+       assert_line --index 0 "⭐ START: restore"
+       assert_line --index 1 "ℹ️ INFO: backup path build/test"
+       assert_line --index 2 "ℹ️ INFO: backup name backup"
+       assert_line --index 3 "ℹ️ INFO: restore mode file"
+       assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/onlylocal/testpath"
+       assert_line --index 5 "ℹ️ INFO: remote path /testpath"
+       assert_line --index 6 "❓ QUESTION: Do you want restore? [N/y]"
+}
+
+# bats test_tags=restore:question
+@test "success question with answer default yes" {
+       ask_restore() {
+               echo "$1"
+               return 0
+       }
+       mkdir --parents "build/test/2000-01-01_01_backup/onlylocal/testpath"
+
+       run main -d "2000-01-01" -n "01" -r "onlylocal" -p "/testpath"
+
+       assert_success
+       assert_line --index 0 "⭐ START: restore"
+       assert_line --index 1 "ℹ️ INFO: backup path build/test"
+       assert_line --index 2 "ℹ️ INFO: backup name backup"
+       assert_line --index 3 "ℹ️ INFO: restore mode file"
+       assert_line --index 4 "ℹ️ INFO: restore path build/test/2000-01-01_01_backup/onlylocal/testpath"
+       assert_line --index 5 "ℹ️ INFO: remote path /testpath"
+       assert_line --index 6 "❓ QUESTION: Do you want restore? [N/y]"
 }
\ No newline at end of file