Skip to content

Commit 48075d6

Browse files
committed
Handle default file and error messages for dependency and required values
1 parent 1823861 commit 48075d6

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

api-test.sh

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -514,20 +514,45 @@ for arg in "$@"; do
514514
esac
515515
done
516516

517-
if [ ! -f "$FILE" ]; then
518-
echo "Please provide an existing file."
517+
command -v curl >/dev/null 2>&1 || {
518+
echo >&2 "This program requires 'curl' to run. Please install 'curl'"
519+
exit 1
520+
}
521+
command -v jq >/dev/null 2>&1 || {
522+
echo >&2 "This program requires 'jq' to run. Please install 'jq'"
519523
exit 1
524+
}
525+
526+
if [ ! -f "$FILE" ]; then
527+
DEFAULT_FILE=("test.json api-test.json template.json")
528+
FOUND_FILE=0
529+
for default in $DEFAULT_FILE; do
530+
if [ -f "$default" ]; then
531+
FOUND_FILE=1
532+
FILE=$default
533+
break
534+
fi
535+
done
536+
if [[ $FOUND_FILE == 0 ]]; then
537+
echo "Please provide an existing file."
538+
exit 1
539+
fi
540+
echo $FILE
520541
fi
521542

522-
cat $FILE | jq empty
543+
jq empty $FILE
544+
523545
if [ $? -ne 0 ]; then
524-
echo "Empty file"
525-
exit
546+
exit 1
526547
fi
548+
527549
URL=$(jq -r '.url' $FILE)
528-
ACCESS_TOKEN=$(jq -r '.accessToken' $FILE)
529-
ID_TOKEN=$(jq -r '.idToken' $FILE)
530550
COMMON_HEADER=$(cat $FILE | jq -r -c ". | .header | if . != null then . else {} end | to_entries | map(\"\(.key): \(.value|tostring)\") | join(\"\n\") | if ( . | length) != 0 then \"-H\" + . else \"-H \" end")
551+
if [[ -z $(jq -r '.testCases | select(. != null and . != {})' $FILE) ]];then
552+
echo "'testCases' is a required field in base object of a test file and must have atleast one test case."
553+
exit 1
554+
fi
555+
531556

532557
case $ACTION in
533558
run)

0 commit comments

Comments
 (0)