From c5c7ccf022559bd3c40506786a1ffba1b28a08d0 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 26 Dec 2019 18:03:39 +0100 Subject: [PATCH] nixos/nginx: fix test When using format-strings, curly brackets need to be escaped using `{{` to avoid errors from python. And apparently, Perl's `==` is used to compare substrings[1] which is why the translation to `assert http_code == "304"` failed as the string contains several headers from curl. [1] Just check `perl <(echo 'die "alarm" if "foo\n304" == 304')` --- nixos/tests/nginx.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nixos/tests/nginx.nix b/nixos/tests/nginx.nix index 24e85d77c884..55d2c9309084 100644 --- a/nixos/tests/nginx.nix +++ b/nixos/tests/nginx.nix @@ -73,11 +73,13 @@ import ./make-test-python.nix ({ pkgs, ... }: { def check_etag(): - etag = webserver.succeed(f'curl -v {url} 2>&1 | sed -n -e "s/^< etag: *//ip"') + etag = webserver.succeed( + f'curl -v {url} 2>&1 | sed -n -e "s/^< etag: *//ip"' + ).rstrip() http_code = webserver.succeed( - f"curl -w '%{http_code}' -X HEAD -H 'If-None-Match: {etag}' {url}" + f"curl -w '%{{http_code}}' --head --fail -H 'If-None-Match: {etag}' {url}" ) - assert http_code == "304" + assert http_code.split("\n")[-1] == "304" return etag @@ -90,6 +92,7 @@ import ./make-test-python.nix ({ pkgs, ... }: { webserver.succeed( "${etagSystem}/bin/switch-to-configuration test >&2" ) + webserver.sleep(1) new_etag = check_etag() assert old_etag != new_etag