2020-04-05 21:25:34 +07:00
|
|
|
{ lib, config, testing, kubenix, ... }:
|
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
let
|
|
|
|
|
modules = [
|
|
|
|
|
# testing module
|
|
|
|
|
config.module
|
|
|
|
|
|
|
|
|
|
./test-options.nix
|
|
|
|
|
../base.nix
|
|
|
|
|
|
|
|
|
|
# passthru some options to test
|
|
|
|
|
{
|
|
|
|
|
config = {
|
|
|
|
|
kubenix.project = mkDefault config.name;
|
|
|
|
|
_module.args = {
|
|
|
|
|
inherit kubenix;
|
2021-05-31 21:45:22 -05:00
|
|
|
test = evaled.config;
|
2020-04-05 21:25:34 +07:00
|
|
|
} // testing.args;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
# eval without checking
|
|
|
|
|
evaled' = kubenix.evalModules {
|
|
|
|
|
check = false;
|
|
|
|
|
inherit modules;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# test configuration
|
|
|
|
|
testConfig = evaled'.config.test;
|
|
|
|
|
|
|
|
|
|
# test features
|
|
|
|
|
testFeatures = evaled'.config._m.features;
|
|
|
|
|
|
2021-05-31 22:31:37 -05:00
|
|
|
# common options that can be applied on this test
|
|
|
|
|
commonOpts =
|
2021-05-13 17:27:08 -04:00
|
|
|
filter
|
|
|
|
|
(d:
|
|
|
|
|
(intersectLists d.features testFeatures) == d.features ||
|
|
|
|
|
(length d.features) == 0
|
|
|
|
|
)
|
2021-05-31 22:31:37 -05:00
|
|
|
testing.common;
|
2020-04-05 21:25:34 +07:00
|
|
|
|
2021-05-31 22:31:37 -05:00
|
|
|
# add common options modules to all modules
|
|
|
|
|
modulesWithCommonOptions = modules ++ (map (d: d.options) commonOpts);
|
2020-04-05 21:25:34 +07:00
|
|
|
|
|
|
|
|
# evaled test
|
2021-05-13 17:27:08 -04:00
|
|
|
evaled =
|
|
|
|
|
let
|
|
|
|
|
evaled' = kubenix.evalModules {
|
2021-05-31 22:31:37 -05:00
|
|
|
modules = modulesWithCommonOptions;
|
2021-05-13 17:27:08 -04:00
|
|
|
};
|
|
|
|
|
in
|
2021-06-01 09:59:52 -05:00
|
|
|
if testing.doThrowError then evaled'
|
2020-04-05 21:25:34 +07:00
|
|
|
else if (builtins.tryEval evaled'.config.test.assertions).success
|
|
|
|
|
then evaled' else null;
|
|
|
|
|
|
2021-05-13 17:27:08 -04:00
|
|
|
in
|
|
|
|
|
{
|
2020-04-05 21:25:34 +07:00
|
|
|
options = {
|
|
|
|
|
module = mkOption {
|
|
|
|
|
description = "Module defining kubenix test";
|
|
|
|
|
type = types.unspecified;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
evaled = mkOption {
|
|
|
|
|
description = "Test evaulation result";
|
|
|
|
|
type = types.nullOr types.attrs;
|
|
|
|
|
internal = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
success = mkOption {
|
|
|
|
|
description = "Whether test assertions were successfull";
|
|
|
|
|
type = types.bool;
|
|
|
|
|
internal = true;
|
|
|
|
|
default = false;
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-06 16:07:24 -04:00
|
|
|
# transparently forwarded from the test's `test` attribute for ease of access
|
|
|
|
|
name = mkOption {
|
|
|
|
|
description = "test name";
|
|
|
|
|
type = types.str;
|
|
|
|
|
internal = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
description = mkOption {
|
|
|
|
|
description = "test description";
|
|
|
|
|
type = types.str;
|
|
|
|
|
internal = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
|
description = "Whether to enable test";
|
|
|
|
|
type = types.bool;
|
|
|
|
|
internal = true;
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-05 21:25:34 +07:00
|
|
|
assertions = mkOption {
|
|
|
|
|
description = "Test result";
|
|
|
|
|
type = types.unspecified;
|
|
|
|
|
internal = true;
|
2021-05-13 17:27:08 -04:00
|
|
|
default = [ ];
|
2020-04-05 21:25:34 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
script = mkOption {
|
|
|
|
|
description = "Test script to use for e2e test";
|
|
|
|
|
type = types.nullOr (types.either types.lines types.path);
|
|
|
|
|
internal = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
|
{
|
|
|
|
|
inherit evaled;
|
2021-05-06 16:07:24 -04:00
|
|
|
inherit (testConfig) name description enable;
|
2020-04-05 21:25:34 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# if test is evaled check assertions
|
|
|
|
|
(mkIf (config.evaled != null) {
|
2021-05-06 16:07:24 -04:00
|
|
|
inherit (evaled.config.test) assertions script;
|
2020-04-05 21:25:34 +07:00
|
|
|
|
|
|
|
|
# if all assertions are true, test is successfull
|
|
|
|
|
success = all (el: el.assertion) config.assertions;
|
|
|
|
|
})
|
|
|
|
|
];
|
|
|
|
|
}
|