diff --git a/setup.py b/setup.py index 2a16fe7f..0d8841be 100644 --- a/setup.py +++ b/setup.py @@ -53,7 +53,6 @@ "watchdog>=0.10.0", "gunicorn>=19.2.0,<21.0; platform_system!='Windows'", ], - extras_require={"test": ["pytest", "tox"]}, entry_points={ "console_scripts": [ "functions-framework=functions_framework._cli:_cli", diff --git a/tests/test_samples.py b/tests/test_samples.py new file mode 100644 index 00000000..65cee7d0 --- /dev/null +++ b/tests/test_samples.py @@ -0,0 +1,44 @@ +import pathlib +import sys +import time + +import docker +import pytest +import requests + +EXAMPLES_DIR = pathlib.Path(__file__).resolve().parent.parent / "examples" + + +@pytest.mark.skipif( + sys.platform != "linux", reason="docker only works on linux in GH actions" +) +class TestSamples: + def stop_all_containers(self, docker_client): + containers = docker_client.containers.list() + for container in containers: + container.stop() + + @pytest.mark.slow_integration_test + def test_cloud_run_http(self): + client = docker.from_env() + self.stop_all_containers(client) + + TAG = "cloud_run_http" + client.images.build(path=str(EXAMPLES_DIR / "cloud_run_http"), tag={TAG}) + container = client.containers.run(image=TAG, detach=True, ports={8080: 8080}) + timeout = 10 + success = False + while success == False and timeout > 0: + try: + response = requests.get("http://localhost:8080") + if response.text == "Hello world!": + success = True + except: + pass + + time.sleep(1) + timeout -= 1 + + container.stop() + + assert success diff --git a/tox.ini b/tox.ini index f5b65064..f2cd7fe8 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,9 @@ envlist = py{35,36,37,38}-{ubuntu-latest,macos-latest,windows-latest},lint [testenv] usedevelop = true deps = + docker pytest-cov + pytest-integration pretend setenv = PYTESTARGS = --cov=functions_framework --cov-branch --cov-report term-missing --cov-fail-under=100