From 8c49e5a78c6226d4dd88cd886d36519158d997ec Mon Sep 17 00:00:00 2001 From: elseym Date: Mon, 31 Aug 2020 13:38:54 +0200 Subject: [PATCH] tests/prometheus-exporters: allow overriding test-node-name allows the prometheus-exporters test abstraction to work with e.g. hyphenated exporter-names --- nixos/tests/prometheus-exporters.nix | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index b912e3425e0e..7327dcae87d2 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -22,6 +22,9 @@ let * `metricProvider` (optional) * this attribute contains additional machine config * + * `nodeName` (optional) + * override an incompatible testnode name + * * Example: * exporterTests. = { * exporterConfig = { @@ -646,24 +649,27 @@ let }; }; in -mapAttrs (exporter: testConfig: (makeTest { +mapAttrs (exporter: testConfig: (makeTest (let + nodeName = testConfig.nodeName or exporter; + +in { name = "prometheus-${exporter}-exporter"; - nodes.${exporter} = mkMerge [{ + nodes.${nodeName} = mkMerge [{ services.prometheus.exporters.${exporter} = testConfig.exporterConfig; } testConfig.metricProvider or {}]; testScript = '' - ${exporter}.start() + ${nodeName}.start() ${concatStringsSep "\n" (map (line: if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")") then line - else "${exporter}.${line}" + else "${nodeName}.${line}" ) (splitString "\n" (removeSuffix "\n" testConfig.exporterTest)))} - ${exporter}.shutdown() + ${nodeName}.shutdown() ''; meta = with maintainers; { - maintainers = [ willibutz ]; + maintainers = [ willibutz elseym ]; }; -})) exporterTests +}))) exporterTests