summaryrefslogtreecommitdiffstats
path: root/nixos/tests/nginx-njs.nix
blob: a64bbad08e104c66901b97c46bcbff24ba0c97df (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
{ pkgs, lib, ... }:
{
  name = "nginx-njs";

  nodes.machine =
    {
      config,
      lib,
      pkgs,
      ...
    }:
    {
      services.nginx = {
        enable = true;
        additionalModules = [ pkgs.nginxModules.njs ];
        commonHttpConfig = ''
          js_import http from ${builtins.toFile "http.js" ''
            function hello(r) {
                r.return(200, "Hello world!");
            }
            export default {hello};
          ''};
        '';
        virtualHosts."localhost".locations."/".extraConfig = ''
          js_content http.hello;
        '';
      };
    };
  testScript = ''
    machine.wait_for_unit("nginx")

    response = machine.wait_until_succeeds("curl -fvvv -s http://127.0.0.1/")
    assert "Hello world!" == response, f"Expected 'Hello world!', got '{response}'"
  '';
}