@@ -153,7 +153,7 @@ parse_header() {
153153 RESPONSE_HEADER=$( echo " $header " " { \" http_version\" : \" ${RESPONSE[0]} \" ,
154154 \" http_status\" : \" ${RESPONSE[1]} \" ,
155155 \" http_message\" : \" ${RESPONSE[@]: 2} \" ,
156- \" http_response\" : \" ${RESPONSE[@]: 0} \" }" | jq -s add)
156+ \" http_response\" : \" ${RESPONSE[@]: 0} \" }" | jq -c - s add)
157157}
158158
159159# # run specific methods
@@ -216,21 +216,38 @@ test_factory() {
216216 continue
217217 fi
218218
219- tput cuf 2
220- echo " ${UNDERLINE} a. Checking condition for header${RESET} "
221- test_runner $TEST_CASE " header" " $RESPONSE_HEADER "
222- echo " "
223- echo " "
224- tput cuf 2
225- echo " ${UNDERLINE} b. Checking condition for body${RESET} "
226- test_runner $TEST_CASE " body" " $RESPONSE_BODY "
227- echo " "
228- echo " "
219+ local TEST_SCENARIO=$( jq -r " .testCases.$TEST_CASE .expect.header? | select(. !=null and . != {})" $FILE )
220+ if [[ ! -z $TEST_SCENARIO ]]; then
221+ tput cuf 2
222+ echo " ${UNDERLINE} Checking condition for header${RESET} "
223+ test_runner $TEST_CASE " header" " $RESPONSE_HEADER "
224+ echo " "
225+ echo " "
226+ fi
227+
228+ TEST_SCENARIO=$( jq -r " .testCases.$TEST_CASE .expect.body? | select(. !=null and . != {})" $FILE )
229+ if [[ ! -z $TEST_SCENARIO ]]; then
230+ tput cuf 2
231+ echo " ${UNDERLINE} Checking condition for body${RESET} "
232+ test_runner $TEST_CASE " body" " $RESPONSE_BODY "
233+ echo " "
234+ echo " "
235+ fi
236+
237+ TEST_SCENARIO=$( jq -r " .testCases.$TEST_CASE .expect.external? | select(. !=null and . != \"\" )" $FILE )
238+ if [[ ! -z $TEST_SCENARIO ]]; then
239+ tput cuf 2
240+ echo " ${UNDERLINE} Checking condition form external program${RESET} "
241+ external_script " $TEST_SCENARIO " " $TEST_CASE " " $RESPONSE_BODY " " $RESPONSE_HEADER "
242+ echo " "
243+ echo " "
244+ fi
229245 done
246+
230247}
231248
232249test_runner () {
233- for test in " " contains eq path_eq path_contains hasKey[] external " " ; do
250+ for test in " " contains eq path_eq path_contains hasKey[]" " ; do
234251 local TEST_SCENARIO=$( jq -r " .testCases.$1 .expect.$2 .$test ? | select(. !=null)" $FILE )
235252 if [[ -z $TEST_SCENARIO ]]; then
236253 continue
@@ -248,9 +265,6 @@ test_runner() {
248265 elif [[ $test == " path_contains" ]]; then
249266 echo " Checking path contains comparision${RESET} "
250267 path_checker " $TEST_SCENARIO " " $3 " 1
251- elif [[ $test == " external" ]]; then
252- echo " Checking external comparision${RESET} "
253- external_script " $TEST_SCENARIO " " $3 "
254268 else
255269 echo " Checking has key comparision${RESET} "
256270 has_key " $TEST_SCENARIO " " $3 "
@@ -259,16 +273,14 @@ test_runner() {
259273}
260274
261275external_script () {
262- $1 " $2 "
263- if [[ $? == 0 ]]; then
276+ $1 " $2 " " $3 " " $4 "
277+ local EXIT_CODE=$?
278+ if [[ $EXIT_CODE == 0 ]]; then
264279 tput cuf 6
265-
266280 echo " ${GREEN}${BOLD} Check Passed${RESET} "
267281 else
268282 tput cuf 6
269-
270283 echo " ${RED}${BOLD} Check Failed${RESET} "
271- echo " External check returned error"
272284 fi
273285}
274286
0 commit comments