Skip to content

Commit

Permalink
tests/prometheus-exporters: allow overriding test-node-name
Browse files Browse the repository at this point in the history
allows the prometheus-exporters test abstraction to work with e.g. hyphenated exporter-names
  • Loading branch information
elseym committed Sep 6, 2020
1 parent b381aac commit 8c49e5a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions nixos/tests/prometheus-exporters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ let
* `metricProvider` (optional)
* this attribute contains additional machine config
*
* `nodeName` (optional)
* override an incompatible testnode name
*
* Example:
* exporterTests.<exporterName> = {
* exporterConfig = {
Expand Down Expand Up @@ -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

0 comments on commit 8c49e5a

Please sign in to comment.