summary refs log tree commit diff
path: root/nixos/tests/prometheus-exporters.nix
diff options
context:
space:
mode:
authorWilliButz <wbutz@cyberfnord.de>2019-05-31 22:01:27 +0200
committerWilliButz <wbutz@cyberfnord.de>2019-05-31 22:02:56 +0200
commit7884354c0fc741b1935b5fa8ea9e9ce53a27772a (patch)
treeb80bad5fe063a87a471775c44946bc68af8571bf /nixos/tests/prometheus-exporters.nix
parent6c7586228c70ce119cef4209ee288d0a3316086f (diff)
downloadnixpkgs-7884354c0fc741b1935b5fa8ea9e9ce53a27772a.tar
nixpkgs-7884354c0fc741b1935b5fa8ea9e9ce53a27772a.tar.gz
nixpkgs-7884354c0fc741b1935b5fa8ea9e9ce53a27772a.tar.bz2
nixpkgs-7884354c0fc741b1935b5fa8ea9e9ce53a27772a.tar.lz
nixpkgs-7884354c0fc741b1935b5fa8ea9e9ce53a27772a.tar.xz
nixpkgs-7884354c0fc741b1935b5fa8ea9e9ce53a27772a.tar.zst
nixpkgs-7884354c0fc741b1935b5fa8ea9e9ce53a27772a.zip
nixos/tests/prometheus-exporters: split into single tests
Generates a set of tests, rather than one large test for all exporters.
Diffstat (limited to 'nixos/tests/prometheus-exporters.nix')
-rw-r--r--nixos/tests/prometheus-exporters.nix81
1 files changed, 42 insertions, 39 deletions
diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix
index 140687a8182..ac50ca93489 100644
--- a/nixos/tests/prometheus-exporters.nix
+++ b/nixos/tests/prometheus-exporters.nix
@@ -1,6 +1,13 @@
-import ./make-test.nix ({ lib, pkgs, ... }:
+{ system ? builtins.currentSystem
+, config ? {}
+, pkgs ? import ../.. { inherit system config; }
+}:
+
+with pkgs.lib;
+with import ../lib/testing.nix { inherit system pkgs; };
+
 let
-  escape' = str: lib.replaceChars [''"'' "$" "\n"] [''\\\"'' "\\$" ""] str;
+  escape' = str: replaceChars [''"'' "$" "\n"] [''\\\"'' "\\$" ""] str;
 
 /*
  * The attrset `exporterTests` contains one attribute
@@ -51,6 +58,25 @@ let
 
   exporterTests = {
 
+    bind = {
+      exporterConfig = {
+        enable = true;
+      };
+      metricProvider = {
+        services.bind.enable = true;
+        services.bind.extraConfig = ''
+          statistics-channels {
+            inet 127.0.0.1 port 8053 allow { localhost; };
+          };
+        '';
+      };
+      exporterTest = ''
+        waitForUnit("prometheus-bind-exporter.service");
+        waitForOpenPort(9119);
+        succeed("curl -sSf http://localhost:9119/metrics" | grep -q 'bind_query_recursions_total 0');
+      '';
+    };
+
     blackbox = {
       exporterConfig = {
         enable = true;
@@ -106,25 +132,6 @@ let
       '';
     };
 
-    bind = {
-      exporterConfig = {
-        enable = true;
-      };
-      metricProvider = {
-        services.bind.enable = true;
-        services.bind.extraConfig = ''
-          statistics-channels {
-            inet 127.0.0.1 port 8053 allow { localhost; };
-          };
-        '';
-      };
-      exporterTest = ''
-        waitForUnit("prometheus-bind-exporter.service");
-        waitForOpenPort(9119);
-        succeed("curl -sSf http://localhost:9119/metrics" | grep -q 'bind_query_recursions_total 0');
-      '';
-    };
-
     dovecot = {
       exporterConfig = {
         enable = true;
@@ -309,27 +316,23 @@ let
       '';
     };
   };
+in
+mapAttrs (exporter: testConfig: (makeTest {
+  name = "prometheus-${exporter}-exporter";
 
-  nodes = lib.mapAttrs (exporter: testConfig: lib.mkMerge [{
+  nodes.${exporter} = mkMerge [{
     services.prometheus.exporters.${exporter} = testConfig.exporterConfig;
-  } testConfig.metricProvider or {}]) exporterTests;
-
-  testScript = lib.concatStrings (lib.mapAttrsToList (exporter: testConfig: (''
-    subtest "${exporter}", sub {
-      ${"$"+exporter}->start();
-      ${lib.concatStringsSep "  " (map (line: ''
-        ${"$"+exporter}->${line};
-      '') (lib.splitString "\n" (lib.removeSuffix "\n" testConfig.exporterTest)))}
-      ${"$"+exporter}->shutdown();
-    };
-  '')) exporterTests);
-in
-{
-  name = "prometheus-exporters";
+  } testConfig.metricProvider or {}];
 
-  inherit nodes testScript;
+  testScript = ''
+    ${"$"+exporter}->start();
+    ${concatStringsSep "  " (map (line: ''
+      ${"$"+exporter}->${line};
+    '') (splitString "\n" (removeSuffix "\n" testConfig.exporterTest)))}
+    ${"$"+exporter}->shutdown();
+  '';
 
-  meta = with lib.maintainers; {
+  meta = with maintainers; {
     maintainers = [ willibutz ];
   };
-})
+})) exporterTests