1import ./make-test-python.nix ({ pkgs, lib, ... }:
2
3{
4 name = "incron";
5 meta.maintainers = [ lib.maintainers.aanderse ];
6
7 nodes.machine =
8 { ... }:
9 { services.incron.enable = true;
10 services.incron.extraPackages = [ pkgs.coreutils ];
11 services.incron.systab = ''
12 /test IN_CREATE,IN_MODIFY,IN_CLOSE_WRITE,IN_MOVED_FROM,IN_MOVED_TO echo "$@/$# $%" >> /root/incron.log
13 '';
14
15 # ensure the directory to be monitored exists before incron is started
16 system.activationScripts.incronTest = ''
17 mkdir /test
18 '';
19 };
20
21 testScript = ''
22 start_all()
23
24 machine.wait_for_unit("multi-user.target")
25 machine.wait_for_unit("incron.service")
26
27 machine.succeed("test -d /test")
28 # create some activity for incron to monitor
29 machine.succeed("touch /test/file")
30 machine.succeed("echo foo >> /test/file")
31 machine.succeed("mv /test/file /root")
32 machine.succeed("mv /root/file /test")
33
34 machine.sleep(1)
35
36 # touch /test/file
37 machine.succeed("grep '/test/file IN_CREATE' /root/incron.log")
38
39 # echo foo >> /test/file
40 machine.succeed("grep '/test/file IN_MODIFY' /root/incron.log")
41 machine.succeed("grep '/test/file IN_CLOSE_WRITE' /root/incron.log")
42
43 # mv /test/file /root
44 machine.succeed("grep '/test/file IN_MOVED_FROM' /root/incron.log")
45
46 # mv /root/file /test
47 machine.succeed("grep '/test/file IN_MOVED_TO' /root/incron.log")
48
49 # ensure something unexpected is not present
50 machine.fail("grep 'IN_OPEN' /root/incron.log")
51 '';
52})