Implementing web server tests for built docker image

This commit is contained in:
Damian Fajfer
2024-04-04 23:55:32 +02:00
parent e46f1271e6
commit 222ae1ef42
6 changed files with 33 additions and 0 deletions

33
tests/run-webserver.py Normal file
View File

@@ -0,0 +1,33 @@
import pytest
import requests
import docker
import time
from os import environ
def wait_for_webserver(max_retries: int) -> requests.Response:
for i in range(max_retries):
try:
response = requests.get("http://localhost:8080")
response.raise_for_status()
return response
except requests.exceptions.ConnectionError:
time.sleep(1)
else:
pytest.fail("Failed to connect to the webserver")
def test_webserver() -> None:
client = docker.from_env()
container = client.containers.run(
environ["GCUPS_DOCKER_IMAGE"],
ports={"8080/tcp": 8080},
detach=True,
remove=True,
)
server_response = wait_for_webserver(30)
assert server_response.status_code == 200
container.kill()
client.close()