about summary refs log tree commit diff
path: root/nixpkgs/nixos/tests/web-servers/static-web-server.nix
blob: da1a9bdec5d25714824911444cbfe80b45c44c2c (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
import ../make-test-python.nix ({ 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")
  '';
})