nixos/caddy: add tests (#70778)

This commit is contained in:
Konrad Borowski 2019-10-09 13:32:03 +02:00 committed by zimbatm
parent eb7ecd3b6f
commit 7e1e138606
3 changed files with 89 additions and 0 deletions

View File

@ -7065,6 +7065,12 @@
githubId = 36407913;
name = "Uli Baum";
};
xfix = {
email = "konrad@borowski.pw";
github = "xfix";
githubId = 1297598;
name = "Konrad Borowski";
};
xnaveira = {
email = "xnaveira@gmail.com";
github = "xnaveira";

View File

@ -35,6 +35,7 @@ in
boot-stage1 = handleTest ./boot-stage1.nix {};
borgbackup = handleTest ./borgbackup.nix {};
buildbot = handleTest ./buildbot.nix {};
caddy = handleTest ./caddy.nix {};
cadvisor = handleTestOn ["x86_64-linux"] ./cadvisor.nix {};
cassandra = handleTest ./cassandra.nix {};
ceph = handleTestOn ["x86_64-linux"] ./ceph.nix {};

82
nixos/tests/caddy.nix Normal file
View File

@ -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");
};
'';
})