at 24.11-pre 3.3 kB view raw
1import ./make-test-python.nix ({ pkgs, ... }: { 2 name = "caddy"; 3 meta = with pkgs.lib.maintainers; { 4 maintainers = [ 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 specialisation.explicit-config-file.configuration = { 52 services.caddy.configFile = pkgs.writeText "Caddyfile" '' 53 localhost:80 54 55 respond "hello world" 56 ''; 57 }; 58 }; 59 }; 60 61 testScript = { nodes, ... }: 62 let 63 explicitConfigFile = "${nodes.webserver.system.build.toplevel}/specialisation/explicit-config-file"; 64 justReloadSystem = "${nodes.webserver.system.build.toplevel}/specialisation/config-reload"; 65 multipleConfigs = "${nodes.webserver.system.build.toplevel}/specialisation/multiple-configs"; 66 rfc42Config = "${nodes.webserver.system.build.toplevel}/specialisation/rfc42"; 67 in 68 '' 69 url = "http://localhost/example.html" 70 webserver.wait_for_unit("caddy") 71 webserver.wait_for_open_port(80) 72 73 74 with subtest("config is reloaded on nixos-rebuild switch"): 75 webserver.succeed( 76 "${justReloadSystem}/bin/switch-to-configuration test >&2" 77 ) 78 webserver.wait_for_open_port(8080) 79 webserver.fail("journalctl -u caddy | grep -q -i stopped") 80 webserver.succeed("journalctl -u caddy | grep -q -i reloaded") 81 82 with subtest("multiple configs are correctly merged"): 83 webserver.succeed( 84 "${multipleConfigs}/bin/switch-to-configuration test >&2" 85 ) 86 webserver.wait_for_open_port(8080) 87 webserver.wait_for_open_port(8081) 88 89 with subtest("rfc42 settings config"): 90 webserver.succeed( 91 "${rfc42Config}/bin/switch-to-configuration test >&2" 92 ) 93 webserver.wait_for_open_port(80) 94 webserver.succeed("curl http://localhost | grep hello") 95 96 with subtest("explicit configFile"): 97 webserver.succeed( 98 "${explicitConfigFile}/bin/switch-to-configuration test >&2" 99 ) 100 webserver.wait_for_open_port(80) 101 webserver.succeed("curl http://localhost | grep hello") 102 ''; 103})