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 diff --git a/scripts/test-all.sh b/scripts/test-all.sh new file mode 100644 index 0000000..20b8fd4 --- /dev/null +++ b/scripts/test-all.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +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..60637ab --- /dev/null +++ b/scripts/test_all.py @@ -0,0 +1,124 @@ +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): + use_env = {**os.environ, **env} + 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) + + +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..e3eef70 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,23 @@ 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 + 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) 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..35e9705 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,13 @@ 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 + 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) container = client.containers.run( image, @@ -114,12 +75,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()