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
}
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