feat(test): support for enabling and disabling tests

This commit is contained in:
Jaka Hudoklin 2019-02-13 17:03:27 +01:00
parent ae3b208821
commit c1b84f3192
No known key found for this signature in database
GPG key ID: 6A08896BFD32BD95
2 changed files with 26 additions and 10 deletions

View file

@ -14,6 +14,12 @@ with lib;
type = types.str; type = types.str;
}; };
enable = mkOption {
description = "Whether to enable test";
type = types.bool;
default = true;
};
assertions = mkOption { assertions = mkOption {
type = types.listOf (types.submodule { type = types.listOf (types.submodule {
options = { options = {

View file

@ -25,16 +25,14 @@ in {
inherit modules; inherit modules;
}).config.test; }).config.test;
evaled = builtins.trace "testing ${test.name}" (kubenix.evalKubernetesModules { evaled =
if test.enable
then builtins.trace "testing ${test.name}" (kubenix.evalKubernetesModules {
inherit modules; inherit modules;
}); })
else {success = false;};
in { in {
options = { options = {
module = mkOption {
description = "Module defining submodule";
type = types.unspecified;
};
name = mkOption { name = mkOption {
description = "test name"; description = "test name";
type = types.str; type = types.str;
@ -47,6 +45,17 @@ in {
internal = true; internal = true;
}; };
enable = mkOption {
description = "Whether to enable test";
type = types.bool;
internal = true;
};
module = mkOption {
description = "Module defining submodule";
type = types.unspecified;
};
evaled = mkOption { evaled = mkOption {
description = "Wheter test was evaled"; description = "Wheter test was evaled";
type = types.bool; type = types.bool;
@ -73,11 +82,12 @@ in {
}; };
config = { config = {
inherit (test) name description; inherit (test) name description enable;
assertions = mkIf config.evaled evaled.config.test.assertions; assertions = mkIf config.evaled evaled.config.test.assertions;
success = mkIf config.evaled (all (el: el.assertion) config.assertions); success = mkIf config.evaled (all (el: el.assertion) config.assertions);
}; };
}))); })));
apply = tests: filter (test: test.enable) tests;
}; };
testing.success = mkOption { testing.success = mkOption {
@ -94,7 +104,7 @@ in {
tests = map (test: { tests = map (test: {
inherit (test) name description evaled success; inherit (test) name description evaled success;
assertions = moduleToAttrs test.assertions; assertions = moduleToAttrs test.assertions;
}) cfg.tests; }) (filter (test: test.enable) cfg.tests);
}); });
}; };
}; };