at 21.11-pre 2.6 kB view raw
1import ./make-test-python.nix ({ pkgs, ... }: { 2 name = "caddy"; 3 meta = with pkgs.lib.maintainers; { 4 maintainers = [ xfix Br1ght0ne ]; 5 }; 6 7 nodes = { 8 webserver = { pkgs, lib, ... }: { 9 services.caddy.enable = true; 10 services.caddy.config = '' 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 24 specialisation.etag.configuration = { 25 services.caddy.config = lib.mkForce '' 26 http://localhost { 27 encode gzip 28 29 file_server 30 root * ${ 31 pkgs.runCommand "testdir2" {} '' 32 mkdir "$out" 33 echo changed > "$out/example.html" 34 '' 35 } 36 } 37 ''; 38 }; 39 40 specialisation.config-reload.configuration = { 41 services.caddy.config = '' 42 http://localhost:8080 { 43 } 44 ''; 45 }; 46 }; 47 }; 48 49 testScript = { nodes, ... }: let 50 etagSystem = "${nodes.webserver.config.system.build.toplevel}/specialisation/etag"; 51 justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/specialisation/config-reload"; 52 in '' 53 url = "http://localhost/example.html" 54 webserver.wait_for_unit("caddy") 55 webserver.wait_for_open_port("80") 56 57 58 def check_etag(url): 59 etag = webserver.succeed( 60 "curl --fail -v '{}' 2>&1 | sed -n -e \"s/^< [Ee][Tt][Aa][Gg]: *//p\"".format( 61 url 62 ) 63 ) 64 etag = etag.replace("\r\n", " ") 65 http_code = webserver.succeed( 66 "curl --fail --silent --show-error -o /dev/null -w \"%{{http_code}}\" --head -H 'If-None-Match: {}' {}".format( 67 etag, url 68 ) 69 ) 70 assert int(http_code) == 304, "HTTP code is {}, expected 304".format(http_code) 71 return etag 72 73 74 with subtest("check ETag if serving Nix store paths"): 75 old_etag = check_etag(url) 76 webserver.succeed( 77 "${etagSystem}/bin/switch-to-configuration test >&2" 78 ) 79 webserver.sleep(1) 80 new_etag = check_etag(url) 81 assert old_etag != new_etag, "Old ETag {} is the same as {}".format( 82 old_etag, new_etag 83 ) 84 85 with subtest("config is reloaded on nixos-rebuild switch"): 86 webserver.succeed( 87 "${justReloadSystem}/bin/switch-to-configuration test >&2" 88 ) 89 webserver.wait_for_open_port("8080") 90 ''; 91})