From a37bdca908bd955225d72de8f61fe7e662b4ce7f Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Mon, 10 Aug 2026 20:42:14 +0200 Subject: [PATCH] add old month and ok --- src/backup | 11 ++++++++- tests/backup_tests.bats | 51 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/backup b/src/backup index 76b56ad..d3f44f3 100755 --- a/src/backup +++ b/src/backup @@ -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 } diff --git a/tests/backup_tests.bats b/tests/backup_tests.bats index 4eca810..28d86b3 100755 --- a/tests/backup_tests.bats +++ b/tests/backup_tests.bats @@ -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 -- 2.47.3