1import ../make-test-python.nix ({ pkgs, lib, ... } : {
2 name = "static-web-server";
3 meta = {
4 maintainers = with lib.maintainers; [ mac-chaffee ];
5 };
6
7 nodes.machine = { pkgs, ... }: {
8 services.static-web-server = {
9 enable = true;
10 listen = "[::]:8080";
11 root = toString (pkgs.writeTextDir "nixos-test.html" ''
12 <h1>Hello NixOS!</h1>
13 '');
14 configuration = {
15 general = { directory-listing = true; };
16 };
17 };
18 };
19
20 testScript = ''
21 machine.start()
22 machine.wait_for_unit("static-web-server.socket")
23 machine.wait_for_open_port(8080)
24 # We don't use wait_until_succeeds() because we're testing socket
25 # activation which better work on the first request
26 response = machine.succeed("curl -fsS localhost:8080")
27 assert "nixos-test.html" in response, "The directory listing page did not include a link to our nixos-test.html file"
28 response = machine.succeed("curl -fsS localhost:8080/nixos-test.html")
29 assert "Hello NixOS!" in response
30 machine.wait_for_unit("static-web-server.service")
31 '';
32})