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')`
This commit is contained in:
Maximilian Bosch 2019-12-26 18:03:39 +01:00
parent 495b0b581c
commit c5c7ccf022
No known key found for this signature in database
GPG key ID: 091DBF4D1FC46B8E

View file

@ -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