]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add error message for no pathes
authorBastian Dehn <hhaalo@arcor.de>
Wed, 5 Aug 2026 18:31:20 +0000 (20:31 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Wed, 5 Aug 2026 18:31:20 +0000 (20:31 +0200)
src/backup
tests/backup_tests.bats

index 7ab21bcf62c38004565310a77e62cae159e293f8..6a501ff6444046163e4b9b465e3cec532a9de7ba 100755 (executable)
@@ -148,7 +148,11 @@ machine_backup_pathes()
        local full_backup_path="$3"
        local pathes=()
        mapfile -t pathes < <(echo "$config" \
-               | jq --raw-output ".machines.$machine.pathes[]")
+               | jq --raw-output ".machines.$machine.pathes[]" \
+               2> /dev/null)
+       [ "${#pathes[@]}" -ne "0" ] \
+               || errlog "missing pathes for machine $machine" \
+               || return $?
        [ -n "$NOCOLOR" ] && YELLOW= && LIGHTPURPLE= && RESET=
 
        local path=
index 4eebba49433b7667215e84bd5ff70dfdaada7fcd..2f3ecd94d2dacde96e615d09e952c6217bca725e 100755 (executable)
@@ -184,7 +184,7 @@ teardown() {
        assert_line --index 5 "✅ SUCCESS: backup"
 }
 
-@test "last backup dir path info" {
+@test "success last backup dir path info" {
        create_backup_dir() {
                :
        }
@@ -206,7 +206,7 @@ teardown() {
        assert_line --index 6 "✅ SUCCESS: backup"
 }
 
-@test "new backup folder info" {
+@test "success new backup folder info" {
        create_backup_dir() {
                :
        }
@@ -225,7 +225,7 @@ teardown() {
        assert_line --index 5 "✅ SUCCESS: backup"
 }
 
-@test "new backup folder with number 02 info" {
+@test "success new backup folder with number 02 info" {
        mkdir --parents "build/2000-01-01_01_backup"
        create_backup_dir() {
                :
@@ -247,7 +247,7 @@ teardown() {
        rmdir "build/2000-01-01_01_backup"
 }
 
-@test "create backup folder" {
+@test "success create backup folder" {
        backup_machines() {
                :
        }
@@ -265,7 +265,7 @@ teardown() {
        [ -d "build/2000-01-01_01_backup" ]
 }
 
-@test "backup machines" {
+@test "success backup machines" {
        machine_backup_pathes() {
                :
        }
@@ -287,7 +287,7 @@ teardown() {
        [ -d "build/2000-01-01_01_backup/testpc2" ]
 }
 
-@test "backup remote pathes" {
+@test "success backup machine pathes" {
        run main
 
        assert_success
@@ -309,4 +309,29 @@ teardown() {
        assert_line --index 15 "ℹ️ INFO: machine ${LIGHTPURPLE}testpc2${RESET}; path ${YELLOW}/home/other${RESET}"
        assert_line --index 16 "################################################################################"
        assert_line --index 17 "✅ SUCCESS: backup"
+}
+
+@test "failure backup machine pathes is null" {
+       yq() {
+               echo '{
+                       "backup_path": "build",
+                       "backup_name": "backup",
+                       "backup_count": 15,
+                       "machines": {
+                               "testpc1": null
+                       }
+                       }'
+       }
+
+       run main
+
+       assert_failure
+       assert_line --index 0 "⭐ START: backup"
+       assert_line --index 1 "ℹ️ INFO: backup path build"
+       assert_line --index 2 "ℹ️ INFO: backup name backup"
+       assert_line --index 3 "ℹ️ INFO: backup count 15"
+       assert_line --index 4 "ℹ️ INFO: backup folder 2000-01-01_01_backup"
+       assert_line --index 5 "ℹ️ INFO: create folder build/2000-01-01_01_backup"
+       assert_line --index 6 "ℹ️ INFO: create directory build/2000-01-01_01_backup/testpc1"
+       assert_line --index 7 "❌ ERROR: missing pathes for machine testpc1"
 }
\ No newline at end of file