1import ./make-test-python.nix ({ pkgs, ... }: {
2 name = "caddy";
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ xfix Br1ght0ne ];
5 };
6
7 nodes = {
8 webserver = { pkgs, lib, ... }: {
9 services.caddy.enable = true;
10 services.caddy.extraConfig = ''
11 http://localhost {
12 encode gzip
13
14 file_server
15 root * ${
16 pkgs.runCommand "testdir" {} ''
17 mkdir "$out"
18 echo hello world > "$out/example.html"
19 ''
20 }
21 }
22 '';
23 services.caddy.enableReload = true;
24
25 specialisation.config-reload.configuration = {
26 services.caddy.extraConfig = ''
27 http://localhost:8080 {
28 }
29 '';
30 };
31 specialisation.multiple-configs.configuration = {
32 services.caddy.virtualHosts = {
33 "http://localhost:8080" = { };
34 "http://localhost:8081" = { };
35 };
36 };
37 specialisation.rfc42.configuration = {
38 services.caddy.settings = {
39 apps.http.servers.default = {
40 listen = [ ":80" ];
41 routes = [{
42 handle = [{
43 body = "hello world";
44 handler = "static_response";
45 status_code = 200;
46 }];
47 }];
48 };
49 };
50 };
51 };
52 };
53
54 testScript = { nodes, ... }:
55 let
56 justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload";
57 multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs";
58 rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42";
59 in
60 ''
61 url = "http://localhost/example.html"
62 webserver.wait_for_unit("caddy")
63 webserver.wait_for_open_port(80)
64
65
66 with subtest("config is reloaded on nixos-rebuild switch"):
67 webserver.succeed(
68 "${justReloadSystem}/bin/switch-to-configuration test >&2"
69 )
70 webserver.wait_for_open_port(8080)
71 webserver.fail("journalctl -u caddy | grep -q -i stopped")
72 webserver.succeed("journalctl -u caddy | grep -q -i reloaded")
73
74 with subtest("multiple configs are correctly merged"):
75 webserver.succeed(
76 "${multipleConfigs}/bin/switch-to-configuration test >&2"
77 )
78 webserver.wait_for_open_port(8080)
79 webserver.wait_for_open_port(8081)
80
81 with subtest("rfc42 settings config"):
82 webserver.succeed(
83 "${rfc42Config}/bin/switch-to-configuration test >&2"
84 )
85 webserver.wait_for_open_port(80)
86 webserver.succeed("curl http://localhost | grep hello")
87 '';
88})