exists_machines "$config" \
|| errlog "$CONFIG_FILE missing machines" \
|| return $?
+
+ local optname=
+ local date=
+ local number=
+ local machine=
+ local path=
+ while getopts "d:n:r:p:ho" optname; do
+ case "$optname" in
+ "d") date="$OPTARG" ;;
+ "n") number="$OPTARG" ;;
+ "r") machine="$OPTARG" ;;
+ "p") path="$OPTARG" ;;
+ "o") origin="deletemode-on" ;;
+ "h") useage && return 0 ;;
+ *) usage && return 0 ;;
+ esac
+ done
+
+ [ -n "$date" ] || errlog "missing date (-d)" || return $?
+ [ -n "$number" ] || errlog "missing number (-n)" || return $?
+ [[ "$number" =~ [[:digit:]]{2} ]] \
+ || errlog "number must two digits" \
+ || return $?
+ [ -n "$machine" ] || errlog "missing machine (-r)" || return $?
+ [ -n "$path" ] || errlog "missing path (-p)" || return $?
}
[ "$TESTMODE" == "ON" ] && return 0
unset RSYNC_LOG_RUNS
}
-# bats test_tags=restore:start
-@test "success start message" {
- run main
-
- assert_success
- assert_line --index 0 "⭐ START: restore"
-}
-
# bats test_tags=backup:start,backup:cmd
@test "failure yq command not found" {
command() {
assert_line --index 1 "ℹ️ INFO: backup path path"
assert_line --index 2 "ℹ️ INFO: backup name backup"
assert_line --index 3 "❌ ERROR: src/config-example.yaml missing machines"
+}
+
+# bats test_tags=backup:start,backup:param
+@test "failure date parameter missing" {
+ run main
+
+ 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 "❌ ERROR: missing date (-d)"
+}
+
+# bats test_tags=backup:start,backup:param
+@test "failure number parameter missing" {
+ run main -d "2000-01-01"
+
+ 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 "❌ ERROR: missing number (-n)"
+}
+
+# bats test_tags=backup:start,backup:param
+@test "failure number parameter must two digits" {
+ run main -d "2000-01-01" -n "1"
+
+ 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 "❌ ERROR: number must two digits"
+}
+
+# bats test_tags=backup:start,backup:param
+@test "failure machine parameter missing" {
+ run main -d "2000-01-01" -n "01"
+
+ 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 "❌ ERROR: missing machine (-r)"
+}
+
+# bats test_tags=backup:start,backup:param
+@test "failure path parameter missing" {
+ run main -d "2000-01-01" -n "01" -r "testpc1.example.com"
+
+ 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 "❌ ERROR: missing path (-p)"
}
\ No newline at end of file