WIP: test refactoring

This commit is contained in:
Jaka Hudoklin 2020-04-05 21:25:34 +07:00 committed by David Arnold
parent 8ad3b90a52
commit bbc5e3d477
No known key found for this signature in database
GPG key ID: 6D6A936E69C59D08
17 changed files with 714 additions and 66 deletions

View file

@ -0,0 +1,51 @@
{ 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}
''
else p.script;
tests = pkgs.linkFarm "${testing.name}-tests" (map (t: {
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;
}

View file

@ -0,0 +1,28 @@
{ lib, config, ... }:
with lib;
let
cfg = config.kubetest;
in {
options.test.kubetest = {
enable = mkOption {
description = "Whether to use kubetest test driver";
type = types.bool;
default = cfg.testScript != "";
};
testScript = mkOption {
type = types.lines;
description = "Test script to use for kubetest";
default = "";
};
extraPackages = mkOption {
type = types.listOf types.package;
description = "List of extra packages to use for kubetest";
default = [];
};
};
}

View file

@ -0,0 +1,15 @@
{ lib, config, ... }:
with lib;
{
options.testing.kubetest = {
defaultHeader = mkOption {
description = "Default test header";
type = types.lines;
default = ''
import pytest
'';
};
};
}