1 import ./make-test-python.nix ({ pkgs, ... }: {
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ xfix Br1ght0ne ];
8 webserver = { pkgs, lib, ... }: {
9 services.caddy.enable = true;
10 services.caddy.extraConfig = ''
16 pkgs.runCommand "testdir" {} ''
18 echo hello world > "$out/example.html"
24 specialisation.etag.configuration = {
25 services.caddy.extraConfig = lib.mkForce ''
31 pkgs.runCommand "testdir2" {} ''
33 echo changed > "$out/example.html"
40 specialisation.config-reload.configuration = {
41 services.caddy.extraConfig = ''
42 http://localhost:8080 {
46 specialisation.multiple-configs.configuration = {
47 services.caddy.virtualHosts = {
48 "http://localhost:8080" = { };
49 "http://localhost:8081" = { };
55 testScript = { nodes, ... }:
57 etagSystem = "${nodes.webserver.config.system.build.toplevel}/specialisation/etag";
58 justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/specialisation/config-reload";
59 multipleConfigs = "${nodes.webserver.config.system.build.toplevel}/specialisation/multiple-configs";
62 url = "http://localhost/example.html"
63 webserver.wait_for_unit("caddy")
64 webserver.wait_for_open_port(80)
68 etag = webserver.succeed(
69 "curl --fail -v '{}' 2>&1 | sed -n -e \"s/^< [Ee][Tt][Aa][Gg]: *//p\"".format(
73 etag = etag.replace("\r\n", " ")
74 http_code = webserver.succeed(
75 "curl --fail --silent --show-error -o /dev/null -w \"%{{http_code}}\" --head -H 'If-None-Match: {}' {}".format(
79 assert int(http_code) == 304, "HTTP code is {}, expected 304".format(http_code)
83 with subtest("check ETag if serving Nix store paths"):
84 old_etag = check_etag(url)
86 "${etagSystem}/bin/switch-to-configuration test >&2"
89 new_etag = check_etag(url)
90 assert old_etag != new_etag, "Old ETag {} is the same as {}".format(
94 with subtest("config is reloaded on nixos-rebuild switch"):
96 "${justReloadSystem}/bin/switch-to-configuration test >&2"
98 webserver.wait_for_open_port(8080)
100 with subtest("multiple configs are correctly merged"):
102 "${multipleConfigs}/bin/switch-to-configuration test >&2"
104 webserver.wait_for_open_port(8080)
105 webserver.wait_for_open_port(8081)