3 # ============LICENSE_START===============================================
4 # Copyright (C) 2020 Nordix Foundation. All rights reserved.
5 # ========================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=================================================
20 # Function to execute curl and compare + print result
22 # Note: Env var PORT must be set to the intended port number
23 # Notre Env var HTTPX must be set to either 'http' or 'https'
25 #args: <http-operation> <url> <response-code> [file]
26 #Expects the env $RESULT to contain the expected RESULT.
27 #If json, the RESULT shall begin with 'json:'.
28 #Any json parameter with unknown value shall be given as "????" to skip checking the value.
31 echo "Need 3 or more parameters, <http-operation> <url> <response-code> [file]: "$@
32 echo "Exiting test script....."
35 curlstr="curl -X "$1" -skw %{http_code} $HTTPX://localhost:"${PORT}${2}" -H accept:*/*"
37 curlstr=$curlstr" -H Content-Type:application/json --data-binary @"$4
39 echo " CMD (${BASH_LINENO[0]}):"$curlstr
41 status=${res:${#res}-3}
42 body=${res:0:${#res}-3}
43 if [ $status -ne $3 ]; then
44 echo " Error status :"$status" Expected status: "$3
46 echo "Exiting test script....."
49 echo " OK, code :"$status" (Expected)"
51 if [ "$RESULT" == "*" ]; then
52 echo " Body contents not checked"
53 elif [[ "$RESULT" == "json:"* ]]; then
54 result=${RESULT:5:${#RESULT}} #Remove 'json:' from the result string
55 res=$(python ../common/compare_json.py "$result" "$body")
56 if [ $res -eq 0 ]; then
57 echo " Expected json body :"$result
58 echo " Body as expected"
60 echo " Expected json body :"$result
65 body="$(echo $body | tr -d '\n' )"
66 if [ "$RESULT" == "$body" ]; then
67 echo " Expected body :"$RESULT
68 echo " Body as expected"
70 echo " Expected body :"$RESULT
80 echo "Need 3 or more parameters, <http-operation> <url> <response-code> [file]: "$@
81 echo "Exiting test script....."
84 curlstr="curl -X "$1" -skw %{http_code} $HTTPX_EXT_SRV://localhost:"${PORT_EXT_SRV}${2}" -H accept:*/*"
86 curlstr=$curlstr" -H Content-Type:application/json --data-binary @"$4
88 echo " CMD (${BASH_LINENO[0]}):"$curlstr
90 status=${res:${#res}-3}
91 body=${res:0:${#res}-3}
92 if [ $status -ne $3 ]; then
93 echo " Error status :"$status" Expected status: "$3
95 echo "Exiting test script....."
98 echo " OK, code :"$status" (Expected)"
100 if [ "$RESULT" == "*" ]; then
101 echo " Body contents not checked"
102 elif [[ "$RESULT" == "json:"* ]]; then
103 result=${RESULT:5:${#RESULT}} #Remove 'json:' from the result string
104 res=$(python ../common/compare_json.py "$result" "$body")
105 if [ $res -eq 0 ]; then
106 echo " Expected json body :"$result
107 echo " Body as expected"
109 echo " Expected json body :"$result
114 body="$(echo $body | tr -d '\n' )"
115 if [ "$RESULT" == "$body" ]; then
116 echo " Expected body :"$RESULT
117 echo " Body as expected"
119 echo " Expected body :"$RESULT