about summary refs log tree commit diff
path: root/lib/tests/modules
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-09-02 22:34:13 +0200
committerSilvan Mosberger <contact@infinisil.com>2020-11-30 23:51:23 +0100
commit3e39d6efdf65ce8fbf18471c0bb1062b28bfe984 (patch)
treeaa417ae5b9d29712d12d6c24c296ed6e980b08df /lib/tests/modules
parent900c4a5abd1061db2390224849cbc5eb8eb07059 (diff)
lib/tests: Add tests for module-builtin assertions
Diffstat (limited to 'lib/tests/modules')
-rw-r--r--lib/tests/modules/assertions/enable-false.nix8
-rw-r--r--lib/tests/modules/assertions/enable-lazy.nix17
-rw-r--r--lib/tests/modules/assertions/multi.nix23
-rw-r--r--lib/tests/modules/assertions/non-cascading.nix17
-rw-r--r--lib/tests/modules/assertions/simple.nix6
-rw-r--r--lib/tests/modules/assertions/submodule-attrsOf-attrsOf.nix13
-rw-r--r--lib/tests/modules/assertions/submodule-attrsOf.nix13
-rw-r--r--lib/tests/modules/assertions/submodule.nix13
-rw-r--r--lib/tests/modules/assertions/trigger-lazy.nix15
-rw-r--r--lib/tests/modules/assertions/trigger-submodule.nix18
-rw-r--r--lib/tests/modules/assertions/underscore-attributes.nix8
-rw-r--r--lib/tests/modules/assertions/warning.nix9
12 files changed, 160 insertions, 0 deletions
diff --git a/lib/tests/modules/assertions/enable-false.nix b/lib/tests/modules/assertions/enable-false.nix
new file mode 100644
index 0000000000000..13b9d99ac701f
--- /dev/null
+++ b/lib/tests/modules/assertions/enable-false.nix
@@ -0,0 +1,8 @@
+{
+
+  _module.assertions.test = {
+    enable = false;
+    message = "Assertion failed";
+  };
+
+}
diff --git a/lib/tests/modules/assertions/enable-lazy.nix b/lib/tests/modules/assertions/enable-lazy.nix
new file mode 100644
index 0000000000000..24b4d15fb8f7d
--- /dev/null
+++ b/lib/tests/modules/assertions/enable-lazy.nix
@@ -0,0 +1,17 @@
+{ lib, ... }: {
+
+  options.foo = lib.mkOption {
+    default = true;
+  };
+
+  options.bar = lib.mkOption {
+    default = true;
+  };
+
+  config._module.assertions.test = {
+    enable = throw "enable evaluated";
+    message = "Assertion failed";
+    triggerPath = [ "foo" ];
+  };
+
+}
diff --git a/lib/tests/modules/assertions/multi.nix b/lib/tests/modules/assertions/multi.nix
new file mode 100644
index 0000000000000..e2fe4ac1a2c5f
--- /dev/null
+++ b/lib/tests/modules/assertions/multi.nix
@@ -0,0 +1,23 @@
+{
+
+  _module.assertions = {
+    test1 = {
+      enable = true;
+      message = "Assertion 1 failed";
+    };
+    test2 = {
+      enable = true;
+      message = "Assertion 2 failed";
+    };
+    test3 = {
+      enable = true;
+      message = "Warning 3 failed";
+      type = "warning";
+    };
+    test4 = {
+      enable = true;
+      message = "Warning 4 failed";
+      type = "warning";
+    };
+  };
+}
diff --git a/lib/tests/modules/assertions/non-cascading.nix b/lib/tests/modules/assertions/non-cascading.nix
new file mode 100644
index 0000000000000..33ade1032a1f1
--- /dev/null
+++ b/lib/tests/modules/assertions/non-cascading.nix
@@ -0,0 +1,17 @@
+{ lib, config, ... }: {
+
+  options.foo = lib.mkOption {
+    default = true;
+  };
+
+  options.bar = lib.mkOption {
+    default = config.foo;
+  };
+
+  config._module.assertions.foo = {
+    enable = true;
+    message = "Foo assertion";
+    triggerPath = [ "foo" ];
+  };
+
+}
diff --git a/lib/tests/modules/assertions/simple.nix b/lib/tests/modules/assertions/simple.nix
new file mode 100644
index 0000000000000..c5128586ec3a6
--- /dev/null
+++ b/lib/tests/modules/assertions/simple.nix
@@ -0,0 +1,6 @@
+{
+  _module.assertions.test = {
+    enable = true;
+    message = "Assertion failed";
+  };
+}
diff --git a/lib/tests/modules/assertions/submodule-attrsOf-attrsOf.nix b/lib/tests/modules/assertions/submodule-attrsOf-attrsOf.nix
new file mode 100644
index 0000000000000..2c7db40dd5b31
--- /dev/null
+++ b/lib/tests/modules/assertions/submodule-attrsOf-attrsOf.nix
@@ -0,0 +1,13 @@
+{ lib, ... }: {
+
+  options.foo = lib.mkOption {
+    default = { bar.baz = {}; };
+    type = lib.types.attrsOf (lib.types.attrsOf (lib.types.submodule {
+      _module.assertions.test = {
+        enable = true;
+        message = "Assertion failed";
+      };
+    }));
+  };
+
+}
diff --git a/lib/tests/modules/assertions/submodule-attrsOf.nix b/lib/tests/modules/assertions/submodule-attrsOf.nix
new file mode 100644
index 0000000000000..78e106181d32a
--- /dev/null
+++ b/lib/tests/modules/assertions/submodule-attrsOf.nix
@@ -0,0 +1,13 @@
+{ lib, ... }: {
+
+  options.foo = lib.mkOption {
+    default = { bar = {}; };
+    type = lib.types.attrsOf (lib.types.submodule {
+      _module.assertions.test = {
+        enable = true;
+        message = "Assertion failed";
+      };
+    });
+  };
+
+}
diff --git a/lib/tests/modules/assertions/submodule.nix b/lib/tests/modules/assertions/submodule.nix
new file mode 100644
index 0000000000000..292593816d67a
--- /dev/null
+++ b/lib/tests/modules/assertions/submodule.nix
@@ -0,0 +1,13 @@
+{ lib, ... }: {
+
+  options.foo = lib.mkOption {
+    default = {};
+    type = lib.types.submodule {
+      _module.assertions.test = {
+        enable = true;
+        message = "Assertion failed";
+      };
+    };
+  };
+
+}
diff --git a/lib/tests/modules/assertions/trigger-lazy.nix b/lib/tests/modules/assertions/trigger-lazy.nix
new file mode 100644
index 0000000000000..812a9ffad07e2
--- /dev/null
+++ b/lib/tests/modules/assertions/trigger-lazy.nix
@@ -0,0 +1,15 @@
+{ lib, ... }: {
+  options.foo = lib.mkOption {
+    default = true;
+  };
+
+  options.bar = lib.mkOption {
+    default = true;
+  };
+
+  config._module.assertions.test = {
+    enable = true;
+    message = "Assertion failed";
+    triggerPath = [ "foo" ];
+  };
+}
diff --git a/lib/tests/modules/assertions/trigger-submodule.nix b/lib/tests/modules/assertions/trigger-submodule.nix
new file mode 100644
index 0000000000000..b5c7821f00f53
--- /dev/null
+++ b/lib/tests/modules/assertions/trigger-submodule.nix
@@ -0,0 +1,18 @@
+{ lib, ... }: {
+
+  options.foo = lib.mkOption {
+    default = { bar = {}; };
+    type = lib.types.attrsOf (lib.types.submodule {
+      options.baz = lib.mkOption {
+        default = true;
+      };
+    });
+  };
+
+  config._module.assertions.test = {
+    enable = true;
+    message = "Assertion failed";
+    triggerPath = [ "foo" "bar" "baz" ];
+  };
+
+}
diff --git a/lib/tests/modules/assertions/underscore-attributes.nix b/lib/tests/modules/assertions/underscore-attributes.nix
new file mode 100644
index 0000000000000..a485cd2e1bd96
--- /dev/null
+++ b/lib/tests/modules/assertions/underscore-attributes.nix
@@ -0,0 +1,8 @@
+{
+
+  _module.assertions._test = {
+    enable = true;
+    message = "Assertion failed";
+  };
+
+}
diff --git a/lib/tests/modules/assertions/warning.nix b/lib/tests/modules/assertions/warning.nix
new file mode 100644
index 0000000000000..6c1dd2c750e63
--- /dev/null
+++ b/lib/tests/modules/assertions/warning.nix
@@ -0,0 +1,9 @@
+{
+
+  _module.assertions.test = {
+    enable = true;
+    type = "warning";
+    message = "Warning message";
+  };
+
+}