diff --git a/test2/conftest.py b/test2/conftest.py index 00a5b6f..07b5f01 100644 --- a/test2/conftest.py +++ b/test2/conftest.py @@ -90,7 +90,13 @@ def monkey_patch_urllib_dns_resolver(): log.debug("resolving domain name %s" % repr(args)) if 'nginx-proxy' in args[0]: docker_client = docker.from_env() - ip = docker_client.containers(filters={"status": "running", "ancestor": "jwilder/nginx-proxy:test"})[0]["NetworkSettings"]["Networks"]["bridge"]["IPAddress"] + net_info = docker_client.containers(filters={"status": "running", "ancestor": "jwilder/nginx-proxy:test"})[0]["NetworkSettings"]["Networks"] + if "bridge" in net_info: + ip = net_info["bridge"]["IPAddress"] + else: + # not default bridge network, fallback on first network defined + network_name = net_info.keys()[0] + ip = net_info[network_name]["IPAddress"] log.info("resolving domain name %r as IP address is %s" % (args[0], ip)) return [ (socket.AF_INET, socket.SOCK_STREAM, 6, '', (ip, args[1])), diff --git a/test2/test_composev2.py b/test2/test_composev2.py new file mode 100644 index 0000000..88a4f80 --- /dev/null +++ b/test2/test_composev2.py @@ -0,0 +1,10 @@ +import pytest + +def test_unknown_virtual_host(docker_compose, nginxproxy): + r = nginxproxy.get("http://nginx-proxy/") + assert r.status_code == 503 + +def test_forwards_to_whoami(docker_compose, nginxproxy): + r = nginxproxy.get("http://web.nginx-proxy.local/port") + assert r.status_code == 200 + assert r.text == "answer from port 81\n" diff --git a/test2/test_composev2.yml b/test2/test_composev2.yml new file mode 100644 index 0000000..5ffaf57 --- /dev/null +++ b/test2/test_composev2.yml @@ -0,0 +1,14 @@ +version: '2' +services: + nginx-proxy: + image: jwilder/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + + web: + image: web + expose: + - "81" + environment: + WEB_PORTS: 81 + VIRTUAL_HOST: web.nginx-proxy.local \ No newline at end of file