Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(devservices): Do not add docker compose command when services to use is empty #93

Merged
merged 1 commit into from
Oct 30, 2024
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
9 changes: 5 additions & 4 deletions devservices/utils/docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,12 @@ def _get_docker_compose_commands_to_run(
service_config_file_path, current_env
)
services_to_use = non_remote_services.intersection(set(mode_dependencies))
docker_compose_commands.append(
create_docker_compose_command(
service.name, service_config_file_path, services_to_use
if len(services_to_use) > 0:
docker_compose_commands.append(
create_docker_compose_command(
service.name, service_config_file_path, services_to_use
)
)
)
return docker_compose_commands


Expand Down
41 changes: 41 additions & 0 deletions tests/utils/test_docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,47 @@ def test_get_all_commands_to_run_simple_local(
]


@mock.patch(
"devservices.utils.docker_compose.subprocess.run",
return_value=subprocess.CompletedProcess(
args=["docker", "compose", "config", "--services"],
returncode=0,
stdout="child-service\n",
),
)
def test_get_all_commands_to_run_no_services_to_use(
mock_run: mock.Mock, tmp_path: Path
) -> None:
child_service_repo_path = tmp_path / "child-service-repo"
create_mock_git_repo("child-service-repo", child_service_repo_path)
child_service_repo_path_str = str(child_service_repo_path)

service_config = load_service_config_from_file(child_service_repo_path_str)
remote_dependencies: set[InstalledRemoteDependency] = set()
current_env = os.environ.copy()
command = "up"
options = ["-d"]
service_config_file_path = os.path.join(
child_service_repo_path_str, DEVSERVICES_DIR_NAME, CONFIG_FILE_NAME
)
mode_dependencies = ["random-service"]
service = Service(
name="child-service",
repo_path=child_service_repo_path_str,
config=service_config,
)
commands = _get_docker_compose_commands_to_run(
service=service,
remote_dependencies=remote_dependencies,
current_env=current_env,
command=command,
options=options,
service_config_file_path=service_config_file_path,
mode_dependencies=mode_dependencies,
)
assert commands == []


@mock.patch("devservices.utils.docker_compose.subprocess.run")
def test_get_all_commands_to_run_simple_remote(
mock_run: mock.Mock, tmp_path: Path
Expand Down