From c1b84f3192ff6d0f057bc6645498a4b44572d1c4 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Wed, 13 Feb 2019 17:03:27 +0100 Subject: [PATCH] feat(test): support for enabling and disabling tests --- test/modules/test.nix | 6 ++++++ test/modules/testing.nix | 30 ++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/test/modules/test.nix b/test/modules/test.nix index 1b54d97..6235abe 100644 --- a/test/modules/test.nix +++ b/test/modules/test.nix @@ -14,6 +14,12 @@ with lib; type = types.str; }; + enable = mkOption { + description = "Whether to enable test"; + type = types.bool; + default = true; + }; + assertions = mkOption { type = types.listOf (types.submodule { options = { diff --git a/test/modules/testing.nix b/test/modules/testing.nix index 91e3cfd..d3ed02d 100644 --- a/test/modules/testing.nix +++ b/test/modules/testing.nix @@ -25,16 +25,14 @@ in { inherit modules; }).config.test; - evaled = builtins.trace "testing ${test.name}" (kubenix.evalKubernetesModules { - inherit modules; - }); + evaled = + if test.enable + then builtins.trace "testing ${test.name}" (kubenix.evalKubernetesModules { + inherit modules; + }) + else {success = false;}; in { options = { - module = mkOption { - description = "Module defining submodule"; - type = types.unspecified; - }; - name = mkOption { description = "test name"; type = types.str; @@ -47,6 +45,17 @@ in { 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 { description = "Wheter test was evaled"; type = types.bool; @@ -73,11 +82,12 @@ in { }; config = { - inherit (test) name description; + inherit (test) name description enable; assertions = mkIf config.evaled evaled.config.test.assertions; success = mkIf config.evaled (all (el: el.assertion) config.assertions); }; }))); + apply = tests: filter (test: test.enable) tests; }; testing.success = mkOption { @@ -94,7 +104,7 @@ in { tests = map (test: { inherit (test) name description evaled success; assertions = moduleToAttrs test.assertions; - }) cfg.tests; + }) (filter (test: test.enable) cfg.tests); }); }; };