mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 17:58:16 +00:00
commit
1775420592
@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
###############################################################################
|
||||
# #
|
||||
# This script is meant to run the test suite from a Docker container. #
|
||||
@ -9,17 +9,20 @@
|
||||
###############################################################################
|
||||
|
||||
# Returns the absolute directory path to this script
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
ARGS=("$@")
|
||||
TESTDIR=$(cd "${0%/*}" && pwd) || exit 1
|
||||
DIR=$(cd "${TESTDIR}/.." && pwd) || exit 1
|
||||
|
||||
# check requirements
|
||||
echo "> Building nginx-proxy-tester image..."
|
||||
docker build -t nginx-proxy-tester -f "${DIR}/requirements/Dockerfile-nginx-proxy-tester" "${DIR}/requirements"
|
||||
docker build -t nginx-proxy-tester \
|
||||
-f "${TESTDIR}/requirements/Dockerfile-nginx-proxy-tester" \
|
||||
"${TESTDIR}/requirements" \
|
||||
|| exit 1
|
||||
|
||||
# run the nginx-proxy-tester container setting the correct value for the working dir in order for
|
||||
# docker-compose to work properly when run from within that container.
|
||||
exec docker run --rm -it --name "nginx-proxy-pytest" \
|
||||
--volume "/var/run/docker.sock:/var/run/docker.sock" \
|
||||
--volume "${DIR}:${DIR}" \
|
||||
--workdir "${DIR}" \
|
||||
nginx-proxy-tester "${ARGS[@]}"
|
||||
--workdir "${TESTDIR}" \
|
||||
nginx-proxy-tester "$@"
|
||||
|
@ -3,10 +3,10 @@ import re
|
||||
|
||||
def test_debug_info_is_present_in_nginx_generated_conf(docker_compose, nginxproxy):
|
||||
conf = nginxproxy.get_conf().decode('ASCII')
|
||||
assert re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+80\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+81\s+tcp \}\]", conf) or \
|
||||
re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+81\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+80\s+tcp \}\]", conf)
|
||||
assert re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+82\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+83\s+tcp \}\]", conf) or \
|
||||
re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+83\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+82\s+tcp \}\]", conf)
|
||||
assert re.search(r"# Exposed ports: \[\{[^}]+\s+80\s+tcp \} \{[^}]+\s+81\s+tcp \}\]", conf) or \
|
||||
re.search(r"# Exposed ports: \[\{[^}]+\s+81\s+tcp \} \{[^}]+\s+80\s+tcp \}\]", conf)
|
||||
assert re.search(r"# Exposed ports: \[\{[^}]+\s+82\s+tcp \} \{[^}]+\s+83\s+tcp \}\]", conf) or \
|
||||
re.search(r"# Exposed ports: \[\{[^}]+\s+83\s+tcp \} \{[^}]+\s+82\s+tcp \}\]", conf)
|
||||
assert "# Default virtual port: 80" in conf
|
||||
assert "# VIRTUAL_PORT: 82" in conf
|
||||
assert conf.count("# /!\\ Virtual port not exposed") == 1
|
||||
|
@ -3,6 +3,6 @@ import re
|
||||
|
||||
def test_debug_info_is_present_in_nginx_generated_conf(docker_compose, nginxproxy):
|
||||
conf = nginxproxy.get_conf().decode('ASCII')
|
||||
assert re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+80\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+81\s+tcp \}\]", conf) or \
|
||||
re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+81\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+80\s+tcp \}\]", conf)
|
||||
assert re.search(r"# Exposed ports: \[\{[^}]+\s+80\s+tcp \} \{[^}]+\s+81\s+tcp \}\]", conf) or \
|
||||
re.search(r"# Exposed ports: \[\{[^}]+\s+81\s+tcp \} \{[^}]+\s+80\s+tcp \}\]", conf)
|
||||
assert conf.count("# Exposed ports: [{") == 1
|
||||
|
@ -1,41 +1,9 @@
|
||||
import os
|
||||
import docker
|
||||
import logging
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def nginx_tmpl():
|
||||
"""
|
||||
pytest fixture which extracts the the nginx config template from
|
||||
the nginxproxy/nginx-proxy:test image
|
||||
"""
|
||||
script_dir = os.path.dirname(__file__)
|
||||
logging.info("extracting nginx.tmpl from nginxproxy/nginx-proxy:test")
|
||||
docker_client = docker.from_env()
|
||||
print(
|
||||
docker_client.containers.run(
|
||||
image="nginxproxy/nginx-proxy:test",
|
||||
remove=True,
|
||||
volumes=["{current_dir}:{current_dir}".format(current_dir=script_dir)],
|
||||
entrypoint="sh",
|
||||
command='-xc "cp /app/nginx.tmpl {current_dir} && chmod 777 {current_dir}/nginx.tmpl"'.format(
|
||||
current_dir=script_dir
|
||||
),
|
||||
stderr=True,
|
||||
)
|
||||
)
|
||||
yield
|
||||
logging.info("removing nginx.tmpl")
|
||||
os.remove(os.path.join(script_dir, "nginx.tmpl"))
|
||||
|
||||
|
||||
def test_unknown_virtual_host_is_503(nginx_tmpl, docker_compose, nginxproxy):
|
||||
def test_unknown_virtual_host_is_503(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://unknown.nginx.container.docker/")
|
||||
assert r.status_code == 503
|
||||
|
||||
|
||||
def test_forwards_to_whoami(nginx_tmpl, docker_compose, nginxproxy):
|
||||
def test_forwards_to_whoami(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://whoami.nginx.container.docker/")
|
||||
assert r.status_code == 200
|
||||
whoami_container = docker_compose.containers.get("whoami")
|
||||
|
@ -14,7 +14,7 @@ services:
|
||||
- nginx
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl
|
||||
- ../../nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl
|
||||
|
||||
web:
|
||||
image: web
|
||||
|
@ -1,8 +1,5 @@
|
||||
import os
|
||||
import docker
|
||||
import logging
|
||||
import pytest
|
||||
import re
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
|
||||
@ -13,38 +10,12 @@ pytestmark = pytest.mark.skipif(
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def nginx_tmpl():
|
||||
"""
|
||||
pytest fixture which extracts the the nginx config template from
|
||||
the nginxproxy/nginx-proxy:test image
|
||||
"""
|
||||
script_dir = os.path.dirname(__file__)
|
||||
logging.info("extracting nginx.tmpl from nginxproxy/nginx-proxy:test")
|
||||
docker_client = docker.from_env()
|
||||
print(
|
||||
docker_client.containers.run(
|
||||
image="nginxproxy/nginx-proxy:test",
|
||||
remove=True,
|
||||
volumes=["{current_dir}:{current_dir}".format(current_dir=script_dir)],
|
||||
entrypoint="sh",
|
||||
command='-xc "cp /app/nginx.tmpl {current_dir} && chmod 777 {current_dir}/nginx.tmpl"'.format(
|
||||
current_dir=script_dir
|
||||
),
|
||||
stderr=True,
|
||||
)
|
||||
)
|
||||
yield
|
||||
logging.info("removing nginx.tmpl")
|
||||
os.remove(os.path.join(script_dir, "nginx.tmpl"))
|
||||
|
||||
|
||||
def test_unknown_virtual_host_is_503(nginx_tmpl, docker_compose, nginxproxy):
|
||||
def test_unknown_virtual_host_is_503(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://unknown.nginx.container.docker/")
|
||||
assert r.status_code == 503
|
||||
|
||||
|
||||
def test_forwards_to_whoami(nginx_tmpl, docker_compose, nginxproxy):
|
||||
def test_forwards_to_whoami(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://whoami.nginx.container.docker/")
|
||||
assert r.status_code == 200
|
||||
whoami_container = docker_compose.containers.get("whoami")
|
||||
|
@ -11,7 +11,7 @@ services:
|
||||
command: -notify-sighup nginx -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl
|
||||
- ../../nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl
|
||||
- nginx_conf:/etc/nginx/conf.d
|
||||
|
||||
web:
|
||||
|
Loading…
x
Reference in New Issue
Block a user