summaryrefslogtreecommitdiffstats
path: root/nixos/tests/caddy.nix
diff options
context:
space:
mode:
authorKonrad Borowski <konrad@borowski.pw>2019-10-09 13:32:03 +0200
committerzimbatm <zimbatm@zimbatm.com>2019-10-09 11:32:03 +0000
commit7e1e1386066c25986402c19c849b7c6f91ff657d (patch)
treef3497ef6b5b944b4c506beaa687ecc637d64e7f6 /nixos/tests/caddy.nix
parenteb7ecd3b6f43d5402fba6abc736ad9a86347ae05 (diff)
nixos/caddy: add tests (#70778)
Diffstat (limited to 'nixos/tests/caddy.nix')
-rw-r--r--nixos/tests/caddy.nix82
1 files changed, 82 insertions, 0 deletions
diff --git a/nixos/tests/caddy.nix b/nixos/tests/caddy.nix
new file mode 100644
index 000000000000..ab9d2fbf4d1d
--- /dev/null
+++ b/nixos/tests/caddy.nix
@@ -0,0 +1,82 @@
+import ./make-test.nix ({ pkgs, ... }: {
+ name = "caddy";
+ meta = with pkgs.stdenv.lib.maintainers; {
+ maintainers = [ xfix ];
+ };
+
+ nodes = {
+ webserver = { pkgs, lib, ... }: {
+ services.caddy.enable = true;
+ services.caddy.config = ''
+ http://localhost {
+ gzip
+
+ root ${
+ pkgs.runCommand "testdir" {} ''
+ mkdir "$out"
+ echo hello world > "$out/example.html"
+ ''
+ }
+ }
+ '';
+
+ nesting.clone = [
+ {
+ services.caddy.config = lib.mkForce ''
+ http://localhost {
+ gzip
+
+ root ${
+ pkgs.runCommand "testdir2" {} ''
+ mkdir "$out"
+ echo changed > "$out/example.html"
+ ''
+ }
+ }
+ '';
+ }
+
+ {
+ services.caddy.config = ''
+ http://localhost:8080 {
+ }
+ '';
+ }
+ ];
+ };
+ };
+
+ testScript = { nodes, ... }: let
+ etagSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-1";
+ justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-2";
+ in ''
+ my $url = 'http://localhost/example.html';
+ $webserver->waitForUnit("caddy");
+ $webserver->waitForOpenPort("80");
+
+ sub checkEtag {
+ my $etag = $webserver->succeed(
+ 'curl -v '.$url.' 2>&1 | sed -n -e "s/^< [Ee][Tt][Aa][Gg]: *//p"'
+ );
+ $etag =~ s/\r?\n$//;
+ my $httpCode = $webserver->succeed(
+ 'curl -w "%{http_code}" -X HEAD -H \'If-None-Match: '.$etag.'\' '.$url
+ );
+ die "HTTP code is not 304" unless $httpCode == 304;
+ return $etag;
+ }
+
+ subtest "check ETag if serving Nix store paths", sub {
+ my $oldEtag = checkEtag;
+ $webserver->succeed("${etagSystem}/bin/switch-to-configuration test >&2");
+ $webserver->sleep(1); # race condition
+ my $newEtag = checkEtag;
+ die "Old ETag $oldEtag is the same as $newEtag" if $oldEtag eq $newEtag;
+ };
+
+ subtest "config is reloaded on nixos-rebuild switch", sub {
+ $webserver->succeed("${justReloadSystem}/bin/switch-to-configuration test >&2");
+ $webserver->waitForOpenPort("8080");
+ };
+ '';
+})