8000 Test Sample projects (#60) · sesi/functions-framework-python@c88d94c · GitHub
[go: up one dir, main page]

Skip to content

Commit c88d94c

Browse files
authored
Test Sample projects (GoogleCloudPlatform#60)
* Test the http sample * Test the http sample * Convert shell to docker py api * Include docker-py dep * Extra deps are in TOX * Docker-py from pip is weird. * Only run on linux. * Stop running containers if they are running. * Improve skip message. * lint error fixes
1 parent 32bba7d commit c88d94c

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"watchdog>=0.10.0",
5454
"gunicorn>=19.2.0,<21.0; platform_system!='Windows'",
5555
],
56-
extras_require={"test": ["pytest", "tox"]},
5756
entry_points={
5857
"console_scripts": [
5958
"functions-framework=functions_framework._cli:_cli",

tests/test_samples.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pathlib
2+
import sys
3+
import time
4+
5+
import docker
6+
import pytest
7+
import requests
8+
9+
EXAMPLES_DIR = pathlib.Path(__file__).resolve().parent.parent / "examples"
10+
11+
12+
@pytest.mark.skipif(
13+
sys.platform != "linux", reason="docker only works on linux in GH actions"
14+
)
15+
class TestSamples:
16+
def stop_all_containers(self, docker_client):
17+
containers = docker_client.containers.list()
18+
for container in containers:
19+
container.stop()
20+
21+
@pytest.mark.slow_integration_test
22+
def test_cloud_run_http(self):
23+
client = docker.from_env()
24+
self.stop_all_containers(client)
25+
26+
TAG = "cloud_run_http"
27+
client.images.build(path=str(EXAMPLES_DIR / "cloud_run_http"), tag={TAG})
28+
container = client.containers.run(image=TAG, detach=True, ports={8080: 8080})
29+
timeout = 10
30+
success = False
31+
while success == False and timeout > 0:
32+
try:
33+
response = requests.get("http://localhost:8080")
34+
if response.text == "Hello world!":
35+
success = True
36+
except:
37+
pass
38+
39+
time.sleep(1)
40+
timeout -= 1
41+
42+
container.stop()
43+
44+
assert success

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ envlist = py{35,36,37,38}-{ubuntu-latest,macos-latest,windows-latest},lint
44
[testenv]
55
usedevelop = true
66
deps =
7+
docker
78
pytest-cov
9+
pytest-integration
810
pretend
911
setenv =
1012
PYTESTARGS = --cov=functions_framework --cov-branch --cov-report term-missing --cov-fail-under=100

0 commit comments

Comments
 (0)
0