nixpkgs/nixos/tests/caddy.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.9 KiB
Nix
Raw Normal View History

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