Skip to content

Commit

Permalink
feat: add in suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar5526 committed Jan 14, 2024
1 parent 6daa35b commit 9f2c179
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@ jobs:
with:
python-version: 3.11 # Choose your Python version

- name: Install dependencies
- name: Cache Python dependencies
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install main dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install -r requirements.txt
- name: Install development dependencies
run: pip install -r requirements-dev.txt

- name: Run pytest
run: python -m pytest -vvv
4 changes: 1 addition & 3 deletions server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ class ComposeHelper:

def __init__(self, compose_file_location: str, load_compose_file=True):
self._compose_file_location = compose_file_location
self._compose = None
if load_compose_file:
self._compose = load_yaml_file(self._compose_file_location)
self._compose = load_yaml_file(self._compose_file_location) if load_compose_file else None

def start_services(
self, nginx_port: str, conf_file_path: str, deployment_namespace: str
Expand Down
32 changes: 21 additions & 11 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,27 @@ def test_start_services(compose_helper, mocker):
# - No ports
# - No container_name
# - Restart should be present in each service
for service in compose_helper._compose["services"]:
if (
"ports" in compose_helper._compose["services"][service]
and service != f"nginx_{deployment_namespace}"
):
assert False, "Ports mapping present in processed compose file"
if "container_name" in compose_helper._compose["services"][service]:
assert False, "Container Name present in processed compose file"
if "restart" not in compose_helper._compose["services"][service]:
assert False, "Restart clause missing in processed compose file"
assert compose_helper._compose["services"][service]["restart"] == "always"
services = compose_helper._compose["services"]

# Deployment Proxy should be added in compose file
is_deployment_proxy_service = False

for service_name, service_config in services.items():
is_deployment_proxy_service = is_deployment_proxy_service or service_name == f"nginx_{deployment_namespace}"

assert "ports" not in service_config or is_deployment_proxy_service, \
f"Ports mapping should not be present in {service_name}"

assert "container_name" not in service_config, \
f"Container Name should not be present in {service_name}"

assert "restart" in service_config, \
f"Restart clause missing in {service_name}"

assert service_config["restart"] == "always", \
f"Incorrect restart policy in {service_name}"

assert is_deployment_proxy_service, "Deployment (Nginx) Proxy is missing in processed services"

mocked_run.assert_called_once_with(
["docker-compose", "up", "-d", "--build"], check=True, cwd=pathlib.Path(".")
Expand Down

0 comments on commit 9f2c179

Please sign in to comment.