mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-02-24 01:38:15 +00:00
ci: Add tests for the virtual-path routing
@gregsymons test cases were too outdated to be ported easily. The new tests should include the coverage of the old ones.
This commit is contained in:
parent
2901b917a0
commit
fc4c4e17ca
@ -29,13 +29,36 @@ def web1(docker_compose):
|
||||
except NotFound:
|
||||
pass
|
||||
|
||||
@pytest.fixture()
|
||||
def web2(docker_compose):
|
||||
"""
|
||||
pytest fixture creating a web container with `VIRTUAL_HOST=nginx-proxy`, `VIRTUAL_PATH=/web2/` and `VIRTUAL_DEST=/` listening on port 82.
|
||||
"""
|
||||
container = docker_compose.containers.run(
|
||||
name="web2",
|
||||
image="web",
|
||||
detach=True,
|
||||
environment={
|
||||
"WEB_PORTS": "82",
|
||||
"VIRTUAL_HOST": "nginx-proxy",
|
||||
"VIRTUAL_PATH": "/web2/",
|
||||
"VIRTUAL_DEST": "/",
|
||||
},
|
||||
ports={"82/tcp": None}
|
||||
)
|
||||
sleep(2) # give it some time to initialize and for docker-gen to detect it
|
||||
yield container
|
||||
try:
|
||||
docker_compose.containers.get("web2").remove(force=True)
|
||||
except NotFound:
|
||||
pass
|
||||
|
||||
def test_nginx_proxy_behavior_when_alone(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://nginx-proxy/")
|
||||
assert r.status_code == 503
|
||||
|
||||
|
||||
def test_new_container_is_detected(web1, nginxproxy):
|
||||
def test_new_container_is_detected_vhost(web1, nginxproxy):
|
||||
r = nginxproxy.get("http://web1.nginx-proxy/port")
|
||||
assert r.status_code == 200
|
||||
assert "answer from port 81\n" == r.text
|
||||
@ -44,3 +67,16 @@ def test_new_container_is_detected(web1, nginxproxy):
|
||||
sleep(2)
|
||||
r = nginxproxy.get("http://web1.nginx-proxy/port")
|
||||
assert r.status_code == 503
|
||||
|
||||
def test_new_container_is_detected_vpath(web2, nginxproxy):
|
||||
r = nginxproxy.get("http://nginx-proxy/web2/port")
|
||||
assert r.status_code == 200
|
||||
assert "answer from port 82\n" == r.text
|
||||
r = nginxproxy.get("http://nginx-proxy/port")
|
||||
assert r.status_code in [404, 503]
|
||||
|
||||
web2.remove(force=True)
|
||||
sleep(2)
|
||||
r = nginxproxy.get("http://nginx-proxy/web2/port")
|
||||
assert r.status_code == 503
|
||||
|
||||
|
59
test/test_virtual-path/test_virtual_paths.py
Normal file
59
test/test_virtual-path/test_virtual_paths.py
Normal file
@ -0,0 +1,59 @@
|
||||
from time import sleep
|
||||
|
||||
import pytest
|
||||
from docker.errors import NotFound
|
||||
|
||||
@pytest.mark.parametrize("stub,expected_port", [
|
||||
("nginx-proxy.test/web1", 81),
|
||||
("nginx-proxy.test/web2", 82),
|
||||
("nginx-proxy.test", 83),
|
||||
("foo.nginx-proxy.test", 42),
|
||||
])
|
||||
def test_valid_path(docker_compose, nginxproxy, stub, expected_port):
|
||||
r = nginxproxy.get(f"http://{stub}/port")
|
||||
assert r.status_code == 200
|
||||
assert r.text == f"answer from port {expected_port}\n"
|
||||
|
||||
@pytest.mark.parametrize("stub", [
|
||||
"nginx-proxy.test/foo",
|
||||
"bar.nginx-proxy.test",
|
||||
])
|
||||
def test_invalid_path(docker_compose, nginxproxy, stub):
|
||||
r = nginxproxy.get(f"http://{stub}/port")
|
||||
assert r.status_code in [404, 503]
|
||||
|
||||
@pytest.fixture()
|
||||
def web4(docker_compose):
|
||||
"""
|
||||
pytest fixture creating a web container with `VIRTUAL_HOST=nginx-proxy.test`, `VIRTUAL_PATH=/web4/` and `VIRTUAL_DEST=/` listening on port 84.
|
||||
"""
|
||||
container = docker_compose.containers.run(
|
||||
name="web4",
|
||||
image="web",
|
||||
detach=True,
|
||||
environment={
|
||||
"WEB_PORTS": "84",
|
||||
"VIRTUAL_HOST": "nginx-proxy.test",
|
||||
"VIRTUAL_PATH": "/web4/",
|
||||
"VIRTUAL_DEST": "/",
|
||||
},
|
||||
ports={"84/tcp": None}
|
||||
)
|
||||
sleep(2) # give it some time to initialize and for docker-gen to detect it
|
||||
yield container
|
||||
try:
|
||||
docker_compose.containers.get("web4").remove(force=True)
|
||||
except NotFound:
|
||||
pass
|
||||
|
||||
"""
|
||||
Test if we can add and remove a single virtual_path from multiple ones on the same subdomain.
|
||||
"""
|
||||
def test_container_hotplug(web4, nginxproxy):
|
||||
r = nginxproxy.get(f"http://nginx-proxy.test/web4/port")
|
||||
assert r.status_code == 200
|
||||
assert r.text == f"answer from port 84\n"
|
||||
web4.remove(force=True)
|
||||
sleep(2)
|
||||
r = nginxproxy.get(f"http://nginx-proxy.test/web4/port")
|
||||
assert r.status_code == 404
|
42
test/test_virtual-path/test_virtual_paths.yml
Normal file
42
test/test_virtual-path/test_virtual_paths.yml
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
foo:
|
||||
image: web
|
||||
expose:
|
||||
- "42"
|
||||
environment:
|
||||
WEB_PORTS: "42"
|
||||
VIRTUAL_HOST: "foo.nginx-proxy.test"
|
||||
|
||||
web1:
|
||||
image: web
|
||||
expose:
|
||||
- "81"
|
||||
environment:
|
||||
WEB_PORTS: "81"
|
||||
VIRTUAL_HOST: "nginx-proxy.test"
|
||||
VIRTUAL_PATH: "/web1/"
|
||||
|
||||
web2:
|
||||
image: web
|
||||
expose:
|
||||
- "82"
|
||||
environment:
|
||||
WEB_PORTS: "82"
|
||||
VIRTUAL_HOST: "nginx-proxy.test"
|
||||
VIRTUAL_PATH: "/web2/"
|
||||
|
||||
web3:
|
||||
image: web
|
||||
expose:
|
||||
- "83"
|
||||
environment:
|
||||
WEB_PORTS: "83"
|
||||
VIRTUAL_HOST: "nginx-proxy.test"
|
||||
VIRTUAL_PATH: "/"
|
||||
|
||||
sut:
|
||||
image: nginxproxy/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
|
Loading…
x
Reference in New Issue
Block a user