From a6c7c8e7c7861d275018d7eb49b5f1383a1639a5 Mon Sep 17 00:00:00 2001 From: dcarrillo Date: Sun, 15 Dec 2019 18:45:41 +0100 Subject: [PATCH] Refactor tests --- tests/nginx.conf | 2 +- tests/test.sh | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/nginx.conf b/tests/nginx.conf index eaee28c..2f3a490 100644 --- a/tests/nginx.conf +++ b/tests/nginx.conf @@ -69,7 +69,7 @@ http { server_name _ ""; access_log /dev/fd/1; - location = /geoip { + location = /ip { limit_req zone=limited4 burst=5 nodelay; if ($http_user_agent ~* (?:curl|wget|libwww-perl|python|ansible-httpget|HTTPie|WindowsPowerShell|http_request|^$)) { return 200 "$remote_addr\n"; diff --git a/tests/test.sh b/tests/test.sh index e143fa9..3207875 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -2,6 +2,10 @@ set -e +if [ x"$DEBUG" = xtrue ]; then + set -x +fi + trap _catch_err ERR trap _cleanup EXIT @@ -63,16 +67,14 @@ docker run --name "${NGINX_VERSION}"_test --rm -p 65521:80 -p 65523:443 \ -v "$TMP_DIR"/dhparams.pem:/tmp/dhparams.pem:ro \ -d "${DOCKER_IMAGE}":"${NGINX_VERSION}" -printf "\nTesting http request: %s:%s\n" "${DOCKER_IMAGE}" "${NGINX_VERSION}" -STATUS_CODE=$(curl -s -m 5 -o /dev/null -w "%{http_code}" http://localhost:65521/nginx_status) -_check_status_code "$STATUS_CODE" +for request in http://localhost:65521/nginx_status https://localhost:65523/nginx_status; do + printf "\nRequesting %s\n" $request + STATUS_CODE=$(curl -s -k -m 5 -o /dev/null -w "%{http_code}" $request) + _check_status_code "$STATUS_CODE" +done -printf "\nTesting https request: %s:%s\n" "${DOCKER_IMAGE}" "${NGINX_VERSION}" -STATUS_CODE=$(curl -s -m 5 -o /dev/null -w "%{http_code}" --http2 -k https://localhost:65523/) -_check_status_code "$STATUS_CODE" - -printf "\nTesting http geoip request: %s:%s\n" "${DOCKER_IMAGE}" "${NGINX_VERSION}" -RESPONSE=$(curl -s -m 5 http://localhost:65521/geoip) +printf "\nRequesting http://localhost:65521/ip\n" +RESPONSE=$(curl -s -m 5 http://localhost:65521/ip) _check_if_is_ip "$RESPONSE" echo "All tests succeeded !"