X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=test%2Fcommon%2Fdo_curl_function.sh;fp=test%2Fcommon%2Fdo_curl_function.sh;h=c4365d8b85466182f809c1b0210876fb7b0af16a;hb=72667f1d4b9e534b38b206f64f2ac67df01a2ed9;hp=e1d890d021795109771edb8623544b5ce88470d1;hpb=c6ce83e505a1919db52b054f1d86add74dc8f138;p=nonrtric.git diff --git a/test/common/do_curl_function.sh b/test/common/do_curl_function.sh index e1d890d0..c4365d8b 100755 --- a/test/common/do_curl_function.sh +++ b/test/common/do_curl_function.sh @@ -25,9 +25,11 @@ # All calls made to 'localhost:'. # Expects env PORT set to intended port number # Expects env RESULT to contain the target response body. +# Optional env HTTPX shall contain protocol 'http' or 'https'. If not set, 'http' is used. For 'https' all cert errors are ignored # RESULT="*" means that returned payload is not checked, may container any text -# RESULT="" menans that the returned payload has to match the exactly +# RESULT="" means that the returned payload has to match the exactly # RESULT="json:" means that the returned json payload is compared with the expected result (order of json keys and index is irrelevant) +# RESULT="json-array-size:" means that the returned json payload shall contain the number of element given by the # Env BODY contains the response body after the call # Any error will stop script execution # How to use in a test script: source this file into your bash test script to the make the function available. @@ -39,7 +41,19 @@ do_curl() { echo "Exting test script....." exit 1 fi - curlstr="curl -X "$1" -sw %{http_code} localhost:$PORT$2 -H accept:*/*" + + if [ -z $HTTPX ]; then + if [ "$HTTPX" != "http" ] && [ "$HTTPX" != "https" ]; then + echo "Env var HTTPX shall be set to 'http' or 'https'" + echo "Exting test script....." + exit 1 + fi + PROT="http" + else + PROT=$HTTPX + fi + + curlstr="curl -X "$1" -skw %{http_code} ${PROT}://localhost:$PORT$2 -H accept:*/*" if [ $# -gt 3 ]; then curlstr=$curlstr" -H Content-Type:application/json --data-binary @"$4 fi @@ -70,6 +84,19 @@ do_curl() { echo "Exiting....." exit 1 fi + elif [[ "$RESULT" == "json-array-size:"* ]]; then + count=${RESULT:16:${#RESULT}} + #Find dir of the common dir + DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + echo $body > .tmp.json + res=$(python ${DIR}/count_json_elements.py .tmp.json) + if [ $res -eq $count ]; then + echo " Body (array size) as expected" + else + echo " Expected json array size: "$count + echo "Exiting....." + exit 1 + fi else body="$(echo $body | tr -d '\n' )" if [ "$RESULT" == "$body" ]; then