mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-22 14:45:27 +00:00
nixos/caddy: port test to python
This commit is contained in:
parent
85f3d86bea
commit
2f7199af21
|
@ -1,4 +1,4 @@
|
|||
import ./make-test.nix ({ pkgs, ... }: {
|
||||
import ./make-test-python.nix ({ pkgs, ... }: {
|
||||
name = "caddy";
|
||||
meta = with pkgs.stdenv.lib.maintainers; {
|
||||
maintainers = [ xfix ];
|
||||
|
@ -50,33 +50,38 @@ import ./make-test.nix ({ pkgs, ... }: {
|
|||
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");
|
||||
url = "http://localhost/example.html"
|
||||
webserver.wait_for_unit("caddy")
|
||||
webserver.wait_for_open_port("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;
|
||||
};
|
||||
def check_etag(url):
|
||||
etag = webserver.succeed(
|
||||
"curl -v '{}' 2>&1 | sed -n -e \"s/^< [Ee][Tt][Aa][Gg]: *//p\"".format(url)
|
||||
)
|
||||
etag = etag.replace("\r\n", " ")
|
||||
http_code = webserver.succeed(
|
||||
"curl -w \"%{{http_code}}\" -X HEAD -H 'If-None-Match: {}' {}".format(etag, url)
|
||||
)
|
||||
assert int(http_code) == 304, "HTTP code is not 304"
|
||||
return etag
|
||||
|
||||
subtest "config is reloaded on nixos-rebuild switch", sub {
|
||||
$webserver->succeed("${justReloadSystem}/bin/switch-to-configuration test >&2");
|
||||
$webserver->waitForOpenPort("8080");
|
||||
};
|
||||
|
||||
with subtest("check ETag if serving Nix store paths"):
|
||||
old_etag = check_etag(url)
|
||||
webserver.succeed(
|
||||
"${etagSystem}/bin/switch-to-configuration test >&2"
|
||||
)
|
||||
webserver.sleep(1)
|
||||
new_etag = check_etag(url)
|
||||
assert old_etag != new_etag, "Old ETag {} is the same as {}".format(
|
||||
old_etag, new_etag
|
||||
)
|
||||
|
||||
with subtest("config is reloaded on nixos-rebuild switch"):
|
||||
webserver.succeed(
|
||||
"${justReloadSystem}/bin/switch-to-configuration test >&2"
|
||||
)
|
||||
webserver.wait_for_open_port("8080")
|
||||
'';
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue