This commit is contained in:
David Arnold 2021-05-13 17:27:08 -04:00
parent c3fa598922
commit db6d83c61e
No known key found for this signature in database
GPG key ID: 6D6A936E69C59D08
53 changed files with 1916 additions and 1599 deletions

View file

@ -1,7 +1,6 @@
{ nixosPath, config, pkgs, lib, kubenix, ... }:
with lib;
let
cfg = config.testing;
@ -18,7 +17,8 @@ let
isTestEnabled = test:
(cfg.enabledTests == null || elem test.name cfg.enabledTests) && test.enable;
in {
in
{
imports = [
./docker.nix
./driver/kubetest.nix
@ -40,30 +40,32 @@ in {
defaults = mkOption {
description = "List of defaults to apply to tests";
type = types.listOf (types.submodule ({config, ...}: {
type = types.listOf (types.submodule ({ config, ... }: {
options = {
features = mkOption {
description = "List of features that test has to have to apply defaults";
type = types.listOf types.str;
default = [];
default = [ ];
};
default = mkOption {
description = "Default to apply to test";
type = types.unspecified;
default = {};
default = { };
};
};
}));
default = [];
default = [ ];
};
tests = mkOption {
description = "List of test cases";
default = [];
type = types.listOf (types.coercedTo types.path (module: {
inherit module;
}) (types.submodule testModule));
default = [ ];
type = types.listOf (types.coercedTo types.path
(module: {
inherit module;
})
(types.submodule testModule));
apply = tests: filter isTestEnabled tests;
};
@ -82,7 +84,7 @@ in {
args = mkOption {
description = "Attribute set of extra args passed to tests";
type = types.attrs;
default = {};
default = { };
};
success = mkOption {

View file

@ -1,16 +1,16 @@
{ config, lib, pkgs, ... }:
with lib;
with import ../../lib/docker.nix { inherit lib pkgs; };
with import ../../lib/docker.nix { inherit lib pkgs; };
let
testing = config.testing;
allImages = flatten (map (t: t.evaled.config.docker.export or []) testing.tests);
allImages = flatten (map (t: t.evaled.config.docker.export or [ ]) testing.tests);
cfg = config.testing.docker;
in {
in
{
options.testing.docker = {
registryUrl = mkOption {
description = "Docker registry url";
@ -38,7 +38,7 @@ in {
};
config.testing.defaults = [{
features = ["docker"];
features = [ "docker" ];
default = {
docker.registry.url = cfg.registryUrl;
};

View file

@ -1,12 +1,11 @@
{ lib, config, pkgs, ... }:
with lib;
let
testing = config.testing;
cfg = testing.driver.kubetest;
kubetest = import ./kubetestdrv.nix {inherit pkgs;};
kubetest = import ./kubetestdrv.nix { inherit pkgs; };
pythonEnv = pkgs.python38.withPackages (ps: with ps; [
pytest
@ -16,18 +15,20 @@ let
toTestScript = t:
if isString t.script
then pkgs.writeText "${t.name}.py" ''
${cfg.defaultHeader}
${t.script}
''
then
pkgs.writeText "${t.name}.py" ''
${cfg.defaultHeader}
${t.script}
''
else t.script;
tests = pkgs.linkFarm "${testing.name}-tests" (
map (t: {
path = toTestScript t;
name = "${t.name}_test.py";
})
( filter (t: t.script != null) testing.tests )
map
(t: {
path = toTestScript t;
name = "${t.name}_test.py";
})
(filter (t: t.script != null) testing.tests)
);
testScript = pkgs.writeScript "test-${testing.name}.sh" ''
@ -35,7 +36,8 @@ let
${pythonEnv}/bin/pytest -p no:cacheprovider ${tests} $@
'';
in {
in
{
options.testing.driver.kubetest = {
defaultHeader = mkOption {
type = types.lines;
@ -48,7 +50,7 @@ in {
extraPackages = mkOption {
type = types.listOf types.package;
description = "Extra packages to pass to tests";
default = [];
default = [ ];
};
};

View file

@ -1,7 +1,6 @@
{ lib, config, testing, kubenix, ... }:
with lib;
let
modules = [
# testing module
@ -36,25 +35,29 @@ let
# defaults that can be applied on tests
defaults =
filter (d:
(intersectLists d.features testFeatures) == d.features ||
(length d.features) == 0
) testing.defaults;
filter
(d:
(intersectLists d.features testFeatures) == d.features ||
(length d.features) == 0
)
testing.defaults;
# add default modules to all modules
modulesWithDefaults = modules ++ (map (d: d.default) defaults);
# evaled test
evaled = let
evaled' = kubenix.evalModules {
modules = modulesWithDefaults;
};
in
evaled =
let
evaled' = kubenix.evalModules {
modules = modulesWithDefaults;
};
in
if testing.throwError then evaled'
else if (builtins.tryEval evaled'.config.test.assertions).success
then evaled' else null;
in {
in
{
options = {
module = mkOption {
description = "Module defining kubenix test";
@ -97,7 +100,7 @@ in {
description = "Test result";
type = types.unspecified;
internal = true;
default = [];
default = [ ];
};
script = mkOption {

View file

@ -1,7 +1,6 @@
{ lib, config, pkgs, ... }:
with lib;
let
testing = config.testing;
@ -32,7 +31,8 @@ let
echo "--> running tests"
${testing.testScript} --kube-config=$KUBECONFIG
'';
in {
in
{
options.testing.runtime.local = {
script = mkOption {
type = types.package;

View file

@ -9,7 +9,6 @@
}:
with lib;
let
testing = config.testing;
kubeconfig = "/etc/${config.services.kubernetes.pki.etcClusterAdminKubeconfig}";

View file

@ -1,11 +1,11 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.test;
in {
in
{
options.test = {
name = mkOption {
description = "Test name";
@ -38,8 +38,8 @@ in {
};
};
});
default = [];
example = [ { assertion = false; message = "you can't enable this for some reason"; } ];
default = [ ];
example = [{ assertion = false; message = "you can't enable this for some reason"; }];
description = ''
This option allows modules to express conditions that must
hold for the evaluation of the system configuration to