From 6937842e6816a13c7a4075eabf2a10f263155608 Mon Sep 17 00:00:00 2001
From: Jerome Charaoui <jerome@riseup.net>
Date: Sat, 23 Jan 2021 18:21:40 -0500
Subject: [PATCH] backup halt should trigger email report if enabled

---
 CHANGELOG.md          |  1 +
 src/backupninja.in    |  2 ++
 test/backupninja.bats | 13 ++++++++++---
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e94787c..c11a983 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - [build] make build reproducible regardless of usrmerge (DEBBUG-915222)
 - [core] silence exit code message unless --debug is used
+- [core] backup halt should trigger email report if enabled
 
 ## [1.2.0] - 2021-01-21
 
diff --git a/src/backupninja.in b/src/backupninja.in
index 985241b..5d482f9 100755
--- a/src/backupninja.in
+++ b/src/backupninja.in
@@ -606,6 +606,7 @@ if [ $actions_run == 0 ]; then doit=0
 elif [ "$reportemail" == "" ]; then doit=0
 elif [ $fatals != 0 ]; then doit=1
 elif [ $errors != 0 ]; then doit=1
+elif [ $halts != 0 ]; then doit=1
 elif [ "$reportsuccess" == "yes" ]; then doit=1
 elif [ "$reportwarning" == "yes" -a $warnings != 0 ]; then doit=1
 else doit=0
@@ -617,6 +618,7 @@ if [ $doit == 1 ]; then
    [ $warnings == 0 ] || subject="WARNING"
    [ $errors == 0 ] || subject="ERROR"
    [ $fatals == 0 ] || subject="FAILED"
+   [ $halts == 0 ] || subject="HALTED"
 
    {
       for ((i=0; i < ${#messages[@]} ; i++)); do
diff --git a/test/backupninja.bats b/test/backupninja.bats
index 90152de..96eecb6 100644
--- a/test/backupninja.bats
+++ b/test/backupninja.bats
@@ -68,14 +68,21 @@ create_test_action() {
     echo "${lines[0]}" | grep -qe '^Configuration files must not be writable/readable by group staff!'
 }
 
-@test "reports: error report is mailed" {
+@test "reports: report is mailed when halts > 0" {
+    create_test_action halt test_halt
+    run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh"
+    sleep 0.1
+    grep -q "\*halt\* -- ${BATS_TMPDIR}/backup.d/test.sh" /var/mail/vagrant
+}
+
+@test "reports: report is mailed when fatals > 0" {
     create_test_action fatal test_error
     run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh"
     sleep 0.1
     grep -q "\*failed\* -- ${BATS_TMPDIR}/backup.d/test.sh" /var/mail/vagrant
 }
 
-@test "reports: warning report is mailed" {
+@test "reports: report is mailed when reportwarning = yes and warnings > 0" {
     create_test_action warning test_warning
     setconfig backupninja.conf reportsuccess no
     setconfig backupninja.conf reportwarning yes
@@ -84,7 +91,7 @@ create_test_action() {
     grep -q "Warning: test_warning" /var/mail/vagrant
 }
 
-@test "reports: success report is mailed" {
+@test "reports: report is mailed when reportsuccess = yes" {
     create_test_action
     setconfig backupninja.conf reportsuccess yes
     run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh"
-- 
GitLab