From eb46cc99b38f678f9a5d0f3d1f3ee65a5db58dc7 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Mon, 14 Oct 2013 16:48:20 +1030 Subject: [PATCH] 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. --- testdefs.sh | 28 ++++++++++++++++++++++++++++ tests/rhizomechannels | 12 ------------ tests/rhizomeprotocol | 18 +++--------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/testdefs.sh b/testdefs.sh index 791c7fb3..4196e03e 100644 --- a/testdefs.sh +++ b/testdefs.sh @@ -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" +} diff --git a/tests/rhizomechannels b/tests/rhizomechannels index 48c40a07..330e3afb 100755 --- a/tests/rhizomechannels +++ b/tests/rhizomechannels @@ -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 diff --git a/tests/rhizomeprotocol b/tests/rhizomeprotocol index 0f4663b3..6f58a43b 100755 --- a/tests/rhizomeprotocol +++ b/tests/rhizomeprotocol @@ -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 \