summaryrefslogtreecommitdiffstats
path: root/nixos/tests/caddy.nix
diff options
context:
space:
mode:
authorMarijan <marijan.petricevic@hotmail.de>2019-11-06 13:56:16 +0100
committerMarijan Petricevic <marijan.petricevic94@gmail.com>2019-11-07 10:51:04 +0100
commit2f7199af213465a806450013d82cf2be42de4075 (patch)
tree4ccb37494278a910d6c47bdd8e618194bd50a635 /nixos/tests/caddy.nix
parent85f3d86bea70fe0d76a7e3520966c58604f8e5e9 (diff)
nixos/caddy: port test to python
Diffstat (limited to 'nixos/tests/caddy.nix')
-rw-r--r--nixos/tests/caddy.nix57
1 files changed, 31 insertions, 26 deletions
diff --git a/nixos/tests/caddy.nix b/nixos/tests/caddy.nix
index ab9d2fbf4d1d..fc10df0c79b5 100644
--- a/nixos/tests/caddy.nix
+++ b/nixos/tests/caddy.nix
@@ -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")
'';
})