@@ -138,11 +138,11 @@ function usage() {
138138
139139# api methods
140140call_api () {
141- ROUTE=$( jq -r " .testCases.$1 .path" $FILE )
142- BODY=" $( jq -r " .testCases.$1 | select(.body != null) | .body" $FILE ) "
143- QUERY_PARAMS=$( cat $FILE | jq -r " .testCases.$1 | select(.query != null) | .query | to_entries | map(\" \(.key)=\(.value|tostring)\" ) | join(\" &\" ) | \" ?\" + . " )
144- REQUEST_HEADER=$( cat $FILE | jq -r " .testCases.$1 | .header | if . != null then . else {} end | to_entries | map(\" \(.key): \(.value|tostring)\" ) | join(\" \n\" ) | if ( . | length) != 0 then \" -H\" + . else \" -H \" end" )
145- METHOD=" $( jq -r " .testCases.$1 .method //\" GET\" | ascii_upcase" $FILE ) "
141+ ROUTE=$( jq -r " .testCases.\" $1 \" .path" $FILE )
142+ BODY=" $( jq -r " .testCases.\" $1 \" | select(.body != null) | .body" $FILE ) "
143+ QUERY_PARAMS=$( cat $FILE | jq -r " .testCases.\" $1 \" | select(.query != null) | .query | to_entries | map(\" \(.key)=\(.value|tostring)\" ) | join(\" &\" ) | \" ?\" + . " )
144+ REQUEST_HEADER=$( cat $FILE | jq -r " .testCases.\" $1 \" | .header | if . != null then . else {} end | to_entries | map(\" \(.key): \(.value|tostring)\" ) | join(\" \n\" ) | if ( . | length) != 0 then \" -H\" + . else \" -H \" end" )
145+ METHOD=" $( jq -r " .testCases.\" $1 \" .method //\" GET\" | ascii_upcase" $FILE ) "
146146 # curl -ivs --request $METHOD "$URL$ROUTE$QUERY_PARAMS" \
147147 # --data "$BODY" \
148148 # "$COMMON_HEADER" \
@@ -211,8 +211,8 @@ api_factory() {
211211 for TEST_CASE in $@ ; do
212212 API_ERROR=0
213213 echo " ${BOLD} Running Case:${RESET} $TEST_CASE "
214- echo_v " ${BOLD} Description: ${RESET} $( jq -r " .testCases.$TEST_CASE .description" $FILE ) "
215- echo_v " ${BOLD} Action: ${RESET} $( jq -r " .testCases.$TEST_CASE .method //\" GET\" | ascii_upcase" $FILE ) $( jq -r " .testCases.$TEST_CASE .path" $FILE ) "
214+ echo_v " ${BOLD} Description: ${RESET} $( jq -r " .testCases.\" $TEST_CASE \" .description" $FILE ) "
215+ echo_v " ${BOLD} Action: ${RESET} $( jq -r " .testCases.\" $TEST_CASE \" .method //\" GET\" | ascii_upcase" $FILE ) $( jq -r " .testCases.\" $TEST_CASE \" .path" $FILE ) "
216216 call_api $TEST_CASE
217217 display_results
218218 echo " "
@@ -227,9 +227,9 @@ test_factory() {
227227 for TEST_CASE in $@ ; do
228228 API_ERROR=0
229229 echo " ${BOLD} Testing Case:${RESET} $TEST_CASE "
230- echo_v " ${BOLD} Description: ${RESET} $( jq -r " .testCases.$TEST_CASE .description" $FILE ) "
231- echo_v " ${BOLD} Action: ${RESET} $( jq -r " .testCases.$TEST_CASE .method //\" GET\" | ascii_upcase" $FILE ) $( jq -r " .testCases.$TEST_CASE .path" $FILE ) "
232- if [[ -z $( jq -r " .testCases.$TEST_CASE .expect? | select(. !=null)" $FILE ) ]]; then
230+ echo_v " ${BOLD} Description: ${RESET} $( jq -r " .testCases.\" $TEST_CASE \" .description" $FILE ) "
231+ echo_v " ${BOLD} Action: ${RESET} $( jq -r " .testCases.\" $TEST_CASE \" .method //\" GET\" | ascii_upcase" $FILE ) $( jq -r " .testCases.\" $TEST_CASE \" .path" $FILE ) "
232+ if [[ -z $( jq -r " .testCases.\" $TEST_CASE \" .expect? | select(. !=null)" $FILE ) ]]; then
233233 tput cuf 2
234234 echo " No test cases found"
235235 echo " "
@@ -245,7 +245,7 @@ test_factory() {
245245 continue
246246 fi
247247
248- local TEST_SCENARIO=$( jq -r " .testCases.$TEST_CASE .expect.header? | select(. !=null and . != {})" $FILE )
248+ local TEST_SCENARIO=$( jq -r " .testCases.\" $TEST_CASE \" .expect.header? | select(. !=null and . != {})" $FILE )
249249 if [[ ! -z $TEST_SCENARIO ]]; then
250250 tput cuf 2
251251 echo " ${UNDERLINE} Checking condition for header${RESET} "
@@ -254,7 +254,7 @@ test_factory() {
254254 echo " "
255255 fi
256256
257- TEST_SCENARIO=$( jq -r " .testCases.$TEST_CASE .expect.body? | select(. !=null and . != {})" $FILE )
257+ TEST_SCENARIO=$( jq -r " .testCases.\" $TEST_CASE \" .expect.body? | select(. !=null and . != {})" $FILE )
258258 if [[ ! -z $TEST_SCENARIO ]]; then
259259 tput cuf 2
260260 echo " ${UNDERLINE} Checking condition for body${RESET} "
@@ -263,7 +263,7 @@ test_factory() {
263263 echo " "
264264 fi
265265
266- TEST_SCENARIO=$( jq -r " .testCases.$TEST_CASE .expect.external? | select(. !=null and . != \"\" )" $FILE )
266+ TEST_SCENARIO=$( jq -r " .testCases.\" $TEST_CASE \" .expect.external? | select(. !=null and . != \"\" )" $FILE )
267267 if [[ ! -z $TEST_SCENARIO ]]; then
268268 tput cuf 2
269269 echo " ${UNDERLINE} Checking condition from external program${RESET} "
@@ -299,7 +299,7 @@ test_factory() {
299299
300300test_runner () {
301301 for test in " " contains eq path_eq path_contains hasKey[]" " ; do
302- local TEST_SCENARIO=$( jq -c -r " .testCases.$1 .expect.$2 .$test ? | select(. !=null)" $FILE )
302+ local TEST_SCENARIO=$( jq -c -r " .testCases.\" $1 \" .expect.$2 .$test ? | select(. !=null)" $FILE )
303303 if [[ -z $TEST_SCENARIO ]]; then
304304 continue
305305 fi
0 commit comments