Skip to content

Commit 06bb0ff

Browse files
committed
Add describe command and bump service version
1 parent 48075d6 commit 06bb0ff

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

api-test.sh

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -o pipefail
33

4-
VERSION='0.2.0'
4+
VERSION='0.3.0'
55
RED=$(tput setaf 1)
66
GREEN=$(tput setaf 2)
77
BOLD=$(tput bold)
@@ -416,6 +416,7 @@ path_checker() {
416416
done
417417
}
418418

419+
# run command
419420
run() {
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
456459
test() {
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
488505
for 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
515532
done
516533

534+
# Check for dependency programs
517535
command -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
541558
fi
542559

543-
jq empty $FILE
560+
jq empty $FILE
544561

545562
if [ $? -ne 0 ]; then
546563
exit 1
547564
fi
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+
550573
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
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
554578
fi
555579

556-
557580
case $ACTION in
558581
run)
559582
run $@
560583
;;
561584
test) test $@ ;;
585+
describe) describe $@ ;;
562586
*)
563587
usage
564588
;;

0 commit comments

Comments
 (0)