summaryrefslogtreecommitdiffstats
path: root/nixos/tests/web-servers/unit-perl.nix
blob: 157e989c8bd1dc0461baee3769b34d94b0b88c0d (plain)
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
{ pkgs, ... }:
let
  testdir = pkgs.writeTextDir "www/app.psgi" ''
    my $app = sub {
        return [
            "200",
            [ "Content-Type" => "text/plain" ],
            [ "Hello, Perl on Unit!" ],
        ];
    };
  '';

in
{
  name = "unit-perl-test";
  meta.maintainers = with pkgs.lib.maintainers; [ sgo ];

  nodes.machine =
    {
      config,
      lib,
      pkgs,
      ...
    }:
    {
      services.unit = {
        enable = true;
        config = pkgs.lib.strings.toJSON {
          listeners."*:8080".application = "perl";
          applications.perl = {
            type = "perl";
            script = "${testdir}/www/app.psgi";
          };
        };
      };
    };
  testScript = ''
    machine.wait_for_unit("unit.service")
    machine.wait_for_open_port(8080)

    response = machine.succeed("curl -f -vvv -s http://127.0.0.1:8080/")
    assert "Hello, Perl on Unit!" in response, "Hello world"
  '';
}