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

  meta = with pkgs.lib.maintainers; {
    maintainers = [ sgo ];
  };

  nodes.machine = { config, lib, pkgs, ... }: {
    services.httpd = {
      enable = true;
      adminAddr = "admin@localhost";
      virtualHosts."modperl" =
        let
          inc = pkgs.writeTextDir "ModPerlTest.pm" ''
            package ModPerlTest;
            use strict;
            use Apache2::RequestRec ();
            use Apache2::RequestIO ();
            use Apache2::Const -compile => qw(OK);
            sub handler {
              my $r = shift;
              $r->content_type('text/plain');
              print "Hello mod_perl!\n";
              return Apache2::Const::OK;
            }
            1;
          '';
          startup = pkgs.writeScript "startup.pl" ''
            use lib "${inc}",
              split ":","${with pkgs.perl.pkgs; makeFullPerlPath ([ mod_perl2 ])}";
            1;
          '';
        in
        {
          extraConfig = ''
            PerlRequire ${startup}
          '';
          locations."/modperl" = {
            extraConfig = ''
              SetHandler perl-script
              PerlResponseHandler ModPerlTest
            '';
          };
        };
      enablePerl = true;
    };
  };
  testScript = { ... }: ''
    machine.wait_for_unit("httpd.service")
    response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/modperl")
    assert "Hello mod_perl!" in response, "/modperl handler did not respond"
  '';
})