nixos/caddy: port test to python
This commit is contained in:
committed by
Marijan Petricevic
parent
85f3d86bea
commit
2f7199af21
+31
-26
@@ -1,4 +1,4 @@
|
|||||||
import ./make-test.nix ({ pkgs, ... }: {
|
import ./make-test-python.nix ({ pkgs, ... }: {
|
||||||
name = "caddy";
|
name = "caddy";
|
||||||
meta = with pkgs.stdenv.lib.maintainers; {
|
meta = with pkgs.stdenv.lib.maintainers; {
|
||||||
maintainers = [ xfix ];
|
maintainers = [ xfix ];
|
||||||
@@ -50,33 +50,38 @@ import ./make-test.nix ({ pkgs, ... }: {
|
|||||||
etagSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-1";
|
etagSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-1";
|
||||||
justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-2";
|
justReloadSystem = "${nodes.webserver.config.system.build.toplevel}/fine-tune/child-2";
|
||||||
in ''
|
in ''
|
||||||
my $url = 'http://localhost/example.html';
|
url = "http://localhost/example.html"
|
||||||
$webserver->waitForUnit("caddy");
|
webserver.wait_for_unit("caddy")
|
||||||
$webserver->waitForOpenPort("80");
|
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 {
|
def check_etag(url):
|
||||||
my $oldEtag = checkEtag;
|
etag = webserver.succeed(
|
||||||
$webserver->succeed("${etagSystem}/bin/switch-to-configuration test >&2");
|
"curl -v '{}' 2>&1 | sed -n -e \"s/^< [Ee][Tt][Aa][Gg]: *//p\"".format(url)
|
||||||
$webserver->sleep(1); # race condition
|
)
|
||||||
my $newEtag = checkEtag;
|
etag = etag.replace("\r\n", " ")
|
||||||
die "Old ETag $oldEtag is the same as $newEtag" if $oldEtag eq $newEtag;
|
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");
|
with subtest("check ETag if serving Nix store paths"):
|
||||||
$webserver->waitForOpenPort("8080");
|
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")
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user