commit 01f29225519b391f7ee15ffd0559f0d830f9bb21
parent e21915da3005be4b214e7f16170212461466c6c5
Author: Wim Dupont <wim@wimdupont.com>
Date: Sun, 19 Mar 2023 01:14:40 +0100
testscript in loop
Diffstat:
1 file changed, 45 insertions(+), 43 deletions(-)
diff --git a/src/test/resources/play.sh b/src/test/resources/play.sh
@@ -13,13 +13,7 @@ done
shift $((OPTIND-1))
-method=$1
-id=$2
-
-if [ -z "${method}" ]; then
- echo "Request method? (GET/POST/PUT/DELETE)"
- read -r method
-fi
+id=$1
get_id () {
if [ -z "${id}" ]; then
@@ -38,42 +32,50 @@ get_url () {
request=
-case ${method^^} in
-
- GET)
- get_id
- if [ -z "${id}" ]; then
- request=$(curl -X GET -sw '%{http_code}' $(get_url))
- else
- request=$(curl -X GET -sw '%{http_code}' $(get_url "/${id}") | jq)
- fi
- ;;
-
- POST)
- request=$(curl -X POST -sw '%{http_code}' $(get_url) -H 'Content-Type: application/json' -d '{"name":"Created John","number":120}' | jq)
- ;;
-
- PUT)
- get_id
- request=$(curl -X PUT -sw '%{http_code}' $(get_url "/${id}") -H 'Content-Type: application/json' -d '{"name":"Updated John","number":166}' | jq)
- ;;
-
- DELETE)
- get_id
- request=$(curl -k -X 'DELETE' -sw '%{http_code}' $(get_url "/${id}") | jq)
- ;;
-
- *)
- echo "Unknown http method."
- ;;
-esac
-
-echo "${request}"
-retrieved_id=$(echo "${request}" | jq "try .[0].id catch \"JQ_ERROR\"" | head -n 1 | tr -d \")
+while [[ "${method}" != @(q|quit|e|exit) ]]
+do
+ echo "Request method? (GET/POST/PUT/DELETE) - q, quit, e, or exit to quit."
+ read -r method
-if [ "${retrieved_id}" == "JQ_ERROR" ]; then
- retrieved_id=$(echo "${request}" | jq "try .id catch \"JQ_ERROR\"" | head -n 1 | tr -d \")
-fi
+ case ${method^^} in
+
+ GET)
+ get_id
+ if [ -z "${id}" ]; then
+ request=$(curl -X GET -sw '%{http_code}' $(get_url) | jq)
+ else
+ request=$(curl -X GET -sw '%{http_code}' $(get_url "/${id}") | jq)
+ fi
+ ;;
+
+ POST)
+ request=$(curl -X POST -sw '%{http_code}' $(get_url) -H 'Content-Type: application/json' -d '{"name":"Created John","number":120}' | jq)
+ ;;
+
+ PUT)
+ get_id
+ request=$(curl -X PUT -sw '%{http_code}' $(get_url "/${id}") -H 'Content-Type: application/json' -d '{"name":"Updated John","number":166}' | jq)
+ ;;
+
+ DELETE)
+ get_id
+ request=$(curl -k -X 'DELETE' -sw '%{http_code}' $(get_url "/${id}") | jq)
+ ;;
+
+ *)
+ echo "Unknown http method."
+ ;;
+ esac
+
+ echo ${method^^}
+ echo "${request}"
+ retrieved_id=$(echo "${request}" | jq "try .[0].id catch \"JQ_ERROR\"" | head -n 1 | tr -d \")
+
+ if [ "${retrieved_id}" == "JQ_ERROR" ]; then
+ retrieved_id=$(echo "${request}" | jq "try .id catch \"JQ_ERROR\"" | head -n 1 | tr -d \")
+ fi
-echo "${retrieved_id}" | xclip
+ echo "${retrieved_id}" | xclip
+ id=
+done