nixosTests.caddy: migrate to runTest (#395444)

This commit is contained in:
Gaétan Lepage 2025-04-02 17:37:22 +02:00 committed by GitHub
commit b1ab0f8dc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 135 additions and 137 deletions

View file

@ -270,7 +270,7 @@ in
buildbot = runTest ./buildbot.nix; buildbot = runTest ./buildbot.nix;
buildkite-agents = handleTest ./buildkite-agents.nix { }; buildkite-agents = handleTest ./buildkite-agents.nix { };
c2fmzq = handleTest ./c2fmzq.nix { }; c2fmzq = handleTest ./c2fmzq.nix { };
caddy = handleTest ./caddy.nix { }; caddy = runTest ./caddy.nix;
cadvisor = handleTestOn [ "x86_64-linux" ] ./cadvisor.nix { }; cadvisor = handleTestOn [ "x86_64-linux" ] ./cadvisor.nix { };
cage = handleTest ./cage.nix { }; cage = handleTest ./cage.nix { };
cagebreak = handleTest ./cagebreak.nix { }; cagebreak = handleTest ./cagebreak.nix { };

View file

@ -1,155 +1,153 @@
import ./make-test-python.nix ( { pkgs, ... }:
{ pkgs, ... }: {
{ name = "caddy";
name = "caddy"; meta = with pkgs.lib.maintainers; {
meta = with pkgs.lib.maintainers; { maintainers = [
maintainers = [ Br1ght0ne
Br1ght0ne stepbrobd
stepbrobd ];
]; };
};
nodes = { nodes = {
webserver = webserver =
{ pkgs, ... }: { pkgs, ... }:
{ {
services.caddy.enable = true; services.caddy.enable = true;
services.caddy.extraConfig = ''
http://localhost {
encode gzip
file_server
root * ${
pkgs.runCommand "testdir" { } ''
mkdir "$out"
echo hello world > "$out/example.html"
''
}
}
'';
services.caddy.enableReload = true;
specialisation.config-reload.configuration = {
services.caddy.extraConfig = '' services.caddy.extraConfig = ''
http://localhost { http://localhost:8080 {
encode gzip
file_server
root * ${
pkgs.runCommand "testdir" { } ''
mkdir "$out"
echo hello world > "$out/example.html"
''
}
} }
''; '';
services.caddy.enableReload = true; };
specialisation.multiple-configs.configuration = {
specialisation.config-reload.configuration = { services.caddy.virtualHosts = {
services.caddy.extraConfig = '' "http://localhost:8080" = { };
http://localhost:8080 { "http://localhost:8081" = { };
}
'';
}; };
specialisation.multiple-configs.configuration = { };
services.caddy.virtualHosts = { specialisation.multiple-hostnames.configuration = {
"http://localhost:8080" = { }; services.caddy.virtualHosts = {
"http://localhost:8081" = { }; "http://localhost:8080 http://localhost:8081" = { };
};
}; };
specialisation.multiple-hostnames.configuration = { };
services.caddy.virtualHosts = { specialisation.rfc42.configuration = {
"http://localhost:8080 http://localhost:8081" = { }; services.caddy.settings = {
}; apps.http.servers.default = {
}; listen = [ ":80" ];
specialisation.rfc42.configuration = { routes = [
services.caddy.settings = {
apps.http.servers.default = {
listen = [ ":80" ];
routes = [
{
handle = [
{
body = "hello world";
handler = "static_response";
status_code = 200;
}
];
}
];
};
};
};
specialisation.explicit-config-file.configuration = {
services.caddy.configFile = pkgs.writeText "Caddyfile" ''
localhost:80
respond "hello world"
'';
};
specialisation.with-plugins.configuration = {
services.caddy = {
package = pkgs.caddy.withPlugins {
plugins = [ "github.com/caddyserver/replace-response@v0.0.0-20241211194404-3865845790a7" ];
hash = "sha256-WPmJPnyOrAnuJxvn3ywswqvLGV8SZzzn3gU1Tbtpao4=";
};
configFile = pkgs.writeText "Caddyfile" ''
{ {
order replace after encode handle = [
{
body = "hello world";
handler = "static_response";
status_code = 200;
}
];
} }
];
localhost:80 {
respond "hello world"
replace world caddy
}
'';
}; };
}; };
}; };
}; specialisation.explicit-config-file.configuration = {
services.caddy.configFile = pkgs.writeText "Caddyfile" ''
localhost:80
testScript = respond "hello world"
{ nodes, ... }: '';
let };
explicitConfigFile = "${nodes.webserver.system.build.toplevel}/specialisation/explicit-config-file"; specialisation.with-plugins.configuration = {
justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload"; services.caddy = {
multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs"; package = pkgs.caddy.withPlugins {
multipleHostnames = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-hostnames"; plugins = [ "github.com/caddyserver/replace-response@v0.0.0-20241211194404-3865845790a7" ];
rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42"; hash = "sha256-WPmJPnyOrAnuJxvn3ywswqvLGV8SZzzn3gU1Tbtpao4=";
withPluginsConfig = "${nodes.webserver.system.build.toplevel}/specialisation/with-plugins"; };
in configFile = pkgs.writeText "Caddyfile" ''
'' {
url = "http://localhost/example.html" order replace after encode
webserver.wait_for_unit("caddy") }
webserver.wait_for_open_port(80)
localhost:80 {
respond "hello world"
replace world caddy
}
'';
};
};
};
};
testScript =
{ nodes, ... }:
let
explicitConfigFile = "${nodes.webserver.system.build.toplevel}/specialisation/explicit-config-file";
justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload";
multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs";
multipleHostnames = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-hostnames";
rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42";
withPluginsConfig = "${nodes.webserver.system.build.toplevel}/specialisation/with-plugins";
in
''
url = "http://localhost/example.html"
webserver.wait_for_unit("caddy")
webserver.wait_for_open_port(80)
with subtest("config is reloaded on nixos-rebuild switch"): with subtest("config is reloaded on nixos-rebuild switch"):
webserver.succeed( webserver.succeed(
"${justReloadSystem}/bin/switch-to-configuration test >&2" "${justReloadSystem}/bin/switch-to-configuration test >&2"
) )
webserver.wait_for_open_port(8080) webserver.wait_for_open_port(8080)
webserver.fail("journalctl -u caddy | grep -q -i stopped") webserver.fail("journalctl -u caddy | grep -q -i stopped")
webserver.succeed("journalctl -u caddy | grep -q -i reloaded") webserver.succeed("journalctl -u caddy | grep -q -i reloaded")
with subtest("multiple configs are correctly merged"): with subtest("multiple configs are correctly merged"):
webserver.succeed( webserver.succeed(
"${multipleConfigs}/bin/switch-to-configuration test >&2" "${multipleConfigs}/bin/switch-to-configuration test >&2"
) )
webserver.wait_for_open_port(8080) webserver.wait_for_open_port(8080)
webserver.wait_for_open_port(8081) webserver.wait_for_open_port(8081)
with subtest("a virtual host with multiple hostnames works"): with subtest("a virtual host with multiple hostnames works"):
webserver.succeed( webserver.succeed(
"${multipleHostnames}/bin/switch-to-configuration test >&2" "${multipleHostnames}/bin/switch-to-configuration test >&2"
) )
webserver.wait_for_open_port(8080) webserver.wait_for_open_port(8080)
webserver.wait_for_open_port(8081) webserver.wait_for_open_port(8081)
with subtest("rfc42 settings config"): with subtest("rfc42 settings config"):
webserver.succeed( webserver.succeed(
"${rfc42Config}/bin/switch-to-configuration test >&2" "${rfc42Config}/bin/switch-to-configuration test >&2"
) )
webserver.wait_for_open_port(80) webserver.wait_for_open_port(80)
webserver.succeed("curl http://localhost | grep hello") webserver.succeed("curl http://localhost | grep hello")
with subtest("explicit configFile"): with subtest("explicit configFile"):
webserver.succeed( webserver.succeed(
"${explicitConfigFile}/bin/switch-to-configuration test >&2" "${explicitConfigFile}/bin/switch-to-configuration test >&2"
) )
webserver.wait_for_open_port(80) webserver.wait_for_open_port(80)
webserver.succeed("curl http://localhost | grep hello") webserver.succeed("curl http://localhost | grep hello")
with subtest("plugins are correctled installed and configurable"): with subtest("plugins are correctled installed and configurable"):
webserver.succeed( webserver.succeed(
"${withPluginsConfig}/bin/switch-to-configuration test >&2" "${withPluginsConfig}/bin/switch-to-configuration test >&2"
) )
webserver.wait_for_open_port(80) webserver.wait_for_open_port(80)
webserver.succeed("curl http://localhost | grep caddy") webserver.succeed("curl http://localhost | grep caddy")
''; '';
} }
)