summaryrefslogtreecommitdiffstats
path: root/nixos/tests/web-servers/static-web-server.nix
blob: 0727b5cba021d110187d6bdf3045040259808d87 (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
{ pkgs, lib, ... }:
{
  name = "static-web-server";
  meta = {
    maintainers = with lib.maintainers; [ mac-chaffee ];
  };

  nodes.machine =
    { pkgs, ... }:
    {
      services.static-web-server = {
        enable = true;
        listen = "[::]:8080";
        root = toString (
          pkgs.writeTextDir "nixos-test.html" ''
            <h1>Hello NixOS!</h1>
          ''
        );
        configuration = {
          general = {
            directory-listing = true;
          };
        };
      };
    };

  testScript = ''
    machine.start()
    machine.wait_for_unit("static-web-server.socket")
    machine.wait_for_open_port(8080)
    # We don't use wait_until_succeeds() because we're testing socket
    # activation which better work on the first request
    response = machine.succeed("curl -fsS localhost:8080")
    assert "nixos-test.html" in response, "The directory listing page did not include a link to our nixos-test.html file"
    response = machine.succeed("curl -fsS localhost:8080/nixos-test.html")
    assert "Hello NixOS!" in response
    machine.wait_for_unit("static-web-server.service")
  '';
}