]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add error missing paramters
authorBastian Dehn <hhaalo@arcor.de>
Sat, 15 Aug 2026 10:58:47 +0000 (12:58 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 15 Aug 2026 10:58:57 +0000 (12:58 +0200)
src/restore
tests/restore_tests.bats

index 4f6629b3a2d5bc871828627fd37c544ab540d5a9..32656f1c0ddd7ad59bcdbae8188e6131f970765f 100755 (executable)
@@ -78,6 +78,31 @@ main()
        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
index fb8922afa4b37c5be5c8706846e050d045ce495a..95d15c0d21d90903bdac9f78ab730194dba7bc2d 100755 (executable)
@@ -29,14 +29,6 @@ teardown() {
        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() {
@@ -153,4 +145,59 @@ teardown() {
        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