From: Bastian Dehn Date: Tue, 11 Aug 2026 16:07:45 +0000 (+0200) Subject: add green tests with stat X-Git-Tag: v1.0.6^2~1^2~5 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=aa4268a4f7df4980a01ee6f98d47d0ee3b97e9f7;p=simple-backup.git add green tests with stat --- diff --git a/src/backup b/src/backup index d59edc1..bbb9e81 100755 --- a/src/backup +++ b/src/backup @@ -411,7 +411,9 @@ check_backup_date() stat_file=$(echo "$config" | jq --raw-output '.backup_stat_file') [ -n "$NOCOLOR" ] && LIGHTRED= && LIGHTGREEN= && RESET= && color= [ "$stat_file" != "null" ] || return 0 - [ -f "$stat_file" ] || printf "none%-.s\n" {1..3} > "$stat_file" + [ -f "$stat_file" ] \ + || printf "none%-.s\n" {1..3} 2> /dev/null 1> "$stat_file" \ + || return 0 for type in day week month; do status="ok" @@ -434,7 +436,9 @@ update_stat() local month= stat_file=$(echo "$config" | jq --raw-output '.backup_stat_file') [ "$stat_file" != "null" ] || return 0 - [ -f "$stat_file" ] || printf "none%-.s\n" {1..3} > "$stat_file" + [ -f "$stat_file" ] \ + || printf "none%-.s\n" {1..3} 2> /dev/null 1> "$stat_file" \ + || return 0 type=$(get_backup_type "$config") day=$(awk 'NR==1 {print; exit}' "$stat_file") diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 1f223c7..e180310 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -296,8 +296,11 @@ teardown() { assert_line --index 5 "ℹ️ INFO: backup folder 2000-01-01_02_backup" assert_line --index 6 "💾 START: backup run" assert_line --index 7 "ℹ️ INFO: backup count: 1" - assert_line --index 8 "🏁 FINISH: backup run" - assert_line --index 9 "✅ SUCCESS: backup" + assert_line --index 8 "day none old" + assert_line --index 9 "week none old" + assert_line --index 10 "month none old" + assert_line --index 11 "🏁 FINISH: backup run" + assert_line --index 12 "✅ SUCCESS: backup" } # bats test_tags=backup:info @@ -320,8 +323,11 @@ teardown() { assert_line --index 5 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup" assert_line --index 6 "💾 START: backup run" assert_line --index 7 "ℹ️ INFO: backup count: 1" - assert_line --index 8 "🏁 FINISH: backup run" - assert_line --index 9 "✅ SUCCESS: backup" + assert_line --index 8 "day none old" + assert_line --index 9 "week none old" + assert_line --index 10 "month none old" + assert_line --index 11 "🏁 FINISH: backup run" + assert_line --index 12 "✅ SUCCESS: backup" [ -d "build/test/2000-01-01_01_backup" ] } @@ -347,8 +353,11 @@ teardown() { assert_line --index 6 "ℹ️ INFO: create folder build/test/2000-01-01_36_backup" assert_line --index 7 "💾 START: backup run" assert_line --index 8 "ℹ️ INFO: backup count: 2" - assert_line --index 9 "🏁 FINISH: backup run" - assert_line --index 10 "✅ SUCCESS: backup" + assert_line --index 9 "day none old" + assert_line --index 10 "week none old" + assert_line --index 11 "month none old" + assert_line --index 12 "🏁 FINISH: backup run" + assert_line --index 13 "✅ SUCCESS: backup" [ -d "build/test/2000-01-01_36_backup" ] } @@ -374,8 +383,11 @@ teardown() { assert_line --index 6 "ℹ️ INFO: create folder build/test/2000-01-01_01_backup" assert_line --index 7 "💾 START: backup run" assert_line --index 8 "ℹ️ INFO: backup count: 2" - assert_line --index 9 "🏁 FINISH: backup run" - assert_line --index 10 "✅ SUCCESS: backup" + assert_line --index 9 "day none old" + assert_line --index 10 "week none old" + assert_line --index 11 "month none old" + assert_line --index 12 "🏁 FINISH: backup run" + assert_line --index 13 "✅ SUCCESS: backup" [ -d "build/test/2000-01-01_01_backup" ] } @@ -403,8 +415,11 @@ teardown() { assert_line --index 9 "ℹ️ INFO: create directory build/test/2000-01-01_01_backup/onlylocal" assert_line --index 10 "ℹ️ INFO: 2000-01-01T23:30:45+02:00 [none] created 2000-01-01_01_backup -> build/test/backup.log" assert_line --index 11 "ℹ️ INFO: backup count: 1" - assert_line --index 12 "🏁 FINISH: backup run" - assert_line --index 13 "✅ SUCCESS: backup" + assert_line --index 12 "day none old" + assert_line --index 13 "week none old" + assert_line --index 14 "month none old" + assert_line --index 15 "🏁 FINISH: backup run" + assert_line --index 16 "✅ SUCCESS: backup" [ -d "build/test/2000-01-01_01_backup" ] [ -d "build/test/2000-01-01_01_backup/testpc1" ] [ -d "build/test/2000-01-01_01_backup/testpc2" ] @@ -445,8 +460,11 @@ teardown() { assert_line --index 21 "################################################################################" assert_line --index 22 "ℹ️ INFO: 2000-01-01T23:30:45+02:00 [none] created 2000-01-01_01_backup -> build/test/backup.log" assert_line --index 23 "ℹ️ INFO: backup count: 1" - assert_line --index 24 "🏁 FINISH: backup run" - assert_line --index 25 "✅ SUCCESS: backup" + assert_line --index 24 "day none old" + assert_line --index 25 "week none old" + assert_line --index 26 "month none old" + assert_line --index 27 "🏁 FINISH: backup run" + assert_line --index 28 "✅ SUCCESS: backup" } # bats test_tags=backup:info