mirror of
https://github.com/thib8956/nginx-proxy
synced 2024-11-22 03:46:29 +00:00
TESTS: add a test to verify nginx conf is update on container creation/deletion
This commit is contained in:
parent
68816390ee
commit
2aef648f3d
46
test/test_events.py
Normal file
46
test/test_events.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
"""
|
||||||
|
Test that nginx-proxy detects new containers
|
||||||
|
"""
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from docker.errors import NotFound
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.yield_fixture()
|
||||||
|
def web1(docker_compose):
|
||||||
|
"""
|
||||||
|
pytest fixture creating a web container with `VIRTUAL_HOST=web1.nginx-proxy` listening on port 81.
|
||||||
|
"""
|
||||||
|
container = docker_compose.containers.run(
|
||||||
|
name="web1",
|
||||||
|
image="web",
|
||||||
|
detach=True,
|
||||||
|
environment={
|
||||||
|
"WEB_PORTS": "81",
|
||||||
|
"VIRTUAL_HOST": "web1.nginx-proxy"
|
||||||
|
},
|
||||||
|
ports={"81/tcp": None}
|
||||||
|
)
|
||||||
|
sleep(2) # give it some time to initialize and for docker-gen to detect it
|
||||||
|
yield container
|
||||||
|
try:
|
||||||
|
docker_compose.containers.get("web1").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):
|
||||||
|
r = nginxproxy.get("http://web1.nginx-proxy/port")
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert "answer from port 81\n" == r.text
|
||||||
|
|
||||||
|
web1.remove(force=True)
|
||||||
|
sleep(2)
|
||||||
|
r = nginxproxy.get("http://web1.nginx-proxy/port")
|
||||||
|
assert r.status_code == 503
|
4
test/test_events.yml
Normal file
4
test/test_events.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
nginxproxy:
|
||||||
|
image: jwilder/nginx-proxy:test
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/tmp/docker.sock:ro
|
Loading…
Reference in New Issue
Block a user