mirror of
https://github.com/aljazceru/gcups.git
synced 2025-12-17 05:14:23 +01:00
Implementing web server tests for built docker image
This commit is contained in:
BIN
tests/__pycache__/run-webserver.cpython-310-pytest-7.3.1.pyc
Normal file
BIN
tests/__pycache__/run-webserver.cpython-310-pytest-7.3.1.pyc
Normal file
Binary file not shown.
33
tests/run-webserver.py
Normal file
33
tests/run-webserver.py
Normal 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()
|
||||
Reference in New Issue
Block a user