Skip to content

Commit

Permalink
CI: fixed templates-resolver-ipv6 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
thresheek committed Feb 7, 2024
1 parent a06a168 commit e230e12
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .test/tests/templates-resolver-ipv6/expected-std-out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
example.com - OK
ipv6 nameserver(s) present
29 changes: 25 additions & 4 deletions .test/tests/templates-resolver-ipv6/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ fi

# Create a new Docker network
nid="$(docker network create --ipv6 --subnet fd0c:7e57::/64 nginx-test-ipv6-network)"
trap "docker network rm -f $nid > /dev/null" EXIT

_network_exit_handler() {
docker network rm -f $nid > /dev/null
}

# Create an instance of the container-under-test
serverImage="$("$HOME/oi/test/tests/image-name.sh" librarytest/nginx-template "$image")"
Expand All @@ -30,7 +33,14 @@ FROM $image
COPY dir/server.conf.template /etc/nginx/templates/server.conf.template
EOD
cid="$(docker run -d --network $nid -e NGINX_ENTRYPOINT_LOCAL_RESOLVERS=true -e NGINX_MY_SERVER_NAME=example.com "$serverImage")"
trap "docker rm -vf $cid > /dev/null" EXIT

_container_exit_handler() {
docker rm -vf $cid > /dev/null
}
_exit_handler() { _container_exit_handler; _network_exit_handler; }
trap "_exit_handler" EXIT

ipv6cid="$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.GlobalIPv6Address}}{{end}}' $cid)"

_request() {
local method="$1"
Expand All @@ -49,12 +59,23 @@ _request() {
fi

docker run --rm \
--link "$cid":nginx \
--network "$nid" \
"$clientImage" \
curl -fsSL -X"$method" --connect-to '::nginx:' "$@" "$proto://example.com/$url"
curl -fsSL -X"$method" --connect-to "::[$ipv6cid]:" "$@" "$proto://example.com/$url"
}

. "$HOME/oi/test/retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'

# Check that we can request /
_request GET http '/resolver-templates' | grep 'example.com - OK'

result="$(docker exec $cid grep resolver /etc/nginx/conf.d/server.conf)"

case "$result" in
resolver*\[*\]*)
echo "ipv6 nameserver(s) present"
;;
*)
echo "no ipv6 nameserver(s) present"
;;
esac
1 change: 1 addition & 0 deletions .test/tests/templates-resolver-ipv6/server.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ resolver ${NGINX_LOCAL_RESOLVERS};

server {
listen 80;
listen [::]:80;
server_name ${NGINX_MY_SERVER_NAME};
default_type text/plain;
location = / { return 200 'OK\n'; }
Expand Down

0 comments on commit e230e12

Please sign in to comment.