2022-04-02 13:28:07 -07:00
|
|
|
{
|
|
|
|
|
lib,
|
|
|
|
|
config,
|
|
|
|
|
pkgs,
|
|
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
with lib; let
|
2022-04-02 13:43:57 -07:00
|
|
|
inherit (config) testing;
|
2020-04-05 21:25:34 +07:00
|
|
|
cfg = testing.driver.kubetest;
|
|
|
|
|
|
2022-04-02 13:28:07 -07:00
|
|
|
kubetest = import ./kubetestdrv.nix {inherit pkgs;};
|
2021-05-08 13:02:20 -04:00
|
|
|
|
2022-04-02 13:28:07 -07:00
|
|
|
pythonEnv = pkgs.python38.withPackages (ps:
|
|
|
|
|
with ps;
|
|
|
|
|
[
|
|
|
|
|
pytest
|
|
|
|
|
kubetest
|
|
|
|
|
kubernetes
|
|
|
|
|
]
|
|
|
|
|
++ cfg.extraPackages);
|
2020-04-05 21:25:34 +07:00
|
|
|
|
|
|
|
|
toTestScript = t:
|
|
|
|
|
if isString t.script
|
2021-05-13 17:27:08 -04:00
|
|
|
then
|
|
|
|
|
pkgs.writeText "${t.name}.py" ''
|
|
|
|
|
${cfg.defaultHeader}
|
|
|
|
|
${t.script}
|
|
|
|
|
''
|
2021-05-06 16:07:24 -04:00
|
|
|
else t.script;
|
2020-04-05 21:25:34 +07:00
|
|
|
|
2021-06-01 10:28:53 -05:00
|
|
|
tests = let
|
2022-04-02 13:28:07 -07:00
|
|
|
# make sure tests are prefixed so that alphanumerical
|
|
|
|
|
# sorting reproduces them in the same order as they
|
|
|
|
|
# have been declared in the list.
|
|
|
|
|
seive = t: t.script != null && t.enabled;
|
|
|
|
|
allEligibleTests = filter seive testing.tests;
|
|
|
|
|
listLengthPadding = builtins.length (
|
|
|
|
|
lib.stringToCharacters (
|
|
|
|
|
builtins.toString (
|
|
|
|
|
builtins.length allEligibleTests
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
op = i: t: {
|
|
|
|
|
path = toTestScript t;
|
|
|
|
|
name = let
|
|
|
|
|
prefix = lib.fixedWidthNumber listLengthPadding i;
|
|
|
|
|
in "${prefix}_${t.name}_test.py";
|
|
|
|
|
};
|
|
|
|
|
in
|
|
|
|
|
pkgs.linkFarm "${testing.name}-tests" (
|
|
|
|
|
lib.imap0 op allEligibleTests
|
|
|
|
|
);
|
2020-04-05 21:25:34 +07:00
|
|
|
|
|
|
|
|
testScript = pkgs.writeScript "test-${testing.name}.sh" ''
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
${pythonEnv}/bin/pytest -p no:cacheprovider ${tests} $@
|
|
|
|
|
'';
|
2022-04-02 13:28:07 -07:00
|
|
|
in {
|
2020-04-05 21:25:34 +07:00
|
|
|
options.testing.driver.kubetest = {
|
|
|
|
|
defaultHeader = mkOption {
|
|
|
|
|
type = types.lines;
|
|
|
|
|
description = "Default test header";
|
|
|
|
|
default = ''
|
|
|
|
|
import pytest
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extraPackages = mkOption {
|
|
|
|
|
type = types.listOf types.package;
|
|
|
|
|
description = "Extra packages to pass to tests";
|
2022-04-02 13:28:07 -07:00
|
|
|
default = [];
|
2020-04-05 21:25:34 +07:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config.testing.testScript = testScript;
|
|
|
|
|
}
|