X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=near-rt-ric-simulator%2Ftest%2Fcommon%2Ftest_common.sh;fp=near-rt-ric-simulator%2Ftest%2Fcommon%2Ftest_common.sh;h=b142ce8b1c5f5bd13173588710465f79ef8ecab6;hb=21be2e0c890fb9604d0add2942fcff19b6fe2fb2;hp=0000000000000000000000000000000000000000;hpb=f27a4460b38b62e665f3e9ee936f439270eded32;p=sim%2Fa1-interface.git diff --git a/near-rt-ric-simulator/test/common/test_common.sh b/near-rt-ric-simulator/test/common/test_common.sh new file mode 100755 index 0000000..b142ce8 --- /dev/null +++ b/near-rt-ric-simulator/test/common/test_common.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# ============LICENSE_START=============================================== +# Copyright (C) 2020 Nordix Foundation. All rights reserved. +# ======================================================================== +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END================================================= +# + +# Function to execute curl and compare + print result + +#args: [file] +#Expects the env $RESULT to contain the expected RESULT. +#If json, the RESULT shall begin with 'json:'. +#Any json parameter with unknown value shall be given as "????" to skip checking the value. +do_curl() { + if [ $# -lt 3 ]; then + echo "Need 3 or more parameters, [file]: "$@ + echo "Exiting test script....." + exit 1 + fi + curlstr="curl -X "$1" -sw %{http_code} localhost:"${PORT}${2}" -H accept:*/*" + if [ $# -gt 3 ]; then + curlstr=$curlstr" -H Content-Type:application/json --data-binary @"$4 + fi + echo " CMD:"$curlstr + res=$($curlstr) + status=${res:${#res}-3} + body=${res:0:${#res}-3} + if [ $status -ne $3 ]; then + echo " Error status :"$status" Expected status: "$3 + echo " Body :"$body + echo "Exiting test script....." + exit 1 + else + echo " OK, code :"$status" (Expected)" + echo " Body :"$body + if [ "$RESULT" == "*" ]; then + echo " Body contents not checked" + elif [[ "$RESULT" == "json:"* ]]; then + result=${RESULT:5:${#RESULT}} #Remove 'json:' from the result string + res=$(python ../common/compare_json.py "$result" "$body") + echo $res + if [ $res -eq 0 ]; then + echo " Expected json body :"$result + echo " Body as expected" + else + echo " Expected json body :"$result + echo "Exiting....." + exit 1 + fi + else + body="$(echo $body | tr -d '\n' )" + if [ "$RESULT" == "$body" ]; then + echo " Expected body :"$RESULT + echo " Body as expected" + else + echo " Expected body :"$RESULT + echo "Exiting....." + exit 1 + fi + fi + fi +} \ No newline at end of file