diff --git a/tests/api-test.sh b/tests/api-test.sh index 8e16af5..d322867 100755 --- a/tests/api-test.sh +++ b/tests/api-test.sh @@ -14,6 +14,8 @@ DEFUSER="root" DEFNAMESPACE="sysadm" DEFCLASS="systemmanager" DEFACTION="{\"action\":\"procinfo\"}" +RESTMODE="no" +RESTIP="127.0.0.1" # Set variable to call jsawk utility JSAWK="./utils/jsawk -j js24" @@ -105,31 +107,34 @@ if [ -z "$APITESTPAYLOAD" ] ; then echo "" fi -# Source our resty functions -. ./utils/resty -W "https://127.0.0.1:12151" -H "Accept: application/json" -H "Content-Type: application/json" -u ${APITESTUSER}:${APITESTPASS} +# If the user wanted to do RESTMODE +if [ "$RESTMODE" = "yes" ] ; then + # Source our resty functions + . ./utils/resty -W "https://${RESTIP}:12151" -H "Accept: application/json" -H "Content-Type: application/json" -u ${APITESTUSER}:${APITESTPASS} -# Save output to a file in addition to stdout -ofile="/tmp/api-response" -echo "" > /tmp/api-response + # Save output to a file in addition to stdout + ofile="/tmp/api-response" + echo "" > /tmp/api-response -# Check the reply of this REST query -echo "" | tee -a $ofile -echo "REST Request:" | tee -a $ofile -echo "-------------------------------" | tee -a $ofile -echo "PUT /${APITESTNAMESPACE}/${APITESTCLASS}" | tee -a $ofile -echo "${APITESTPAYLOAD}" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile + # Check the reply of this REST query + echo "" | tee -a $ofile + echo "REST Request:" | tee -a $ofile + echo "-------------------------------" | tee -a $ofile + echo "PUT /${APITESTNAMESPACE}/${APITESTCLASS}" | tee -a $ofile + echo "${APITESTPAYLOAD}" | perl -0007 -MJSON -ne'print to_json(from_json($_, {allow_nonref=>1}),{pretty=>1})."\n"' | tee -a $ofile -echo "" | tee -a $ofile -echo "REST Response:" | tee -a $ofile -echo "-------------------------------" | tee -a $ofile -PUT /${APITESTNAMESPACE}/${APITESTCLASS} "${APITESTPAYLOAD}" -v -k #2>/tmp/.rstErr | tee -a $ofile -if [ $? -ne 0 ] ; then - echo "Failed.. Error output:" - cat /tmp/.rstErr + echo "" | tee -a $ofile + echo "REST Response:" | tee -a $ofile + echo "-------------------------------" | tee -a $ofile + PUT /${APITESTNAMESPACE}/${APITESTCLASS} "${APITESTPAYLOAD}" -v -k 2>/tmp/.rstErr | tee -a $ofile + if [ $? -ne 0 ] ; then + echo "Failed.. Error output:" + cat /tmp/.rstErr + fi + rm $ofile + rm /tmp/.rstErr + exit 0 fi -rm $ofile -rm /tmp/.rstErr -exit 0; # Now check the response via WebSockets