diff --git a/test/default.nix b/test/default.nix index b755c79..a79711c 100644 --- a/test/default.nix +++ b/test/default.nix @@ -1,17 +1,24 @@ { pkgs ? import {} , kubenix ? import ../. {inherit pkgs;} , lib ? kubenix.lib +, k8sVersions ? ["1.7" "1.8" "1.9" "1.10" "1.11" "1.12" "1.13"] # whether any testing error should throw an error , throwError ? true }: with lib; -(evalModules { +listToAttrs (map (version: let + version' = replaceStrings ["."] ["_"] version; +in nameValuePair "v${version'}" (evalModules { modules = [ ./modules/testing.nix { + imports = [kubenix.k8s kubenix.submodules]; + + kubernetes.version = version; + testing.throwError = throwError; testing.tests = [ ./k8s/simple.nix @@ -20,6 +27,10 @@ with lib; ./k8s/1.13/crd.nix ./submodules/simple.nix ]; + testing.defaults = ({kubenix, ...}: { + imports = [kubenix.k8s]; + kubernetes.version = version; + }); } ]; args = { @@ -28,4 +39,4 @@ with lib; specialArgs = { inherit kubenix; }; -}).config.testing.result +}).config.testing.result) k8sVersions) diff --git a/test/k8s/crd.nix b/test/k8s/crd.nix index 98d257d..1b12f1a 100644 --- a/test/k8s/crd.nix +++ b/test/k8s/crd.nix @@ -12,6 +12,7 @@ in { test = { name = "k8s/crd"; description = "Simple test tesing CRD"; + enable = builtins.compareVersions config.kubernetes.version "1.8" >= 0; assertions = [{ message = "should have group set"; assertion = cfg.spec.group == "stable.example.com"; diff --git a/test/modules/testing.nix b/test/modules/testing.nix index d3ed02d..88fb5ff 100644 --- a/test/modules/testing.nix +++ b/test/modules/testing.nix @@ -4,6 +4,7 @@ with lib; let cfg = config.testing; + parentConfig = config; in { options = { testing.throwError = mkOption { @@ -12,13 +13,22 @@ in { default = true; }; + testing.defaults = mkOption { + description = "Testing defaults"; + type = types.coercedTo types.unspecified (value: [value]) (types.listOf types.unspecified); + example = literalExample ''{config, ...}: { + kubernetes.version = config.kubernetes.version; + }''; + default = []; + }; + testing.tests = mkOption { description = "Attribute set of test cases"; default = []; type = types.listOf (types.coercedTo types.path (module: {inherit module;}) (types.submodule ({config, ...}: let modules = [config.module ./test.nix { config._module.args.test = config; - }]; + }] ++ cfg.defaults; test = (kubenix.evalKubernetesModules { check = false;