]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add old month and ok
authorBastian Dehn <hhaalo@arcor.de>
Mon, 10 Aug 2026 18:42:14 +0000 (20:42 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 10 Aug 2026 18:42:14 +0000 (20:42 +0200)
src/backup
tests/backup_tests.bats

index 76b56adc115c9430d806c92e63c759a37984caa1..d3f44f319a5caa746d12f8c08bb87e730c0f1f48 100755 (executable)
@@ -381,7 +381,16 @@ is_backup_old()
        case "$type" in
        "day") [ "$diff" -ge "0" ] || return 1 ;;
        "week") [ "$diff" -ge "-6" ] || return 1 ;;
-       "month") [ "$backup_month" == "$now_month" ] || return 1 ;;
+       "month")
+               local current_date=
+               local current_year=
+               local current_month=
+               current_date=$(get_date)
+               current_year=${current_date:0:4}
+               current_month=${current_date:5:2}
+               [ "$current_year" == "${date:0:4}" ] || return 1
+               [ "$current_month" == "${date:5:2}" ] || return 1
+               ;;
        *) return 0 ;;
        esac
 }
index 4eca8108305737350ae225f54510887b3ad24075..28d86b3e75f4f99f13e9417fc35ed1b92412643c 100755 (executable)
@@ -1063,4 +1063,55 @@ teardown() {
        assert_line --index 0 "day   none       old"
        assert_line --index 1 "week  2000-01-01 old"
        assert_line --index 2 "month none       old"
+}
+
+# bats test_tags=backup:check
+@test "success check backup date month ok" {
+       mkdir --parents "build/test"
+       printf "none\nnone\n2000-01-01\n" > "build/test/stats"
+       get_date() {
+               echo "2000-01-01"
+       }
+
+       run main "check"
+
+       assert_success
+       [ -f "build/test/stats" ]
+       assert_line --index 0 "day   none       old"
+       assert_line --index 1 "week  none       old"
+       assert_line --index 2 "month 2000-01-01 ok"
+}
+
+# bats test_tags=backup:check
+@test "success check backup date month old over year" {
+       mkdir --parents "build/test"
+       printf "none\nnone\n2000-01-01\n" > "build/test/stats"
+       get_date() {
+               date --date="2000-01-01" +%s
+       }
+
+       run main "check"
+
+       assert_success
+       [ -f "build/test/stats" ]
+       assert_line --index 0 "day   none       old"
+       assert_line --index 1 "week  none       old"
+       assert_line --index 2 "month 2000-01-01 old"
+}
+
+# bats test_tags=backup:check
+@test "success check backup date month old" {
+       mkdir --parents "build/test"
+       printf "none\nnone\n2000-01-01\n" > "build/test/stats"
+       get_date() {
+               echo "2000-02-01"
+       }
+
+       run main "check"
+
+       assert_success
+       [ -f "build/test/stats" ]
+       assert_line --index 0 "day   none       old"
+       assert_line --index 1 "week  none       old"
+       assert_line --index 2 "month 2000-01-01 old"
 }
\ No newline at end of file