commit df523f2befaf541f7a181a9b38151289b0a4176e
Author: Jim Meyering <meyering(a)redhat.com>
Date: Sat Aug 4 14:36:30 2012 +0200
tests: auto: fix false-positive rawhide failure due to curl difference
We were relying on the format of curl diagnostics.
For the delete-nonexistent test, curl-7.24 prints this:
curl: (22) The requested URL returned error: 404
but curl-7.27 appends the "Not Found":
curl: (22) The requested URL returned error: 404 Not Found
* t/auto: Don't rely on unspecified details of curl output: use curl's
--write-out option to explicitly print the HTTP return code to stdout,
and test that rather than the unspecified diagnostic.
Also, when waiting for mongo, don't rely on the "wait_for" function
evaluating our command, i.e., use double quotes, not single.
This makes our use of $m_port more future-proof.
* t/basic: Fix 10 more instances of the curl problem. The first two
by converting to use compare, leaving the remaining ones with grep,
since that is the more concise change.
t/auto | 9 ++++++---
t/basic | 43 ++++++++++++++++++++++---------------------
2 files changed, 28 insertions(+), 24 deletions(-)
---
diff --git a/t/auto b/t/auto
index 5f7092d..334810e 100755
--- a/t/auto
+++ b/t/auto
@@ -24,7 +24,7 @@ cleanup_() { kill $iwhd_pid; }
# Wait longer than usual (i.e., don't use wait_for_mongo), since this
# mongo daemon was started via iwhd itself, and not with $mongo_opt
-wait_for .1 300 'mongo localhost:$m_port < /dev/null' \
+wait_for .1 300 "mongo localhost:$m_port < /dev/null" \
|| framework_failure_ mongod failed to start
# Wait for up to 20 seconds for iwhd to begin listening on $port.
wait_for .1 200 "curl -s
http://localhost:$port" \
@@ -51,8 +51,11 @@ test "$(cat f1copy)" = foo || fail=1
curl -X DELETE
http://localhost:$port/b1/f1 || fail=1
# Ensure that it's gone from the file system.
test -f _fs/b1/f1 && fail=1
+
+curl_w() { curl --write-out '%{http_code}\n' "$@"; }
# Ensure that it's gone in the API as well.
-curl -f
http://localhost:$port/b1/f1 > /dev/null 2> del_object.err
-grep ' 404$' del_object.err || fail=1
+curl_w -f
http://localhost:$port/b1/f1 > del_object.err
+echo 404 > exp || fail=1
+compare exp del_object.err || fail=1
Exit $fail
diff --git a/t/basic b/t/basic
index 6e8c083..8952893 100755
--- a/t/basic
+++ b/t/basic
@@ -22,6 +22,7 @@ mongod --help > /dev/null || fail_ "the mongod program is not
installed"
mongod $mongo_opt --port $m_port --pidfilepath mongod/pid --dbpath mongod &
mongo_pid=$!
cleanup_() { kill -9 $mongo_pid; }
+curl_w() { curl --write-out '%{http_code}\n' "$@"; }
# Wait for mongod to begin listening.
wait_for_mongo $m_port \
@@ -75,12 +76,12 @@ curl -X PUT $bucket || fail=1
test -d FS/b1 || fail=1
# Try to create a duplicate bucket.
-curl -f -X PUT $bucket 2> dup_bucket.err
-grep ' 500$' dup_bucket.err || fail=1
+curl_w -f -X PUT $bucket > dup_bucket.err; echo 500 > exp || fail=1
+compare exp dup_bucket.err || fail=1
# PUT to root; should fail
-curl -f -X PUT
http://localhost:$port 2> root_put.err
-grep ' 404$' root_put.err || fail=1
+curl_w -f -X PUT
http://localhost:$port > root_put.err; echo 404 > exp || fail=1
+compare exp root_put.err || fail=1
# Create a file in that bucket.
echo foo | curl -T - $bucket/obj_test || fail=1
@@ -92,8 +93,8 @@ curl $bucket/obj_test > f1copy
test "$(cat f1copy)" = foo || fail=1
# Test that non-existing bucket gives 404 and not 500 or even 200 as before.
-curl -f
http://localhost:$port/no_bucket 2> no_bucket.err
-grep ' 404$' no_bucket.err || fail=1
+curl_w -f
http://localhost:$port/no_bucket > no_bucket.err
+grep '^404$' no_bucket.err || fail=1
# Get root; default, then Accept: XML & JSON:
curl
http://localhost:$port > root || fail=1
@@ -110,17 +111,17 @@ curl -X DELETE $bucket/obj_test || fail=1
# Ensure that it's gone from the file system.
test -f FS/b1/obj_test && fail=1
# Ensure that it's gone in the API as well.
-curl -f $bucket/obj_test > /dev/null 2> del_object.err
-grep ' 404$' del_object.err || fail=1
+curl_w -f $bucket/obj_test > /dev/null > del_object.err
+grep '^404$' del_object.err || fail=1
# Try to delete a nonexistent object.
-curl -f -X DELETE $bucket/no-such-obj 2> del_nosuch.err
-grep ' 404$' del_nosuch.err || fail=1
+curl_w -f -X DELETE $bucket/no-such-obj > del_nosuch.err
+grep '^404$' del_nosuch.err || fail=1
# Make sure the X-redhat-role header causes failure on a master iwhd.
-echo hello | curl -f -T - -H "X-redhat-role: master" $bucket/role_test \
- 2> role.err
-grep ' 403$' role.err || fail=1
+echo hello | curl_w -f -T - -H "X-redhat-role: master" $bucket/role_test \
+ > role.err
+grep '^403$' role.err || fail=1
# ################## Providers
@@ -236,13 +237,13 @@ compare exp-attr-xml out-attr-deprecated || fail=1
# FIXME: keep this list in sync with the one in rest.c:
# grep '^static.*reserved_name' rest.c
for obj_name in _default _new _policy _query; do
- echo reserved-obj-name | curl -f -T - $bucket/$obj_name 2> bad_oname.err
+ echo reserved-obj-name | curl_w -f -T - $bucket/$obj_name > bad_oname.err
# _query evokes 404. all others evoke 403
case $obj_name in
_query) exp=404;;
*) exp=403;;
esac
- grep " $exp\$" bad_oname.err || fail=1
+ grep "^$exp\$" bad_oname.err || fail=1
done
# Keep this list of reserved words in sync with the one in rest.c:
@@ -264,8 +265,8 @@ for attr in $attr_words; do
*) exp=400;;
esac
- printf whatever | curl -f -T - $bucket/rsvd_attr/$attr 2> bad_attr.err
- grep " $exp$" bad_attr.err \
+ printf whatever | curl_w -f -T - $bucket/rsvd_attr/$attr > bad_attr.err
+ grep "^$exp$" bad_attr.err \
|| fail_ "expected ...$exp; got this: $(cat bad_attr.err)"
done
@@ -274,14 +275,14 @@ done
# grep '^static.*reserved_bucket_name' rest.c
for b in _new _providers; do
invalid_bucket=http://localhost:$port/$b
- curl -f -X PUT $invalid_bucket 2> invalid_bucket.err
+ curl_w -f -X PUT $invalid_bucket > invalid_bucket.err
# FIXME: change the code so that these are the same
case $b in
_new) exp=400;; # MHD_HTTP_BAD_REQUEST
*) exp=404;;
esac
cat invalid_bucket.err
- grep " $exp\$" invalid_bucket.err || fail=1
+ grep "^$exp\$" invalid_bucket.err || fail=1
done
# Make sure PUTting a file truncates.
@@ -324,10 +325,10 @@ curl
http://localhost:$port/_providers > p || fail=1
grep PROVIDER-2 p && { warn_ $ME_: provider deletion failed; fail=1; }
# Delete a non-existent provider.
-curl -f -X DELETE
http://localhost:$port/_providers/no-such 2> p
+curl_w -f -X DELETE
http://localhost:$port/_providers/no-such > p
# ensure it fails; expect exit-22 and http: 404
test $? = 22 || fail=1
-grep ' 404$' p || fail=1
+grep '^404$' p || fail=1
# Get the name of the current primary provider.
curl
http://localhost:$port/_providers/_primary > p || fail=1