--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"
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()
echo "${#@}" > "$RSYNC_LOG"
printf "%s\n" "$@" >> "$RSYNC_LOG"
}
+ ask_restore() {
+ echo "$1"
+ return 0
+ }
}
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