tests/prometheus-exporters: allow overriding test-node-name

allows the prometheus-exporters test abstraction to work with e.g. hyphenated exporter-names
This commit is contained in:
elseym 2020-08-31 13:38:54 +02:00
parent b381aacbba
commit 8c49e5a78c
No known key found for this signature in database
GPG key ID: 8696D1F9E5C020D2

View file

@ -22,6 +22,9 @@ let
* `metricProvider` (optional) * `metricProvider` (optional)
* this attribute contains additional machine config * this attribute contains additional machine config
* *
* `nodeName` (optional)
* override an incompatible testnode name
*
* Example: * Example:
* exporterTests.<exporterName> = { * exporterTests.<exporterName> = {
* exporterConfig = { * exporterConfig = {
@ -646,24 +649,27 @@ let
}; };
}; };
in in
mapAttrs (exporter: testConfig: (makeTest { mapAttrs (exporter: testConfig: (makeTest (let
nodeName = testConfig.nodeName or exporter;
in {
name = "prometheus-${exporter}-exporter"; name = "prometheus-${exporter}-exporter";
nodes.${exporter} = mkMerge [{ nodes.${nodeName} = mkMerge [{
services.prometheus.exporters.${exporter} = testConfig.exporterConfig; services.prometheus.exporters.${exporter} = testConfig.exporterConfig;
} testConfig.metricProvider or {}]; } testConfig.metricProvider or {}];
testScript = '' testScript = ''
${exporter}.start() ${nodeName}.start()
${concatStringsSep "\n" (map (line: ${concatStringsSep "\n" (map (line:
if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")") if (builtins.substring 0 1 line == " " || builtins.substring 0 1 line == ")")
then line then line
else "${exporter}.${line}" else "${nodeName}.${line}"
) (splitString "\n" (removeSuffix "\n" testConfig.exporterTest)))} ) (splitString "\n" (removeSuffix "\n" testConfig.exporterTest)))}
${exporter}.shutdown() ${nodeName}.shutdown()
''; '';
meta = with maintainers; { meta = with maintainers; {
maintainers = [ willibutz ]; maintainers = [ willibutz elseym ];
}; };
})) exporterTests }))) exporterTests