]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add green tests with stat
authorBastian Dehn <hhaalo@arcor.de>
Tue, 11 Aug 2026 16:07:45 +0000 (18:07 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Tue, 11 Aug 2026 16:07:45 +0000 (18:07 +0200)
src/backup
tests/backup_tests.bats

index d59edc131e2d90dfecb4548df94edd5aaa404604..bbb9e818e049b0e0fae272440f0b38d9d6cbe8ec 100755 (executable)
@@ -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")
index 1f223c716daac6df57a4650032b34f781e29fae2..e180310a80624fcf81d2dd9e8bbc36f0a92a52a1 100755 (executable)
@@ -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