Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down