From 9620be91fae9c355cf5f20104881bc23aea36a46 Mon Sep 17 00:00:00 2001 From: Thomas LEVEIL Date: Fri, 17 Feb 2017 01:09:53 +0100 Subject: [PATCH] TESTS: separated containers: fix indentation and remove dependency over jwilder/whoami image --- test/requirements/web/webserver.py | 3 ++ test/test_dockergen/test_dockergen_v2.py | 36 ++++++++++----------- test/test_dockergen/test_dockergen_v2.yml | 9 ++++-- test/test_dockergen/test_dockergen_v3.py | 39 ++++++++++++----------- test/test_dockergen/test_dockergen_v3.yml | 9 ++++-- 5 files changed, 53 insertions(+), 43 deletions(-) diff --git a/test/requirements/web/webserver.py b/test/requirements/web/webserver.py index 22a6ce1..305c207 100755 --- a/test/requirements/web/webserver.py +++ b/test/requirements/web/webserver.py @@ -17,6 +17,9 @@ class Handler(http.server.SimpleHTTPRequestHandler): elif self.path == "/port": response = "answer from port %s\n" % PORT self.wfile.write(response.encode()) + elif self.path == "/": + response = "I'm %s\n" % os.environ['HOSTNAME'] + self.wfile.write(response.encode()) else: self.wfile.write("No route for this path!\n".encode()) diff --git a/test/test_dockergen/test_dockergen_v2.py b/test/test_dockergen/test_dockergen_v2.py index a83af57..c797d0c 100644 --- a/test/test_dockergen/test_dockergen_v2.py +++ b/test/test_dockergen/test_dockergen_v2.py @@ -6,23 +6,24 @@ import pytest @pytest.yield_fixture(scope="module") def nginx_tmpl(): - """ - pytest fixture which extracts the the nginx config template from - the jwilder/nginx-proxy:test image - """ - script_dir = os.path.dirname(__file__) - logging.info("extracting nginx.tmpl from jwilder/nginx-proxy:test") - docker_client = docker.from_env() - print(docker_client.containers.run( - image='jwilder/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")) + """ + pytest fixture which extracts the the nginx config template from + the jwilder/nginx-proxy:test image + """ + script_dir = os.path.dirname(__file__) + logging.info("extracting nginx.tmpl from jwilder/nginx-proxy:test") + docker_client = docker.from_env() + print(docker_client.containers.run( + image='jwilder/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): @@ -35,4 +36,3 @@ def test_forwards_to_whoami(nginx_tmpl, docker_compose, nginxproxy): assert r.status_code == 200 whoami_container = docker_compose.containers.get("whoami") assert r.text == "I'm %s\n" % whoami_container.id[:12] - diff --git a/test/test_dockergen/test_dockergen_v2.yml b/test/test_dockergen/test_dockergen_v2.yml index 145c763..0d2cab0 100644 --- a/test/test_dockergen/test_dockergen_v2.yml +++ b/test/test_dockergen/test_dockergen_v2.yml @@ -16,8 +16,11 @@ services: - /var/run/docker.sock:/tmp/docker.sock:ro - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl - whoami: - image: jwilder/whoami + web: + image: web container_name: whoami + expose: + - "80" environment: - - VIRTUAL_HOST=whoami.nginx.container.docker \ No newline at end of file + WEB_PORTS: 80 + VIRTUAL_HOST: whoami.nginx.container.docker \ No newline at end of file diff --git a/test/test_dockergen/test_dockergen_v3.py b/test/test_dockergen/test_dockergen_v3.py index 8388223..325d6db 100644 --- a/test/test_dockergen/test_dockergen_v3.py +++ b/test/test_dockergen/test_dockergen_v3.py @@ -7,30 +7,32 @@ import pytest def versiontuple(v): return tuple(map(int, (v.split(".")))) + docker_version = docker.from_env().version()['Version'] pytestmark = pytest.mark.skipif(versiontuple(docker_version) < versiontuple('1.13'), - reason="Docker compose syntax v3 requires docker engine v1.13") + reason="Docker compose syntax v3 requires docker engine v1.13") @pytest.yield_fixture(scope="module") def nginx_tmpl(): - """ - pytest fixture which extracts the the nginx config template from - the jwilder/nginx-proxy:test image - """ - script_dir = os.path.dirname(__file__) - logging.info("extracting nginx.tmpl from jwilder/nginx-proxy:test") - docker_client = docker.from_env() - print(docker_client.containers.run( - image='jwilder/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")) + """ + pytest fixture which extracts the the nginx config template from + the jwilder/nginx-proxy:test image + """ + script_dir = os.path.dirname(__file__) + logging.info("extracting nginx.tmpl from jwilder/nginx-proxy:test") + docker_client = docker.from_env() + print(docker_client.containers.run( + image='jwilder/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): @@ -43,4 +45,3 @@ def test_forwards_to_whoami(nginx_tmpl, docker_compose, nginxproxy): assert r.status_code == 200 whoami_container = docker_compose.containers.get("whoami") assert r.text == "I'm %s\n" % whoami_container.id[:12] - diff --git a/test/test_dockergen/test_dockergen_v3.yml b/test/test_dockergen/test_dockergen_v3.yml index b94b09b..643f49b 100644 --- a/test/test_dockergen/test_dockergen_v3.yml +++ b/test/test_dockergen/test_dockergen_v3.yml @@ -14,11 +14,14 @@ services: - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl - nginx_conf:/etc/nginx/conf.d - whoami: - image: jwilder/whoami + web: + image: web container_name: whoami + expose: + - "80" environment: - - VIRTUAL_HOST=whoami.nginx.container.docker + WEB_PORTS: 80 + VIRTUAL_HOST: whoami.nginx.container.docker volumes: nginx_conf: {} \ No newline at end of file