summaryrefslogtreecommitdiff
path: root/test/scripts/e2e_subs/rest.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test/scripts/e2e_subs/rest.sh')
-rwxr-xr-xtest/scripts/e2e_subs/rest.sh185
1 files changed, 176 insertions, 9 deletions
diff --git a/test/scripts/e2e_subs/rest.sh b/test/scripts/e2e_subs/rest.sh
index fab6f1d51..4613a7ba9 100755
--- a/test/scripts/e2e_subs/rest.sh
+++ b/test/scripts/e2e_subs/rest.sh
@@ -35,21 +35,155 @@ function base_call {
}
+function base_post_call {
+ curl -X POST --data-binary @/${TEMPDIR}/$4 -o "$3" -w "%{http_code}" -q -s -H "Authorization: Bearer $1" "$NET$2"
+}
+
+
+function base_delete_call {
+ curl -X DELETE -o "$3" -w "%{http_code}" -q -s -H "Authorization: Bearer $1" "$NET$2"
+}
+
function call_admin {
base_call "$ADMIN_TOKEN" "$1" "$2"
}
+function call_post_admin {
+ base_post_call "$ADMIN_TOKEN" "$1" "$2" "$3"
+}
+
+function call_delete_admin {
+ base_delete_call "$ADMIN_TOKEN" "$1" "$2" "$3"
+}
function call {
base_call "$PUB_TOKEN" "$1" "$2"
}
+function call_post {
+ base_post_call "$PUB_TOKEN" "$1" "$2"
+}
+
+function call_delete {
+ base_delete_call "$PUB_TOKEN" "$1" "$2"
+}
+
function fail_and_exit {
printf "\n\nFailed test - $1 ($2): $3\n\n"
exit 1
}
+# $1 - test description.
+# $2 - query
+# $3 - expected status code
+# $4 - the file to upload
+# $5... - substring that should be in the response
+function call_post_and_verify {
+ local DESCRIPTION="$1"
+ shift
+ local QUERY="$1"
+ shift
+ local EXPECTED_CODE="$1"
+ shift
+ local FILENAME_TO_UPLOAD="$1"
+ shift
+
+ echo "MATCHING $@"
+ curl_post_test "$DESCRIPTION" "$QUERY" "$EXPECTED_CODE" true "$FILENAME_TO_UPLOAD" "$@"
+}
+
+
+# CURL POST Test - POST query and verify results
+# $1 - test description.
+# $2 - query
+# $3 - expected status code
+# $4 - match result
+# $5 - the file to upload
+# $6... - substring(s) that should be in the response
+function curl_post_test {
+ local DESCRIPTION="$1"
+ shift
+ local QUERY="$1"
+ shift
+ local EXPECTED_CODE="$1"
+ shift
+ local MATCH_RESULT="$1"
+ shift
+ local FILENAME_TO_UPLOAD="$1"
+ shift
+
+ set +e
+ local CODE
+ if [[ "$USE_ADMIN" = true ]]; then
+ CODE=$(call_post_admin "$QUERY" "${TEMPDIR}/curl_out.txt" "$FILENAME_TO_UPLOAD")
+ else
+ CODE=$(call_post "$QUERY" "${TEMPDIR}/curl_out.txt" "$FILENAME_TO_UPLOAD")
+ fi
+
+ verify $? "$CODE" "$DESCRIPTION" "$QUERY" "$EXPECTED_CODE" "$MATCH_RESULT" "$@"
+
+}
+
+# CURL Test - query and verify results
+# $1 - test description.
+# $2 - query
+# $3 - expected status code
+# $4 - match result
+function call_delete_and_verify {
+ local DESCRIPTION="$1"
+ shift
+ local QUERY="$1"
+ shift
+ local EXPECTED_CODE="$1"
+ shift
+
+ local MATCH_RESULT="$1"
+ shift
+
+ set +e
+
+ local CODE
+ if [[ "$USE_ADMIN" = true ]]; then
+ CODE=$(call_delete_admin "$QUERY" "${TEMPDIR}/curl_out.txt")
+ else
+ CODE=$(call_delete "$QUERY" "${TEMPDIR}/curl_out.txt" )
+ fi
+
+ verify $? "$CODE" "$DESCRIPTION" "$QUERY" "$EXPECTED_CODE" "$MATCH_RESULT" "$@"
+
+}
+
+
+# CURL Test - query and verify results
+# $1 - test description.
+# $2 - query
+# $3 - expected status code
+# $4 - match result
+# $5... - substring(s) that should be in the response
+function curl_test {
+ local DESCRIPTION="$1"
+ shift
+ local QUERY="$1"
+ shift
+ local EXPECTED_CODE="$1"
+ shift
+ local MATCH_RESULT="$1"
+ shift
+
+ set +e
+
+ local CODE
+ if [[ "$USE_ADMIN" = true ]]; then
+ CODE=$(call_admin "$QUERY" "${TEMPDIR}/curl_out.txt")
+ else
+ CODE=$(call "$QUERY" "${TEMPDIR}/curl_out.txt" )
+ fi
+
+ verify $? "$CODE" "$DESCRIPTION" "$QUERY" "$EXPECTED_CODE" "$MATCH_RESULT" "$@"
+
+}
+
# $1 - test description.
# $2 - query
@@ -67,7 +201,7 @@ function call_and_verify {
curl_test "$DESCRIPTION" "$QUERY" "$EXPECTED_CODE" true "$@"
}
-# CURL Test - query and veryify results
+# CURL Test - query and verify results
# $1 - test description.
# $2 - query
# $3 - expected status code
@@ -82,16 +216,52 @@ function curl_test {
shift
local MATCH_RESULT="$1"
shift
- local SUBSTRING
-
- local START=$SECONDS
set +e
- local CODE=$(call "$QUERY" "${TEMPDIR}/curl_out.txt")
+
+ local CODE
+ if [[ "$USE_ADMIN" = true ]]; then
+ CODE=$(call_admin "$QUERY" "${TEMPDIR}/curl_out.txt")
+ else
+ CODE=$(call "$QUERY" "${TEMPDIR}/curl_out.txt" )
+ fi
+
if [[ $? != 0 ]]; then
cat $CURL_TEMPFILE
fail_and_exit "$DESCRIPTION" "$QUERY" "curl had a non-zero exit code."
fi
+
+ verify $? "$CODE" "$DESCRIPTION" "$QUERY" "$EXPECTED_CODE" "$MATCH_RESULT" "$@"
+
+}
+
+# verify - Common verification code
+# $1 - return code of CURL sub-shell command
+# $2 - HTTP status code
+# $3 - description of test
+# $4 - query to execute
+# $5 - expected HTTP status code to check
+# $6 - match result
+# $7... - substring(s) that should be in the response
+function verify {
+ local SUCCESS=$1
+ shift
+ local CODE=$1
+ shift
+ local DESCRIPTION="$1"
+ shift
+ local QUERY="$1"
+ shift
+ local EXPECTED_CODE="$1"
+ shift
+ local MATCH_RESULT="$1"
+ shift
+
+ if [[ $SUCCESS != 0 ]]; then
+ cat $CURL_TEMPFILE
+ fail_and_exit "$DESCRIPTION" "$QUERY" "curl had a non-zero exit code."
+ fi
+
set -e
RES=$(cat "${TEMPDIR}/curl_out.txt")
@@ -99,10 +269,7 @@ function curl_test {
fail_and_exit "$DESCRIPTION" "$QUERY" "unexpected HTTP status code expected $EXPECTED_CODE (actual $CODE): $RES"
fi
- #local ELAPSED=$(($SECONDS - $START))
- #if [[ $ELAPSED -gt $MAX_TIME ]]; then
- # fail_and_exit "$DESCRIPTION" "$QUERY" "query duration too long, $ELAPSED > $MAX_TIME"
- #fi
+ local SUBSTRING
# Check result substrings
for SUBSTRING in "$@"; do