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 #args: <http-operation> <url> <response-code> [file]
23 #Expects the env $RESULT to contain the expected RESULT.
24 #If json, the RESULT shall begin with 'json:'.
25 #Any json parameter with unknown value shall be given as "????" to skip checking the value.
28 echo "Need 3 or more parameters, <http-operation> <url> <response-code> [file]: "$@
29 echo "Exiting test script....."
32 curlstr="curl -X "$1" -sw %{http_code} localhost:"${PORT}${2}" -H accept:*/*"
34 curlstr=$curlstr" -H Content-Type:application/json --data-binary @"$4
38 status=${res:${#res}-3}
39 body=${res:0:${#res}-3}
40 if [ $status -ne $3 ]; then
41 echo " Error status :"$status" Expected status: "$3
43 echo "Exiting test script....."
46 echo " OK, code :"$status" (Expected)"
48 if [ "$RESULT" == "*" ]; then
49 echo " Body contents not checked"
50 elif [[ "$RESULT" == "json:"* ]]; then
51 result=${RESULT:5:${#RESULT}} #Remove 'json:' from the result string
52 res=$(python ../common/compare_json.py "$result" "$body")
54 if [ $res -eq 0 ]; then
55 echo " Expected json body :"$result
56 echo " Body as expected"
58 echo " Expected json body :"$result
63 body="$(echo $body | tr -d '\n' )"
64 if [ "$RESULT" == "$body" ]; then
65 echo " Expected body :"$RESULT
66 echo " Body as expected"
68 echo " Expected body :"$RESULT