diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2022-11-21 13:27:58 +0100 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2022-11-21 13:27:58 +0100 |
commit | 325bd9868711cfe8ed30b7d2e522de762baa192f (patch) | |
tree | 0655708ff34ec07ecb7561db095dd9ad3f4776bc | |
parent | 15d7b8dc21e77acc343a94d7869764caae7f497d (diff) | |
download | alpine-conf-325bd9868711cfe8ed30b7d2e522de762baa192f.zip |
setup-apkrepos: add test for fastest mirror (-f)
-rw-r--r-- | setup-apkrepos.in | 2 | ||||
-rwxr-xr-x | tests/bin/wget | 4 | ||||
-rwxr-xr-x | tests/setup_apkrepos_test | 12 |
3 files changed, 15 insertions, 3 deletions
diff --git a/setup-apkrepos.in b/setup-apkrepos.in index 9112295..5bd5417 100644 --- a/setup-apkrepos.in +++ b/setup-apkrepos.in @@ -57,7 +57,7 @@ find_fastest_mirror() { local arch="$(apk --print-arch)" for url in $MIRRORS; do # warm up the dns cache - nslookup $(get_hostname_from_url $url) >/dev/null 2>&1 + $MOCK nslookup $(get_hostname_from_url $url) >/dev/null 2>&1 local time="$(time_cmd wget --spider -q -T 5 -t 1 \ ${url%/}/edge/main/$arch/APKINDEX.tar.gz)" if [ -n "$time" ]; then diff --git a/tests/bin/wget b/tests/bin/wget index 77144b9..ad5f235 100755 --- a/tests/bin/wget +++ b/tests/bin/wget @@ -33,7 +33,7 @@ msg() { fi } -OPTS=$(getopt -l quiet,help,spider -o "qhO:" -n $prog -- "$@") || usage "1" >&2 +OPTS=$(getopt -l quiet,help,spider,timeout,tries -o "qhO:T:t:" -n $prog -- "$@") || usage "1" >&2 quiet= eval set -- "$OPTS" @@ -53,6 +53,8 @@ while true; do shift outfile="$1" ;; + -T|--timeout) shift;; + -t|--tries) shift;; --) shift break diff --git a/tests/setup_apkrepos_test b/tests/setup_apkrepos_test index ec0c349..f70b400 100755 --- a/tests/setup_apkrepos_test +++ b/tests/setup_apkrepos_test @@ -6,7 +6,8 @@ init_tests \ setup_apkrepos_exclusive_opts \ setup_apkrepos_https \ setup_apkrepos_random \ - setup_apkrepos_first + setup_apkrepos_first \ + setup_apkrepos_fastest setup_apkrepos_usage_body() { test_usage setup-apkrepos @@ -45,3 +46,12 @@ setup_apkrepos_first_body() { -o match:"Added mirror a0.example.com" \ setup-apkrepos -1 } + +setup_apkrepos_fastest_body() { + init_env + export WGETCONTENT="$(seq 0 9 | awk '{print "https://a" $0 ".example.com"}')" + atf_check -s exit:0 \ + -e match:"^[0-9].*example.com" \ + -o match:"Added mirror a[0-9].example.com" \ + setup-apkrepos -f +} |