From 01311ad238464fa1273080fb328bf0ba0e5de5fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Charaoui?= <jerome@riseup.net>
Date: Sun, 12 Feb 2023 13:59:23 -0500
Subject: [PATCH] add basic test for prometheus exporter

---
 test/backupninja.bats | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/test/backupninja.bats b/test/backupninja.bats
index a8ca55b..e5c9553 100644
--- a/test/backupninja.bats
+++ b/test/backupninja.bats
@@ -1,9 +1,14 @@
 load common
 
+begin_backupninja() {
+    install_pkgs prometheus-node-exporter
+}
+
 teardown_backupninja() {
     [ -x /usr/bin/mail.moved ] && mv /usr/bin/mail.moved /usr/bin/mail
     [ -x /usr/bin/rsync.moved ] && mv /usr/bin/rsync.moved /usr/bin/rsync
     rm -f /var/mail/vagrant
+    rm -f /var/lib/prometheus/node-exporter/backupninja.prom
 }
 
 create_test_action() {
@@ -246,6 +251,14 @@ create_test_action() {
     ! test -f /var/mail/vagrant
 }
 
+@test "reports: writes prometheus metrics when reportprom is yes" {
+    create_test_action info test_info
+    setconfig backupninja.conf reportprom yes
+    run backupninja --now -f "${BATS_TMPDIR}/backupninja.conf" --run "${BATS_TMPDIR}/backup.d/test.sh"
+    [ "$status" -eq 0 ]
+    grep -q "^backupninja_actions{host=\"$(hostname)\"} 1$" /var/lib/prometheus/node-exporter/backupninja.prom
+}
+
 @test "scheduling: runs when = 'everyday at 01' and time matches" {
     create_test_action info test_info
     setconfig backupninja.conf when 'everyday at 01'
-- 
GitLab