From 35251c637ba222c193e7dd5247606964d534c1d8 Mon Sep 17 00:00:00 2001 From: Yaya Date: Thu, 31 Mar 2022 19:39:12 +0000 Subject: [PATCH] nixos/tests/gitlab: Check HTTP response codes cURL always exits with `0` even when the HTTP response codes are above 400, leading to false-positive test results. --- nixos/tests/gitlab.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nixos/tests/gitlab.nix b/nixos/tests/gitlab.nix index f4fac2478fab..c5d925749211 100644 --- a/nixos/tests/gitlab.nix +++ b/nixos/tests/gitlab.nix @@ -116,17 +116,23 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : with lib; { ) '' + optionalString doSetup '' gitlab.succeed( - "curl -X POST -H 'Content-Type: application/json' -H @/tmp/headers -d @${createProject} http://gitlab/api/v4/projects" + """[ "$(curl -o /dev/null -w '%{http_code}' -X POST -H 'Content-Type: application/json' -H @/tmp/headers -d @${createProject} http://gitlab/api/v4/projects)" = "201" ]""" ) gitlab.succeed( - "curl -X POST -H 'Content-Type: application/json' -H @/tmp/headers -d @${putFile} http://gitlab/api/v4/projects/2/repository/files/some-file.txt" + """[ "$(curl -o /dev/null -w '%{http_code}' -X POST -H 'Content-Type: application/json' -H @/tmp/headers -d @${putFile} http://gitlab/api/v4/projects/2/repository/files/some-file.txt)" = "201" ]""" ) '' + '' gitlab.succeed( - "curl -H @/tmp/headers http://gitlab/api/v4/projects/2/repository/archive.tar.gz > /tmp/archive.tar.gz" + """[ "$(curl -o /dev/null -w '%{http_code}' -H @/tmp/headers http://gitlab/api/v4/projects/2/repository/archive.tar.gz)" = "200" ]""" ) gitlab.succeed( - "curl -H @/tmp/headers http://gitlab/api/v4/projects/2/repository/archive.tar.bz2 > /tmp/archive.tar.bz2" + """curl -H @/tmp/headers http://gitlab/api/v4/projects/2/repository/archive.tar.gz > /tmp/archive.tar.gz""" + ) + gitlab.succeed( + """[ "$(curl -o /dev/null -w '%{http_code}' -H @/tmp/headers http://gitlab/api/v4/projects/2/repository/archive.tar.bz2)" = "200" ]""" + ) + gitlab.succeed( + """curl -o /dev/null -w '%{http_code}' -H @/tmp/headers http://gitlab/api/v4/projects/2/repository/archive.tar.bz2 > /tmp/archive.tar.bz2""" ) gitlab.succeed("test -s /tmp/archive.tar.gz") gitlab.succeed("test -s /tmp/archive.tar.bz2")