From d6c4f7e51bb4b4918ddf8d7feb6cb4b949d4f043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 4 May 2019 15:47:38 +0400 Subject: [PATCH 1/4] :sparkles: Make tests independent, running each test by env vars --- scripts/test-all.sh | 4 + scripts/test.sh | 2 +- scripts/test_all.py | 127 +++++++++++++++++++++ tests/test_01_main/test_defaults.py | 58 ++-------- tests/test_01_main/test_env_vars_1.py | 58 ++-------- tests/test_02_app/test_app_and_env_vars.py | 62 ++-------- tests/test_02_app/test_custom_nginx_app.py | 62 ++-------- tests/test_02_app/test_simple_app.py | 62 ++-------- 8 files changed, 177 insertions(+), 258 deletions(-) create mode 100644 scripts/test-all.sh create mode 100644 scripts/test_all.py diff --git a/scripts/test-all.sh b/scripts/test-all.sh new file mode 100644 index 0000000..19bc3b4 --- /dev/null +++ b/scripts/test-all.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +SLEEP_TIME=5 python scripts/test_all.py diff --git a/scripts/test.sh b/scripts/test.sh index dfcc3a9..328219f 100644 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash set -e -docker-compose -f docker-compose.build.yml build +docker-compose -f docker-compose.build.yml build $NAME pytest tests diff --git a/scripts/test_all.py b/scripts/test_all.py new file mode 100644 index 0000000..45706bd --- /dev/null +++ b/scripts/test_all.py @@ -0,0 +1,127 @@ +import os +import subprocess +import sys + +versions = [ + { + "NAME": "python2.7", + "BUILD_PATH": "python2.7", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container (default)", + "DOCKERFILE": "python2.7.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", + "RUN_TESTS": "1", + }, + { + "NAME": "python2.7-alpine3.7", + "BUILD_PATH": "python2.7-alpine3.7", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)", + "DOCKERFILE": "python2.7-alpine3.7.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", + "RUN_TESTS": "1", + }, + { + "NAME": "python2.7-alpine3.8", + "BUILD_PATH": "python2.7-alpine3.8", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)", + "DOCKERFILE": "python2.7-alpine3.8.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", + "RUN_TESTS": "1", + }, + { + "NAME": "python3.5", + "BUILD_PATH": "python3.5", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.5 app in a Docker container (default)", + "DOCKERFILE": "python3.5.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 3.5 app in a Docker container", + "RUN_TESTS": "1", + }, + { + "NAME": "python3.6", + "BUILD_PATH": "python3.6", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container (default)", + "DOCKERFILE": "python3.6.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", + "RUN_TESTS": "1", + }, + { + "NAME": "python3.6-alpine3.7", + "BUILD_PATH": "python3.6-alpine3.7", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)", + "DOCKERFILE": "python3.6-alpine3.7.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", + "RUN_TESTS": "1", + }, + { + "NAME": "python3.6-alpine3.8", + "BUILD_PATH": "python3.6-alpine3.8", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)", + "DOCKERFILE": "python3.6-alpine3.8.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", + "RUN_TESTS": "1", + }, + { + "NAME": "python3.7", + "BUILD_PATH": "python3.7", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)", + "DOCKERFILE": "python3.7.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", + "RUN_TESTS": "1", + }, + { + "NAME": "latest", + "BUILD_PATH": "python3.7", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)", + "DOCKERFILE": "latest.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", + "RUN_TESTS": "1", + }, + { + "NAME": "python3.7-alpine3.7", + "BUILD_PATH": "python3.7-alpine3.7", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)", + "DOCKERFILE": "python3.7-alpine3.7.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", + "RUN_TESTS": "", + }, + { + "NAME": "python3.7-alpine3.8", + "BUILD_PATH": "python3.7-alpine3.8", + "TEST_STR1": "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)", + "DOCKERFILE": "python3.7-alpine3.8.dockerfile", + "TEST_STR2": "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", + "RUN_TESTS": "", + }, +] + + +def test_tag(*, env: dict): + tag = f"tiangolo/uwsgi-nginx:{env['NAME']}" + print(f"Testing image: {tag}") + use_env = {**os.environ, **env, "TAG": tag} + return_code = subprocess.call(["bash", "scripts/test.sh"], env=use_env) + if return_code != 0: + sys.exit(return_code) + + +def print_version_envs(): + env_lines = [] + for version in versions: + env_vars = [] + for key, value in version.items(): + env_vars.append(f"{key}='{value}'") + env_lines.append(" ".join(env_vars)) + for line in env_lines: + print(line) + + +def main(): + for env in versions: + test_tag(env=env) + +import sys + +if __name__ == "__main__": + if len(sys.argv) > 1: + print_version_envs() + else: + main() diff --git a/tests/test_01_main/test_defaults.py b/tests/test_01_main/test_defaults.py index f37eaf1..6b4be40 100644 --- a/tests/test_01_main/test_defaults.py +++ b/tests/test_01_main/test_defaults.py @@ -1,7 +1,7 @@ +import os import time import docker -import pytest import requests from requests import Response @@ -52,62 +52,22 @@ def verify_container(container, response_text): assert response.text == response_text -@pytest.mark.parametrize( - "image,response_text", - [ - ( - "tiangolo/uwsgi-nginx:python2.7", - "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container (default)", - ), - ( - "tiangolo/uwsgi-nginx:python2.7-alpine3.7", - "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx:python2.7-alpine3.8", - "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.5", - "Hello World from a default Nginx uWSGI Python 3.5 app in a Docker container (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.6", - "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.6-alpine3.7", - "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.6-alpine3.8", - "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.7", - "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)", - ), - # ( - # "tiangolo/uwsgi-nginx:python3.7-alpine3.7", - # "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)", - # ), - # ( - # "tiangolo/uwsgi-nginx:python3.7-alpine3.8", - # "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)", - # ), - ], -) -def test_defaults(image, response_text): +def test_defaults(): + if not os.getenv("RUN_TESTS"): + return + image = os.getenv("TAG") + response_text = os.getenv("TEST_STR1") + sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) container = client.containers.run( image, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True ) - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove() diff --git a/tests/test_01_main/test_env_vars_1.py b/tests/test_01_main/test_env_vars_1.py index ae0e454..4c45200 100644 --- a/tests/test_01_main/test_env_vars_1.py +++ b/tests/test_01_main/test_env_vars_1.py @@ -1,7 +1,7 @@ +import os import time import docker -import pytest import requests from ..utils import ( @@ -53,52 +53,12 @@ def verify_container(container, response_text): assert response.text == response_text -@pytest.mark.parametrize( - "image,response_text", - [ - ( - "tiangolo/uwsgi-nginx:python2.7", - "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container (default)", - ), - ( - "tiangolo/uwsgi-nginx:python2.7-alpine3.7", - "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx:python2.7-alpine3.8", - "Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.5", - "Hello World from a default Nginx uWSGI Python 3.5 app in a Docker container (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.6", - "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.6-alpine3.7", - "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.6-alpine3.8", - "Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)", - ), - ( - "tiangolo/uwsgi-nginx:python3.7", - "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)", - ), - # ( - # "tiangolo/uwsgi-nginx:python3.7-alpine3.7", - # "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)", - # ), - # ( - # "tiangolo/uwsgi-nginx:python3.7-alpine3.8", - # "Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)", - # ), - ], -) -def test_env_vars_1(image, response_text): +def test_env_vars_1(): + if not os.getenv("RUN_TESTS"): + return + image = os.getenv("TAG") + response_text = os.getenv("TEST_STR1") + sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) container = client.containers.run( image, @@ -114,12 +74,12 @@ def test_env_vars_1(image, response_text): ports={"80": "8000"}, detach=True, ) - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove() diff --git a/tests/test_02_app/test_app_and_env_vars.py b/tests/test_02_app/test_app_and_env_vars.py index de5598e..473c0d1 100644 --- a/tests/test_02_app/test_app_and_env_vars.py +++ b/tests/test_02_app/test_app_and_env_vars.py @@ -1,8 +1,8 @@ +import os import time from pathlib import Path, PurePath import docker -import pytest import requests from ..utils import ( @@ -52,56 +52,12 @@ def verify_container(container, response_text): assert response.text == response_text -@pytest.mark.parametrize( - "dockerfile,response_text", - [ - ( - "python2.7.dockerfile", - "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", - ), - ( - "python2.7-alpine3.7.dockerfile", - "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", - ), - ( - "python2.7-alpine3.8.dockerfile", - "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", - ), - ( - "python3.5.dockerfile", - "Hello World from Nginx uWSGI Python 3.5 app in a Docker container", - ), - ( - "python3.6.dockerfile", - "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", - ), - ( - "python3.6-alpine3.7.dockerfile", - "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", - ), - ( - "python3.6-alpine3.8.dockerfile", - "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", - ), - ( - "python3.7.dockerfile", - "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - ), - ( - "latest.dockerfile", - "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - ), - # ( - # "python3.7-alpine3.7.dockerfile", - # "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - # ), - # ( - # "python3.7-alpine3.8.dockerfile", - # "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - # ), - ], -) -def test_env_vars_1(dockerfile, response_text): +def test_env_vars_1(): + if not os.getenv("RUN_TESTS"): + return + dockerfile = os.getenv("DOCKERFILE") + response_text = os.getenv("TEST_STR2") + sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) tag = "uwsgi-nginx-testimage" test_path: PurePath = Path(__file__) @@ -117,12 +73,12 @@ def test_env_vars_1(dockerfile, response_text): ports={"8080": "8000"}, detach=True, ) - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove() diff --git a/tests/test_02_app/test_custom_nginx_app.py b/tests/test_02_app/test_custom_nginx_app.py index 5840ff0..906cf36 100644 --- a/tests/test_02_app/test_custom_nginx_app.py +++ b/tests/test_02_app/test_custom_nginx_app.py @@ -1,8 +1,8 @@ +import os import time from pathlib import Path, PurePath import docker -import pytest import requests from ..utils import ( @@ -53,56 +53,12 @@ def verify_container(container, response_text): assert response.text == response_text -@pytest.mark.parametrize( - "dockerfile,response_text", - [ - ( - "python2.7.dockerfile", - "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", - ), - ( - "python2.7-alpine3.7.dockerfile", - "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", - ), - ( - "python2.7-alpine3.8.dockerfile", - "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", - ), - ( - "python3.5.dockerfile", - "Hello World from Nginx uWSGI Python 3.5 app in a Docker container", - ), - ( - "python3.6.dockerfile", - "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", - ), - ( - "python3.6-alpine3.7.dockerfile", - "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", - ), - ( - "python3.6-alpine3.8.dockerfile", - "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", - ), - ( - "python3.7.dockerfile", - "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - ), - ( - "latest.dockerfile", - "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - ), - # ( - # "python3.7-alpine3.7.dockerfile", - # "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - # ), - # ( - # "python3.7-alpine3.8.dockerfile", - # "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - # ), - ], -) -def test_env_vars_1(dockerfile, response_text): +def test_env_vars_1(): + if not os.getenv("RUN_TESTS"): + return + dockerfile = os.getenv("DOCKERFILE") + response_text = os.getenv("TEST_STR2") + sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) tag = "uwsgi-nginx-testimage" test_path: PurePath = Path(__file__) @@ -111,12 +67,12 @@ def test_env_vars_1(dockerfile, response_text): container = client.containers.run( tag, name=CONTAINER_NAME, ports={"8080": "8080"}, detach=True ) - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove() diff --git a/tests/test_02_app/test_simple_app.py b/tests/test_02_app/test_simple_app.py index cd4c69d..5044176 100644 --- a/tests/test_02_app/test_simple_app.py +++ b/tests/test_02_app/test_simple_app.py @@ -1,8 +1,8 @@ +import os import time from pathlib import Path, PurePath import docker -import pytest import requests from ..utils import ( @@ -52,56 +52,12 @@ def verify_container(container, response_text): assert response.text == response_text -@pytest.mark.parametrize( - "dockerfile,response_text", - [ - ( - "python2.7.dockerfile", - "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", - ), - ( - "python2.7-alpine3.7.dockerfile", - "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", - ), - ( - "python2.7-alpine3.8.dockerfile", - "Hello World from Nginx uWSGI Python 2.7 app in a Docker container", - ), - ( - "python3.5.dockerfile", - "Hello World from Nginx uWSGI Python 3.5 app in a Docker container", - ), - ( - "python3.6.dockerfile", - "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", - ), - ( - "python3.6-alpine3.7.dockerfile", - "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", - ), - ( - "python3.6-alpine3.8.dockerfile", - "Hello World from Nginx uWSGI Python 3.6 app in a Docker container", - ), - ( - "python3.7.dockerfile", - "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - ), - ( - "latest.dockerfile", - "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - ), - # ( - # "python3.7-alpine3.7.dockerfile", - # "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - # ), - # ( - # "python3.7-alpine3.8.dockerfile", - # "Hello World from Nginx uWSGI Python 3.7 app in a Docker container", - # ), - ], -) -def test_env_vars_1(dockerfile, response_text): +def test_env_vars_1(): + if not os.getenv("RUN_TESTS"): + return + dockerfile = os.getenv("DOCKERFILE") + response_text = os.getenv("TEST_STR2") + sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) tag = "uwsgi-nginx-testimage" test_path: PurePath = Path(__file__) @@ -110,12 +66,12 @@ def test_env_vars_1(dockerfile, response_text): container = client.containers.run( tag, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True ) - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() # Test that everything works after restarting too container.start() - time.sleep(3) + time.sleep(sleep_time) verify_container(container, response_text) container.stop() container.remove() From 00650f35985b2dc90c8f4433313db4f627a23830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 4 May 2019 15:48:17 +0400 Subject: [PATCH 2/4] :construction_worker: Update Travis to use build matrix --- .travis.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.travis.yml b/.travis.yml index 080c1ad..124055f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,20 @@ install: services: - docker +env: + - NAME='python2.7' BUILD_PATH='python2.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container (default)' DOCKERFILE='python2.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 2.7 app in a Docker container' RUN_TESTS='1' + - NAME='python2.7-alpine3.7' BUILD_PATH='python2.7-alpine3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)' DOCKERFILE='python2.7-alpine3.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 2.7 app in a Docker container' RUN_TESTS='1' + - NAME='python2.7-alpine3.8' BUILD_PATH='python2.7-alpine3.8' TEST_STR1='Hello World from a default Nginx uWSGI Python 2.7 app in a Docker container in Alpine (default)' DOCKERFILE='python2.7-alpine3.8.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 2.7 app in a Docker container' RUN_TESTS='1' + - NAME='python3.5' BUILD_PATH='python3.5' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.5 app in a Docker container (default)' DOCKERFILE='python3.5.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.5 app in a Docker container' RUN_TESTS='1' + - NAME='python3.6' BUILD_PATH='python3.6' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container (default)' DOCKERFILE='python3.6.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.6 app in a Docker container' RUN_TESTS='1' + - NAME='python3.6-alpine3.7' BUILD_PATH='python3.6-alpine3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)' DOCKERFILE='python3.6-alpine3.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.6 app in a Docker container' RUN_TESTS='1' + - NAME='python3.6-alpine3.8' BUILD_PATH='python3.6-alpine3.8' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.6 app in a Docker container in Alpine (default)' DOCKERFILE='python3.6-alpine3.8.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.6 app in a Docker container' RUN_TESTS='1' + - NAME='python3.7' BUILD_PATH='python3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)' DOCKERFILE='python3.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.7 app in a Docker container' RUN_TESTS='1' + - NAME='latest' BUILD_PATH='python3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container (default)' DOCKERFILE='latest.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.7 app in a Docker container' RUN_TESTS='1' + - NAME='python3.7-alpine3.7' BUILD_PATH='python3.7-alpine3.7' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)' DOCKERFILE='python3.7-alpine3.7.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.7 app in a Docker container' RUN_TESTS='' + - NAME='python3.7-alpine3.8' BUILD_PATH='python3.7-alpine3.8' TEST_STR1='Hello World from a default Nginx uWSGI Python 3.7 app in a Docker container in Alpine (default)' DOCKERFILE='python3.7-alpine3.8.dockerfile' TEST_STR2='Hello World from Nginx uWSGI Python 3.7 app in a Docker container' RUN_TESTS='' + + script: - bash scripts/test.sh From a36ca7463967de59d51a2f8ac6182812d71787bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 4 May 2019 16:17:14 +0400 Subject: [PATCH 3/4] :bug: Generate image tag in tests as no env var is provided --- scripts/test-all.sh | 2 +- scripts/test_all.py | 4 +--- tests/test_01_main/test_defaults.py | 3 ++- tests/test_01_main/test_env_vars_1.py | 3 ++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/test-all.sh b/scripts/test-all.sh index 19bc3b4..20b8fd4 100644 --- a/scripts/test-all.sh +++ b/scripts/test-all.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash set -e -SLEEP_TIME=5 python scripts/test_all.py +python scripts/test_all.py diff --git a/scripts/test_all.py b/scripts/test_all.py index 45706bd..6fb1a87 100644 --- a/scripts/test_all.py +++ b/scripts/test_all.py @@ -95,9 +95,7 @@ def test_tag(*, env: dict): - tag = f"tiangolo/uwsgi-nginx:{env['NAME']}" - print(f"Testing image: {tag}") - use_env = {**os.environ, **env, "TAG": tag} + use_env = {**os.environ, **env} return_code = subprocess.call(["bash", "scripts/test.sh"], env=use_env) if return_code != 0: sys.exit(return_code) diff --git a/tests/test_01_main/test_defaults.py b/tests/test_01_main/test_defaults.py index 6b4be40..e3eef70 100644 --- a/tests/test_01_main/test_defaults.py +++ b/tests/test_01_main/test_defaults.py @@ -55,7 +55,8 @@ def verify_container(container, response_text): def test_defaults(): if not os.getenv("RUN_TESTS"): return - image = os.getenv("TAG") + name = os.getenv("NAME") + image = f"tiangolo/uwsgi-nginx:{name}" response_text = os.getenv("TEST_STR1") sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) diff --git a/tests/test_01_main/test_env_vars_1.py b/tests/test_01_main/test_env_vars_1.py index 4c45200..35e9705 100644 --- a/tests/test_01_main/test_env_vars_1.py +++ b/tests/test_01_main/test_env_vars_1.py @@ -56,7 +56,8 @@ def verify_container(container, response_text): def test_env_vars_1(): if not os.getenv("RUN_TESTS"): return - image = os.getenv("TAG") + name = os.getenv("NAME") + image = f"tiangolo/uwsgi-nginx:{name}" response_text = os.getenv("TEST_STR1") sleep_time = int(os.getenv("SLEEP_TIME", 3)) remove_previous_container(client) From a9f5afa3a90d0fb7e9c81cd8fb48cf8e922c6840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 4 May 2019 17:23:33 +0400 Subject: [PATCH 4/4] :fire: Remove duplicated import --- scripts/test_all.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/test_all.py b/scripts/test_all.py index 6fb1a87..60637ab 100644 --- a/scripts/test_all.py +++ b/scripts/test_all.py @@ -116,7 +116,6 @@ def main(): for env in versions: test_tag(env=env) -import sys if __name__ == "__main__": if len(sys.argv) > 1: