assert_output ""
}
-write_log_entry() {
- local type="$1"
+# bats test_tags=backup:log
+@test "success log has logfile entry for type none" {
+ mkdir --parents build/test
+ local config=
+ config=$(yq '.' "$CONFIG_FILE")
+ get_date_time() {
+ echo "2000-01-01T23:30:45+02:00"
+ }
+
+ run log "$config" "log entry"
+
+ assert_success
+ assert_output "ℹ️ INFO: 2000-01-01T23:30:45+02:00 [none] log entry -> build/test/backup.log"
+ assert_equal "$(cat "build/test/backup.log")" "2000-01-01T23:30:45+02:00 [none] log entry"
+}
+
+# bats test_tags=backup:log
+@test "success log has logfile entry for type day" {
mkdir --parents build/test
- touch "build/test/$type"
+ touch build/test/day
local config=
config=$(yq '.' "$CONFIG_FILE")
get_date_time() {
run log "$config" "log entry"
assert_success
- assert_output "ℹ️ INFO: 2000-01-01T23:30:45+02:00 [$type] log entry -> build/test/backup.log"
- assert_equal "$(cat "build/test/backup.log")" "2000-01-01T23:30:45+02:00 [$type] log entry"
+ assert_output "ℹ️ INFO: 2000-01-01T23:30:45+02:00 [day] log entry -> build/test/backup.log"
+ assert_equal "$(cat "build/test/backup.log")" "2000-01-01T23:30:45+02:00 [day] log entry"
}
-for type in none day week month; do
- bats_test_function --tags "backup:log" \
- --description "success log has logfile entry for type $type" \
- -- \
- write_log_entry "$type"
-done
+# bats test_tags=backup:log
+@test "success log has logfile entry for type week" {
+ mkdir --parents build/test
+ touch build/test/week
+ local config=
+ config=$(yq '.' "$CONFIG_FILE")
+ get_date_time() {
+ echo "2000-01-01T23:30:45+02:00"
+ }
+
+ run log "$config" "log entry"
+
+ assert_success
+ assert_output "ℹ️ INFO: 2000-01-01T23:30:45+02:00 [week] log entry -> build/test/backup.log"
+ assert_equal "$(cat "build/test/backup.log")" "2000-01-01T23:30:45+02:00 [week] log entry"
+}
+
+# bats test_tags=backup:log
+@test "success log has logfile entry for type month" {
+ mkdir --parents build/test
+ touch build/test/month
+ local config=
+ config=$(yq '.' "$CONFIG_FILE")
+ get_date_time() {
+ echo "2000-01-01T23:30:45+02:00"
+ }
+
+ run log "$config" "log entry"
+
+ assert_success
+ assert_output "ℹ️ INFO: 2000-01-01T23:30:45+02:00 [month] log entry -> build/test/backup.log"
+ assert_equal "$(cat "build/test/backup.log")" "2000-01-01T23:30:45+02:00 [month] log entry"
+}
# bats test_tags=backup:log
@test "success no logrotate by 99 lines" {