mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 16:10:05 +01:00
WIP: test refactoring
This commit is contained in:
parent
8ad3b90a52
commit
bbc5e3d477
17 changed files with 714 additions and 66 deletions
51
modules/testing/driver/kubetest.nix
Normal file
51
modules/testing/driver/kubetest.nix
Normal 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;
|
||||
}
|
||||
28
modules/testing/driver/kubetest/test-options.nix
Normal file
28
modules/testing/driver/kubetest/test-options.nix
Normal 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 = [];
|
||||
};
|
||||
};
|
||||
}
|
||||
15
modules/testing/driver/kubetest/testing-options.nix
Normal file
15
modules/testing/driver/kubetest/testing-options.nix
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{ lib, config, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options.testing.kubetest = {
|
||||
defaultHeader = mkOption {
|
||||
description = "Default test header";
|
||||
type = types.lines;
|
||||
default = ''
|
||||
import pytest
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue