summary refs log tree commit diff
path: root/nixos/tests/fluentd.nix
blob: e5c4c3d2163190cd09e23500fb637fd2af4c23dd (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
import ./make-test.nix ({ pkgs, lib, ... }: {
  name = "fluentd";

  machine = { pkgs, ... }: {
    services.fluentd = {
      enable = true;
      config = ''
        <source>
          @type http
          port 9880
        </source>

        <match **>
          type copy
          <store>
            @type file
            format json
            path /tmp/fluentd
            symlink_path /tmp/current-log
          </store>
          <store>
            @type stdout
          </store>
        </match>
      '';
    };
  };

  testScript = let
    testMessage = "an example log message";

    payload = pkgs.writeText "test-message.json" (builtins.toJSON {
      inherit testMessage;
    });
  in ''
    $machine->start;
    $machine->waitForUnit('fluentd.service');
    $machine->waitForOpenPort(9880);

    $machine->succeed("curl -fsSL -X POST -H 'Content-type: application/json' -d @${payload} http://localhost:9880/test.tag");

    $machine->succeed("systemctl stop fluentd"); # blocking flush

    $machine->succeed("grep '${testMessage}' /tmp/current-log");
  '';
})