about summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authorAaron Andersen <aaron@fosslib.net>2018-11-10 17:37:22 -0500
committerAaron Andersen <aaron@fosslib.net>2018-11-10 20:54:10 -0500
commit24af0bc2b5293697695cb6d878b007130ab8db14 (patch)
tree9e887ea739f7f396fd791c7081e7466192612921 /nixos/tests
parentcf1ce60c2081a987a6a2646f9f5ddfe99affab30 (diff)
downloadnixlib-24af0bc2b5293697695cb6d878b007130ab8db14.tar
nixlib-24af0bc2b5293697695cb6d878b007130ab8db14.tar.gz
nixlib-24af0bc2b5293697695cb6d878b007130ab8db14.tar.bz2
nixlib-24af0bc2b5293697695cb6d878b007130ab8db14.tar.lz
nixlib-24af0bc2b5293697695cb6d878b007130ab8db14.tar.xz
nixlib-24af0bc2b5293697695cb6d878b007130ab8db14.tar.zst
nixlib-24af0bc2b5293697695cb6d878b007130ab8db14.zip
nixos/incron: added nixos test to ensure expected behaviour
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/incron.nix52
1 files changed, 52 insertions, 0 deletions
diff --git a/nixos/tests/incron.nix b/nixos/tests/incron.nix
new file mode 100644
index 000000000000..e39bbb5f096b
--- /dev/null
+++ b/nixos/tests/incron.nix
@@ -0,0 +1,52 @@
+import ./make-test.nix ({ pkgs, lib, ... }:
+
+{
+  name = "incron";
+  meta.maintainers = [ lib.maintainers.aanderse ];
+
+  machine =
+    { ... }:
+    { services.incron.enable = true;
+      services.incron.extraPackages = [ pkgs.coreutils ];
+      services.incron.systab = ''
+        /test IN_CREATE,IN_MODIFY,IN_CLOSE_WRITE,IN_MOVED_FROM,IN_MOVED_TO echo "$@/$# $%" >> /root/incron.log
+      '';
+
+      # ensure the directory to be monitored exists before incron is started
+      system.activationScripts.incronTest = ''
+        mkdir /test
+      '';
+    };
+
+  testScript = ''
+    startAll;
+
+    $machine->waitForUnit("multi-user.target");
+    $machine->waitForUnit("incron.service");
+
+    $machine->succeed("test -d /test");
+    # create some activity for incron to monitor
+    $machine->succeed("touch /test/file");
+    $machine->succeed("echo foo >> /test/file");
+    $machine->succeed("mv /test/file /root");
+    $machine->succeed("mv /root/file /test");
+
+    $machine->sleep(1);
+
+    # touch /test/file
+    $machine->succeed("grep '/test/file IN_CREATE' /root/incron.log");
+
+    # echo foo >> /test/file
+    $machine->succeed("grep '/test/file IN_MODIFY' /root/incron.log");
+    $machine->succeed("grep '/test/file IN_CLOSE_WRITE' /root/incron.log");
+
+    # mv /test/file /root
+    $machine->succeed("grep '/test/file IN_MOVED_FROM' /root/incron.log");
+
+    # mv /root/file /test
+    $machine->succeed("grep '/test/file IN_MOVED_TO' /root/incron.log");
+
+    # ensure something unexpected is not present
+    $machine->fail("grep 'IN_OPEN' /root/incron.log");
+  '';
+})