From 7f31d87e2a58ae108757391699d74ea3132fb560 Mon Sep 17 00:00:00 2001 From: Fabrice Reix Date: Fri, 5 Apr 2024 10:16:07 +0200 Subject: [PATCH] Test pretty-printed JSON output --- bin/install_prerequisites_alpine.sh | 2 +- bin/install_prerequisites_archlinux.sh | 2 +- bin/install_prerequisites_docker_archlinux.sh | 2 +- bin/install_prerequisites_docker_fedora.sh | 2 +- bin/install_prerequisites_docker_ubuntu.sh | 3 +- bin/install_prerequisites_fedora.sh | 2 +- bin/install_prerequisites_macos.sh | 2 +- bin/install_prerequisites_ubuntu.sh | 2 +- bin/install_prerequisites_windows.ps1 | 4 + .../assert_value_error.out.pattern | 130 +++++++++++++++++- .../hurl/tests_failed/assert_value_error.ps1 | 6 +- .../hurl/tests_failed/assert_value_error.sh | 8 +- 12 files changed, 154 insertions(+), 11 deletions(-) diff --git a/bin/install_prerequisites_alpine.sh b/bin/install_prerequisites_alpine.sh index 71a17617a4f..abf4e747490 100755 --- a/bin/install_prerequisites_alpine.sh +++ b/bin/install_prerequisites_alpine.sh @@ -3,6 +3,6 @@ set -Eeuo pipefail echo "----- install prerequisite packages -----" apk update --quiet -apk add --quiet sudo bash sudo netcat-openbsd curl curl-dev build-base libidn2 libffi-dev libxml2-dev libxml2-utils openssl-dev python3 python3-dev py3-pip cargo squid +apk add --quiet sudo bash sudo netcat-openbsd curl curl-dev build-base libidn2 libffi-dev libxml2-dev libxml2-utils openssl-dev python3 python3-dev py3-pip cargo squid jq sudo squid -k shutdown || true sudo rm -v /dev/shm/squid*.shm >/dev/null 2>&1 || true diff --git a/bin/install_prerequisites_archlinux.sh b/bin/install_prerequisites_archlinux.sh index 9920cc17578..471a4526ad3 100755 --- a/bin/install_prerequisites_archlinux.sh +++ b/bin/install_prerequisites_archlinux.sh @@ -2,6 +2,6 @@ set -Eeuo pipefail echo "----- install prerequisite packages -----" -pacman -Syu --noconfirm bash sudo icu base-devel libxml2 python3 python3-venv glibc openbsd-netcat squid +pacman -Syu --noconfirm bash sudo icu base-devel libxml2 python3 python3-venv glibc openbsd-netcat squid jq sudo squid -k shutdown || true sudo rm -v /dev/shm/squid*.shm >/dev/null 2>&1 || true diff --git a/bin/install_prerequisites_docker_archlinux.sh b/bin/install_prerequisites_docker_archlinux.sh index c1e60f12ffa..b8453f7f01d 100755 --- a/bin/install_prerequisites_docker_archlinux.sh +++ b/bin/install_prerequisites_docker_archlinux.sh @@ -2,7 +2,7 @@ set -Eeuo pipefail echo "----- install prerequisite packages -----" -pacman -Sy --noconfirm bash sudo python3 python-pip icu base-devel libxml2 glibc openbsd-netcat squid +pacman -Sy --noconfirm bash sudo python3 python-pip icu base-devel libxml2 glibc openbsd-netcat squid jq sudo squid -k shutdown || true sudo rm -v /dev/shm/squid*.shm >/dev/null 2>&1 || true diff --git a/bin/install_prerequisites_docker_fedora.sh b/bin/install_prerequisites_docker_fedora.sh index e4175cdc929..8dbe00f967e 100755 --- a/bin/install_prerequisites_docker_fedora.sh +++ b/bin/install_prerequisites_docker_fedora.sh @@ -2,7 +2,7 @@ set -Eeuo pipefail echo "----- install prerequisite packages -----" -yum install -y sudo which python3 python3-pip procps gcc libxml2-devel openssl-devel libcurl-devel nc squid +yum install -y sudo which python3 python3-pip procps gcc libxml2-devel openssl-devel libcurl-devel nc squid jq sudo squid -k shutdown || true sudo rm -v /dev/shm/squid*.shm >/dev/null 2>&1 || true diff --git a/bin/install_prerequisites_docker_ubuntu.sh b/bin/install_prerequisites_docker_ubuntu.sh index ec5c55df395..17bfbb8dbdc 100755 --- a/bin/install_prerequisites_docker_ubuntu.sh +++ b/bin/install_prerequisites_docker_ubuntu.sh @@ -19,7 +19,8 @@ apt-get -y install \ python3-pip \ python3-venv \ netcat-openbsd \ - squid + squid \ + jq sudo service squid stop sudo squid -k shutdown || true sudo rm -v /dev/shm/squid*.shm >/dev/null 2>&1 || true diff --git a/bin/install_prerequisites_fedora.sh b/bin/install_prerequisites_fedora.sh index 3b84294611f..524d693c6d1 100755 --- a/bin/install_prerequisites_fedora.sh +++ b/bin/install_prerequisites_fedora.sh @@ -2,7 +2,7 @@ set -Eeuo pipefail echo "----- install prerequisite packages -----" -yum install -y bash sudo procps gcc libxml2-devel openssl-devel libcurl-devel python3-devel python3-pip nc squid +yum install -y bash sudo procps gcc libxml2-devel openssl-devel libcurl-devel python3-devel python3-pip nc squid jq sudo squid -k shutdown || true sudo rm -v /dev/shm/squid*.shm >/dev/null 2>&1 || true diff --git a/bin/install_prerequisites_macos.sh b/bin/install_prerequisites_macos.sh index 2625237c7c8..ccdf27fe308 100755 --- a/bin/install_prerequisites_macos.sh +++ b/bin/install_prerequisites_macos.sh @@ -15,7 +15,7 @@ export CURL_PATH echo "CURL_PATH=$CURL_PATH" PATH="$CURL_PATH:$PATH" export PATH -brew install bash pkg-config squid +brew install bash pkg-config squid jq sudo squid -k shutdown || true sudo rm -v /dev/shm/squid*.shm >/dev/null 2>&1 || true diff --git a/bin/install_prerequisites_ubuntu.sh b/bin/install_prerequisites_ubuntu.sh index bbea4cb9cf5..9ed4d894b0a 100755 --- a/bin/install_prerequisites_ubuntu.sh +++ b/bin/install_prerequisites_ubuntu.sh @@ -3,7 +3,7 @@ set -Eeuo pipefail echo "----- install prerequisite packages -----" sudo apt-get update -sudo apt-get -y install bash libcurl4-openssl-dev libxml2-utils netcat-openbsd python3 python3-pip python3-venv net-tools squid +sudo apt-get -y install bash libcurl4-openssl-dev libxml2-utils netcat-openbsd python3 python3-pip python3-venv net-tools squid jq sudo service squid stop || true sudo squid -k shutdown || true sudo rm -v /dev/shm/squid*.shm >/dev/null 2>&1 || true diff --git a/bin/install_prerequisites_windows.ps1 b/bin/install_prerequisites_windows.ps1 index 59d0e07d989..2a43e0a4d34 100644 --- a/bin/install_prerequisites_windows.ps1 +++ b/bin/install_prerequisites_windows.ps1 @@ -47,3 +47,7 @@ sc queryex squidsrv | tee -Append -filepath integration\build\proxy.log echo "==== Squid process status" Get-Process | Where {$_.Name -eq "Squid"} | tee -Append -filepath integration\build\proxy.log +# install jq +echo "==== install jq" +choco install --confirm jq +if ($LASTEXITCODE) { Throw } diff --git a/integration/hurl/tests_failed/assert_value_error.out.pattern b/integration/hurl/tests_failed/assert_value_error.out.pattern index 15bf6f40b56..d7c02380e15 100644 --- a/integration/hurl/tests_failed/assert_value_error.out.pattern +++ b/integration/hurl/tests_failed/assert_value_error.out.pattern @@ -1 +1,129 @@ -{"cookies":[],"entries":[{"asserts":[{"line":2,"success":true},{"line":2,"success":true},{"line":4,"message":"Assert failure\n --> tests_failed/assert_value_error.hurl:4:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 4 | header \"content-type\" == \"XXX\"\n | actual: string \n | expected: string \n |","success":false},{"line":5,"message":"Assert failure\n --> tests_failed/assert_value_error.hurl:5:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 5 | header \"content-type\" != \"text/html; charset=utf-8\"\n | actual: string \n | expected: string \n |","success":false},{"line":6,"message":"Assert failure\n --> tests_failed/assert_value_error.hurl:6:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 6 | jsonpath \"$.id\" == \"000001\"\n | actual: none\n | expected: string <000001>\n |","success":false},{"line":7,"message":"Assert failure\n --> tests_failed/assert_value_error.hurl:7:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 7 | jsonpath \"$.values\" includes 100\n | actual: [int <1>, int <2>, int <3>]\n | expected: includes int <100>\n |","success":false},{"line":8,"message":"Assert failure\n --> tests_failed/assert_value_error.hurl:8:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 8 | jsonpath \"$.values\" not contains \"Hello\"\n | actual: [int <1>, int <2>, int <3>]\n | expected: not contains string \n | >>> types between actual and expected are not consistent\n |","success":false},{"line":9,"message":"Assert failure\n --> tests_failed/assert_value_error.hurl:9:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 9 | jsonpath \"$.count\" > 5\n | actual: int <2>\n | expected: greater than int <5>\n |","success":false},{"line":10,"message":"Assert failure\n --> tests_failed/assert_value_error.hurl:10:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n10 | jsonpath \"$.count\" isFloat\n | actual: int <2>\n | expected: float\n |","success":false},{"line":11,"message":"Assert failure\n --> tests_failed/assert_value_error.hurl:11:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n11 | bytes contains hex,00;\n | actual: byte array <7b202276616c756573223a205b312c322c335d2c2022636f756e74223a20327d>\n | expected: contains byte array <00>\n |","success":false}],"calls":[{"request":{"cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Accept","value":"*/*"},{"name":"User-Agent","value":"hurl/~~~"}],"method":"GET","queryString":[],"url":"http://localhost:8000/error-assert-value"},"response":{"cookies":[],"headers":[{"name":"Server","value":"Werkzeug/~~~ Python/~~~"},{"name":"Date","value":"~~~"},{"name":"Content-Type","value":"text/html; charset=utf-8"},{"name":"Content-Length","value":"32"},{"name":"Server","value":"Flask Server"},{"name":"Connection","value":"close"}],"httpVersion":"HTTP/1.1","status":200},"timings":{"app_connect":~~~,"begin_call":"~~~","connect":~~~,"end_call":"~~~","name_lookup":~~~,"pre_transfer":~~~,"start_transfer":~~~,"total":~~~}}],"captures":[],"index":1,"line":1,"time":~~~}],"filename":"tests_failed/assert_value_error.hurl","success":false,"time":~~~} +{ + "cookies": [], + "entries": [ + { + "asserts": [ + { + "line": 2, + "success": true + }, + { + "line": 2, + "success": true + }, + { + "line": 4, + "message": "Assert failure\n --> tests_failed/assert_value_error.hurl:4:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 4 | header \"content-type\" == \"XXX\"\n | actual: string \n | expected: string \n |", + "success": false + }, + { + "line": 5, + "message": "Assert failure\n --> tests_failed/assert_value_error.hurl:5:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 5 | header \"content-type\" != \"text/html; charset=utf-8\"\n | actual: string \n | expected: string \n |", + "success": false + }, + { + "line": 6, + "message": "Assert failure\n --> tests_failed/assert_value_error.hurl:6:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 6 | jsonpath \"$.id\" == \"000001\"\n | actual: none\n | expected: string <000001>\n |", + "success": false + }, + { + "line": 7, + "message": "Assert failure\n --> tests_failed/assert_value_error.hurl:7:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 7 | jsonpath \"$.values\" includes 100\n | actual: [int <1>, int <2>, int <3>]\n | expected: includes int <100>\n |", + "success": false + }, + { + "line": 8, + "message": "Assert failure\n --> tests_failed/assert_value_error.hurl:8:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 8 | jsonpath \"$.values\" not contains \"Hello\"\n | actual: [int <1>, int <2>, int <3>]\n | expected: not contains string \n | >>> types between actual and expected are not consistent\n |", + "success": false + }, + { + "line": 9, + "message": "Assert failure\n --> tests_failed/assert_value_error.hurl:9:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n 9 | jsonpath \"$.count\" > 5\n | actual: int <2>\n | expected: greater than int <5>\n |", + "success": false + }, + { + "line": 10, + "message": "Assert failure\n --> tests_failed/assert_value_error.hurl:10:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n10 | jsonpath \"$.count\" isFloat\n | actual: int <2>\n | expected: float\n |", + "success": false + }, + { + "line": 11, + "message": "Assert failure\n --> tests_failed/assert_value_error.hurl:11:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n11 | bytes contains hex,00;\n | actual: byte array <7b202276616c756573223a205b312c322c335d2c2022636f756e74223a20327d>\n | expected: contains byte array <00>\n |", + "success": false + } + ], + "calls": [ + { + "request": { + "cookies": [], + "headers": [ + { + "name": "Host", + "value": "localhost:8000" + }, + { + "name": "Accept", + "value": "*/*" + }, + { + "name": "User-Agent", + "value": "hurl/~~~" + } + ], + "method": "GET", + "queryString": [], + "url": "http://localhost:8000/error-assert-value" + }, + "response": { + "cookies": [], + "headers": [ + { + "name": "Server", + "value": "Werkzeug/~~~" + }, + { + "name": "Date", + "value": "~~~" + }, + { + "name": "Content-Type", + "value": "text/html; charset=utf-8" + }, + { + "name": "Content-Length", + "value": "32" + }, + { + "name": "Server", + "value": "Flask Server" + }, + { + "name": "Connection", + "value": "close" + } + ], + "httpVersion": "HTTP/1.1", + "status": 200 + }, + "timings": { + "app_connect": ~~~, + "begin_call": "~~~", + "connect": ~~~, + "end_call": "~~~", + "name_lookup": ~~~, + "pre_transfer": ~~~, + "start_transfer": ~~~, + "total": ~~~ + } + } + ], + "captures": [], + "index": 1, + "line": 1, + "time": ~~~ + } + ], + "filename": "tests_failed/assert_value_error.hurl", + "success": false, + "time": ~~~ +} diff --git a/integration/hurl/tests_failed/assert_value_error.ps1 b/integration/hurl/tests_failed/assert_value_error.ps1 index 808e54f1423..5734cd537b0 100644 --- a/integration/hurl/tests_failed/assert_value_error.ps1 +++ b/integration/hurl/tests_failed/assert_value_error.ps1 @@ -1,3 +1,7 @@ Set-StrictMode -Version latest $ErrorActionPreference = 'Stop' -hurl --json tests_failed/assert_value_error.hurl + +$out=hurl --json tests_failed/assert_value_error.hurl +$exit_code="$lastexitcode" +echo "$out" | jq +exit "$exit_code" \ No newline at end of file diff --git a/integration/hurl/tests_failed/assert_value_error.sh b/integration/hurl/tests_failed/assert_value_error.sh index f1c3b4ad9a0..5569cfca8c4 100755 --- a/integration/hurl/tests_failed/assert_value_error.sh +++ b/integration/hurl/tests_failed/assert_value_error.sh @@ -1,3 +1,9 @@ #!/bin/bash set -Eeuo pipefail -hurl --json tests_failed/assert_value_error.hurl + +set +e +out=$(hurl --json tests_failed/assert_value_error.hurl) +exit_code="$?" +echo "$out" | jq +exit "$exit_code" +