summaryrefslogtreecommitdiff
path: root/test/apiv2/test-apiv2
diff options
context:
space:
mode:
Diffstat (limited to 'test/apiv2/test-apiv2')
-rwxr-xr-xtest/apiv2/test-apiv251
1 files changed, 33 insertions, 18 deletions
diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2
index 2f01783ff..78325eb24 100755
--- a/test/apiv2/test-apiv2
+++ b/test/apiv2/test-apiv2
@@ -111,6 +111,14 @@ function _show_ok() {
_bump $testcounter_file
count=$(<$testcounter_file)
+
+ # "skip" is a special case of "ok". Assume that our caller has included
+ # the magical '# skip - reason" comment string.
+ if [[ $ok == "skip" ]]; then
+ # colon-plus: replace green with yellow, but only if green is non-null
+ green="${green:+\e[33m}"
+ ok=1
+ fi
if [ $ok -eq 1 ]; then
echo -e "${green}ok $count ${TEST_CONTEXT} $testname${reset}"
echo "ok $count ${TEST_CONTEXT} $testname" >>$LOG
@@ -125,7 +133,7 @@ function _show_ok() {
echo -e "${red}# actual: ${bold}$actual${reset}"
echo "not ok $count ${TEST_CONTEXT} $testname" >>$LOG
- echo " expected: $expect"
+ echo " expected: $expect" >>$LOG
_bump $failures_file
}
@@ -241,27 +249,34 @@ function t() {
fi
local i
+
+ # Special case: if response code does not match, dump the response body
+ # and skip all further subtests.
+ if [[ $actual_code != $expected_code ]]; then
+ echo -e "# response: $output"
+ for i; do
+ _show_ok skip "$testname: $i # skip - wrong return code"
+ done
+ return
+ fi
+
for i; do
- case "$i" in
+ if expr "$i" : "[^=~]\+=.*" >/dev/null; then
# Exact match on json field
- *=*)
- json_field=$(expr "$i" : "\([^=]*\)=")
- expect=$(expr "$i" : '[^=]*=\(.*\)')
- actual=$(jq -r "$json_field" <<<"$output")
- is "$actual" "$expect" "$testname : $json_field"
- ;;
+ json_field=$(expr "$i" : "\([^=]*\)=")
+ expect=$(expr "$i" : '[^=]*=\(.*\)')
+ actual=$(jq -r "$json_field" <<<"$output")
+ is "$actual" "$expect" "$testname : $json_field"
+ elif expr "$i" : "[^=~]\+~.*" >/dev/null; then
# regex match on json field
- *~*)
- json_field=$(expr "$i" : "\([^~]*\)~")
- expect=$(expr "$i" : '[^~]*~\(.*\)')
- actual=$(jq -r "$json_field" <<<"$output")
- like "$actual" "$expect" "$testname : $json_field"
- ;;
+ json_field=$(expr "$i" : "\([^~]*\)~")
+ expect=$(expr "$i" : '[^~]*~\(.*\)')
+ actual=$(jq -r "$json_field" <<<"$output")
+ like "$actual" "$expect" "$testname : $json_field"
+ else
# Direct string comparison
- *)
- is "$output" "$i" "$testname : output"
- ;;
- esac
+ is "$output" "$i" "$testname : output"
+ fi
done
}