mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-07-01 22:35:45 +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:
committed by
Nicolas Duchon
parent
2901b917a0
commit
fc4c4e17ca
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
|
Reference in New Issue
Block a user