Skip to content

Commit

Permalink
The search function of the Docker Engine has removed, because not use…
Browse files Browse the repository at this point in the history
…d anymore.
  • Loading branch information
janosmurai committed Aug 28, 2024
1 parent 08ecf26 commit ebb99c1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 42 deletions.
15 changes: 1 addition & 14 deletions dem/core/container_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,4 @@ def remove(self, image: str) -> None:
except docker.errors.ImageNotFound:
self.user_output.msg(f"[yellow]The {image} doesn't exist. Unable to remove it.[/]\n")
except docker.errors.APIError:
raise ContainerEngineError(f"The {image} is used by a container. Unable to remove it.\n")

def search(self, registry: str) -> list[str]:
""" Search for repositories on Docker Hub.
Args:
registry -- registry to search
"""
repositories = []

for repositories in self._docker_client.images.search(registry):
repositories.append(repositories['name'])

return repositories
raise ContainerEngineError(f"The {image} is used by a container. Unable to remove it.\n")
29 changes: 1 addition & 28 deletions tests/core/test_container_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,31 +292,4 @@ def test_remove_APIError(mock_from_env: MagicMock) -> None:
# Check expectations
assert str(exported_exception_info) == f"The {test_image_to_remove} is used by a container. Unable to remove it.[/]\n"

mock_docker_client.images.remove.assert_called_once_with(test_image_to_remove)

@patch("docker.from_env")
def test_search(mock_from_env):
# Test setup
mock_docker_client = MagicMock()
mock_from_env.return_value = mock_docker_client
test_registry = "test_registry"
test_repositories = [
{
"name": "repo1"
},
{
"name": "repo2"
},
]
mock_docker_client.images.search.return_value = test_repositories

test_container_engine = container_engine.ContainerEngine()

# Run unit under test
actual_registry_image_list = test_container_engine.search(test_registry)

# Check expectations
mock_docker_client.images.search.assert_called_once_with(test_registry)

expected_registry_image_list = ["repo1", "repo2"]
assert actual_registry_image_list == expected_registry_image_list
mock_docker_client.images.remove.assert_called_once_with(test_image_to_remove)

0 comments on commit ebb99c1

Please sign in to comment.