about summary refs log tree commit diff
path: root/nixos/tests/incron.nix
blob: d016360ba0ef812711bad53a529f79259f04ea8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import ./make-test-python.nix ({ pkgs, lib, ... }:

{
  name = "incron";
  meta.maintainers = [ lib.maintainers.aanderse ];

  nodes.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
      systemd.tmpfiles.settings.incron-test = {
        "/test".d = { };
      };
    };

  testScript = ''
    start_all()

    machine.wait_for_unit("multi-user.target")
    machine.wait_for_unit("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")
  '';
})