11#! /bin/bash
22set -o pipefail
33
4- VERSION=' 0.2 .0'
4+ VERSION=' 0.3 .0'
55RED=$( tput setaf 1)
66GREEN=$( tput setaf 2)
77BOLD=$( tput bold)
@@ -416,6 +416,7 @@ path_checker() {
416416 done
417417}
418418
419+ # run command
419420run () {
420421 for arg in " $@ " ; do
421422 case $arg in
@@ -447,27 +448,17 @@ run() {
447448 all)
448449 api_factory " $( jq -r ' .testCases | keys[]' $FILE ) "
449450 ;;
451+ ' ' ) usage run ;;
450452 * )
451453 api_factory $@
452454 ;;
453455 esac
454456}
455457
458+ # test command
456459test () {
457460 for arg in " $@ " ; do
458461 case $arg in
459- -i | --include)
460- SHOW_HEADER=1
461- shift
462- ;;
463- -I | --header-only)
464- HEADER_ONLY=1
465- shift
466- ;;
467- -s | --silent)
468- SILENT=1
469- shift
470- ;;
471462 -h | --help)
472463 usage test
473464 exit
@@ -479,15 +470,41 @@ test() {
479470 all)
480471 test_factory " $( jq -r ' .testCases | keys[]' $FILE ) "
481472 ;;
473+ ' ' )
474+ usage test
475+ ;;
482476 * )
483477 test_factory $@
484478 ;;
485479 esac
486480}
487481
482+ # describe command
483+ describe () {
484+ for arg in " $@ " ; do
485+ case $arg in
486+ -h | --help)
487+ usage describe
488+ exit
489+ ;;
490+ esac
491+ done
492+
493+ case $1 in
494+ ' ' )
495+ echo -e " S.N.\tTest case"
496+ jq -r ' .testCases | keys[]' $FILE | awk ' {print NR "\t" $0}'
497+ ;;
498+ * )
499+ jq -r " .testCases | .$1 | .$2 ?" $FILE
500+ ;;
501+ esac
502+ }
503+
504+ # INIT COMMANDS AND CHECKS
488505for arg in " $@ " ; do
489506 case $arg in
490- run | test)
507+ run | test | describe )
491508 ACTION=" $1 "
492509 shift
493510 break
@@ -514,6 +531,7 @@ for arg in "$@"; do
514531 esac
515532done
516533
534+ # Check for dependency programs
517535command -v curl > /dev/null 2>&1 || {
518536 echo >&2 " This program requires 'curl' to run. Please install 'curl'"
519537 exit 1
@@ -537,28 +555,34 @@ if [ ! -f "$FILE" ]; then
537555 echo " Please provide an existing file."
538556 exit 1
539557 fi
540- echo $FILE
541558fi
542559
543- jq empty $FILE
560+ jq empty $FILE
544561
545562if [ $? -ne 0 ]; then
546563 exit 1
547564fi
548565
549- URL=$( jq -r ' .url' $FILE )
566+ # Check if url is present
567+ URL=$( jq -r ' .url | select( . != null)' $FILE )
568+ if [[ -z $URL ]]; then
569+ echo " 'url' is a required field in base object of a test file and must be a string."
570+ exit 1
571+ fi
572+
550573COMMON_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
574+ # Check if test cases is present
575+ if [[ -z $( jq -r ' .testCases | select(. != null and . != {})' $FILE ) ]]; then
552576 echo " 'testCases' is a required field in base object of a test file and must have atleast one test case."
553577 exit 1
554578fi
555579
556-
557580case $ACTION in
558581run)
559582 run $@
560583 ;;
561584test) test $@ ;;
585+ describe) describe $@ ;;
562586* )
563587 usage
564588 ;;
0 commit comments