Improve test defs: setup_curl()

Replace setup_curl_7() function in separate test scripts with a single,
general setup_curl() function in testdefs.sh which takes the minimum
version number as its argument.
This commit is contained in:
Andrew Bettison 2013-10-14 16:48:20 +10:30
parent ef2cc1404c
commit eb46cc99b3
3 changed files with 31 additions and 27 deletions

View File

@ -732,3 +732,31 @@ has_seen_instances() {
instances_see_each_other() {
foreach_instance "$@" has_seen_instances "$@"
}
# Setup function:
# - ensure that the given version of the curl(1) utility is available
# - remove all proxy settings
setup_curl() {
local minversion="${1?}"
local ver="$(curl --version | tr '\n' ' ')"
case "$ver" in
'')
fail "curl(1) command is not present"
;;
curl\ *\ Protocols:*\ http\ *)
set -- $ver
tfw_cmp_version "$2" 7
case $? in
0|2)
unset http_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset ALL_PROXY
return 0
;;
esac
fail "curl(1) version $2 is not adequate (expecting $minversion or higher)"
;;
esac
fail "cannot parse output of curl --version: $ver"
}

View File

@ -46,18 +46,6 @@ configure_servald_server() {
set mdp.iftype.wifi.tick_ms 500
}
setup_curl_7() {
case "$(curl --version | tr '\n' ' ')" in
curl\ @(7|8|9|[1-9][0-1]).*\ Protocols:*\ http\ *) ;;
'') fail "curl(1) command is not present";;
*) fail "curl(1) version is not adequate (expecting 7 or higher)";;
esac
unset http_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset ALL_PROXY
}
setup_common() {
setup_servald
assert_no_servald_processes

View File

@ -47,18 +47,6 @@ configure_servald_server() {
set mdp.iftype.wifi.tick_ms 500
}
setup_curl_7() {
case "$(curl --version | tr '\n' ' ')" in
curl\ @(7|8|9|[1-9][0-1]).*\ Protocols:*\ http\ *) ;;
'') fail "curl(1) command is not present";;
*) fail "curl(1) version is not adequate (expecting 7 or higher)";;
esac
unset http_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset ALL_PROXY
}
setup_common() {
setup_servald
assert_no_servald_processes
@ -526,7 +514,7 @@ test_CorruptPayload() {
doc_HttpFetchRange="Fetch a file range using HTTP GET."
setup_HttpFetchRange() {
setup_curl_7
setup_curl 7
setup_common
set_instance +A
rhizome_add_file file1
@ -549,7 +537,7 @@ test_HttpFetchRange() {
doc_HttpImport="Import bundle using HTTP POST multi-part form."
setup_HttpImport() {
setup_curl_7
setup_curl 7
setup_common
cat >README.WHYNOTSIPS <<'EOF'
When we were looking at implementing secure calls for OpenBTS it was suggested
@ -599,7 +587,7 @@ test_HttpImport() {
doc_HttpAddLocal="Add file locally using HTTP, returns manifest"
setup_HttpAddLocal() {
setup_curl_7
setup_curl 7
setup_common
set_instance +A
executeOk_servald config \