2020-04-24 23:36:52 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, ... }: {
|
|
|
|
name = "caddy";
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2020-11-19 00:13:47 +00:00
|
|
|
maintainers = [ xfix Br1ght0ne ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
webserver = { pkgs, lib, ... }: {
|
|
|
|
services.caddy.enable = true;
|
2022-03-30 09:31:56 +00:00
|
|
|
services.caddy.extraConfig = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
http://localhost {
|
2020-09-25 04:45:31 +00:00
|
|
|
encode gzip
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
file_server
|
|
|
|
root * ${
|
2020-04-24 23:36:52 +00:00
|
|
|
pkgs.runCommand "testdir" {} ''
|
|
|
|
mkdir "$out"
|
|
|
|
echo hello world > "$out/example.html"
|
|
|
|
''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
2023-07-15 17:15:38 +00:00
|
|
|
services.caddy.enableReload = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
specialisation.config-reload.configuration = {
|
2022-03-30 09:31:56 +00:00
|
|
|
services.caddy.extraConfig = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
http://localhost:8080 {
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2021-08-22 07:53:02 +00:00
|
|
|
specialisation.multiple-configs.configuration = {
|
|
|
|
services.caddy.virtualHosts = {
|
|
|
|
"http://localhost:8080" = { };
|
|
|
|
"http://localhost:8081" = { };
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-09-18 10:52:07 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
testScript = { nodes, ... }:
|
|
|
|
let
|
2023-07-15 17:15:38 +00:00
|
|
|
justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload";
|
|
|
|
multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs";
|
2021-09-18 10:52:07 +00:00
|
|
|
in
|
|
|
|
''
|
|
|
|
url = "http://localhost/example.html"
|
|
|
|
webserver.wait_for_unit("caddy")
|
2022-06-16 17:23:12 +00:00
|
|
|
webserver.wait_for_open_port(80)
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
with subtest("config is reloaded on nixos-rebuild switch"):
|
|
|
|
webserver.succeed(
|
|
|
|
"${justReloadSystem}/bin/switch-to-configuration test >&2"
|
|
|
|
)
|
2022-06-16 17:23:12 +00:00
|
|
|
webserver.wait_for_open_port(8080)
|
2023-07-15 17:15:38 +00:00
|
|
|
webserver.fail("journalctl -u caddy | grep -q -i stopped")
|
|
|
|
webserver.succeed("journalctl -u caddy | grep -q -i reloaded")
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
with subtest("multiple configs are correctly merged"):
|
|
|
|
webserver.succeed(
|
|
|
|
"${multipleConfigs}/bin/switch-to-configuration test >&2"
|
|
|
|
)
|
2022-06-16 17:23:12 +00:00
|
|
|
webserver.wait_for_open_port(8080)
|
|
|
|
webserver.wait_for_open_port(8081)
|
2021-09-18 10:52:07 +00:00
|
|
|
'';
|
|
|
|
})
|