kubenix/modules/testing/driver/kubetest.nix

52 lines
1.1 KiB
Nix
Raw Normal View History

2020-04-05 21:25:34 +07:00
{ lib, config, pkgs, ... }:
with lib;
let
testing = config.testing;
cfg = testing.driver.kubetest;
pythonEnv = pkgs.python37.withPackages (ps: with ps; [
pytest
kubetest
kubernetes
] ++ cfg.extraPackages);
toTestScript = t:
if isString t.script
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-05-06 16:07:24 -04:00
tests = builtins.trace testing pkgs.linkFarm "${testing.name}-tests" (map (t: {
2020-04-05 21:25:34 +07:00
path = toTestScript t;
name = "${t.name}_test.py";
}) testing.tests);
testScript = pkgs.writeScript "test-${testing.name}.sh" ''
#!/usr/bin/env bash
${pythonEnv}/bin/pytest -p no:cacheprovider ${tests} $@
'';
in {
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";
default = [];
};
};
config.testing.testScript = testScript;
}