From e9dbb01005241947816ec9db651c60dd17055698 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Thu, 10 Oct 2019 13:01:19 +0200 Subject: [PATCH] feat(submodules): add test for submodule passthru --- tests/default.nix | 1 + tests/submodules/passthru.nix | 59 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/submodules/passthru.nix diff --git a/tests/default.nix b/tests/default.nix index b097332..92c2776 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -37,6 +37,7 @@ let ./submodules/defaults.nix ./submodules/versioning.nix ./submodules/exports.nix + ./submodules/passthru.nix ]; testing.args = { inherit images k8sVersion; diff --git a/tests/submodules/passthru.nix b/tests/submodules/passthru.nix new file mode 100644 index 0000000..c529b81 --- /dev/null +++ b/tests/submodules/passthru.nix @@ -0,0 +1,59 @@ +{ name, config, lib, kubenix, ... }: + +with lib; + +let + submodule = { name, ... }: { + imports = [ kubenix.modules.submodule ]; + + config.submodule = { + name = "subm"; + passthru.global.${name} = "true"; + }; + }; +in { + imports = with kubenix.modules; [ test submodules ]; + + options = { + global = mkOption { + description = "Global value"; + type = types.attrs; + default = {}; + }; + }; + + config = { + test = { + name = "submodules-passthru"; + description = "Submodules passthru test"; + assertions = [{ + message = "should passthru values if passthru enabled"; + assertion = hasAttr "inst1" config.global && config.global.inst1 == "true"; + } { + message = "should not passthru values if passthru not enabled"; + assertion = !(hasAttr "inst2" config.global); + } { + message = "should passthru by default"; + assertion = hasAttr "inst3" config.global && config.global.inst3 == "true"; + }]; + }; + + submodules.imports = [{ + modules = [submodule]; + }]; + + submodules.instances.inst1 = { + submodule = "subm"; + passthru.enable = true; + }; + + submodules.instances.inst2 = { + submodule = "subm"; + passthru.enable = false; + }; + + submodules.instances.inst3 = { + submodule = "subm"; + }; + }; +}