From: Bastian Dehn Date: Wed, 5 Aug 2026 18:31:20 +0000 (+0200) Subject: add error message for no pathes X-Git-Tag: v1.0.6^2~1^2~50 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=ded9164aed33a8c54612f29f09c35359eac8ced5;p=simple-backup.git add error message for no pathes --- diff --git a/src/backup b/src/backup index 7ab21bc..6a501ff 100755 --- a/src/backup +++ b/src/backup @@ -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= diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 4eebba4..2f3ecd9 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -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