about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMinerSebas <scherthan_sebastian@web.de>2024-02-01 15:00:35 +0100
committerMinerSebas <scherthan_sebastian@web.de>2024-02-01 15:00:35 +0100
commitda91e4d75b1c35e3a712887b20d4c9984649ff88 (patch)
treea15b031bc6ae9dbaef3a714f0b193106a152f66a
parentd1f031cbbdca78a1fc6ebf7fa77e72a34045187a (diff)
downloadnixlib-da91e4d75b1c35e3a712887b20d4c9984649ff88.tar
nixlib-da91e4d75b1c35e3a712887b20d4c9984649ff88.tar.gz
nixlib-da91e4d75b1c35e3a712887b20d4c9984649ff88.tar.bz2
nixlib-da91e4d75b1c35e3a712887b20d4c9984649ff88.tar.lz
nixlib-da91e4d75b1c35e3a712887b20d4c9984649ff88.tar.xz
nixlib-da91e4d75b1c35e3a712887b20d4c9984649ff88.tar.zst
nixlib-da91e4d75b1c35e3a712887b20d4c9984649ff88.zip
nixos/tests/prometheus-exporters: add test for prometheus-restic-exporter
-rw-r--r--nixos/tests/prometheus-exporters.nix40
-rw-r--r--pkgs/by-name/pr/prometheus-restic-exporter/package.nix5
2 files changed, 44 insertions, 1 deletions
diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index 53e6626c0e32..a39f3ca0739b 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -1217,6 +1217,39 @@ let
       '';
     };
 
+    restic =
+      let
+        repository = "rest:http://127.0.0.1:8000";
+        passwordFile = pkgs.writeText "restic-test-password" "test-password";
+      in
+      {
+        exporterConfig = {
+          enable = true;
+          inherit repository passwordFile;
+        };
+        metricProvider = {
+          services.restic.server = {
+            enable = true;
+            extraFlags = [ "--no-auth" ];
+          };
+          environment.systemPackages = [ pkgs.restic ];
+        };
+        exporterTest = ''
+          # prometheus-restic-exporter.service fails without initialised repository
+          systemctl("stop prometheus-restic-exporter.service")
+
+          # Initialise the repository
+          wait_for_unit("restic-rest-server.service")
+          wait_for_open_port(8000)
+          succeed("restic init --repo ${repository} --password-file ${passwordFile}")
+
+          systemctl("start prometheus-restic-exporter.service")
+          wait_for_unit("prometheus-restic-exporter.service")
+          wait_for_open_port(9753)
+          wait_until_succeeds("curl -sSf localhost:9753/metrics | grep 'restic_check_success 1.0'")
+        '';
+      };
+
     rspamd = {
       exporterConfig = {
         enable = true;
@@ -1722,7 +1755,12 @@ mapAttrs
       testScript = ''
         ${nodeName}.start()
         ${concatStringsSep "\n" (map (line:
-          if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")")
+          if builtins.any (b: b) [
+            (builtins.match "^[[:space:]]*$" line != null)
+            (builtins.substring 0 1 line == "#")
+            (builtins.substring 0 1 line == " ")
+            (builtins.substring 0 1 line == ")")
+          ]
           then line
           else "${nodeName}.${line}"
         ) (splitString "\n" (removeSuffix "\n" testConfig.exporterTest)))}
diff --git a/pkgs/by-name/pr/prometheus-restic-exporter/package.nix b/pkgs/by-name/pr/prometheus-restic-exporter/package.nix
index 89d8cbae499f..4e3736a573b6 100644
--- a/pkgs/by-name/pr/prometheus-restic-exporter/package.nix
+++ b/pkgs/by-name/pr/prometheus-restic-exporter/package.nix
@@ -3,6 +3,7 @@
 , fetchFromGitHub
 , python3
 , restic
+, nixosTests
 }:
 
 stdenvNoCC.mkDerivation rec {
@@ -32,6 +33,10 @@ stdenvNoCC.mkDerivation rec {
     runHook postInstall
   '';
 
+  passthru.tests = {
+    restic-exporter = nixosTests.prometheus-exporters.restic;
+  };
+
   meta = with lib; {
     description = "Prometheus exporter for the Restic backup system";
     homepage = "https://github.com/ngosang/restic-exporter";