Skip to content

Commit

Permalink
bootstrap: tests: pass Client into FakeContainers
Browse files Browse the repository at this point in the history
This makes the FakeContainer's created by bootstrap stoppable, too
  • Loading branch information
Williangalvani committed Jul 18, 2023
1 parent 954a43a commit ffd1556
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bootstrap/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ def __repr__(self) -> str:
class FakeContainers:
"""Mocks "Containers" class from docker-py"""

def __init__(self, containers: List[FakeContainer]):
def __init__(self, containers: List[FakeContainer], client: "FakeClient"):
self.containers: Dict[str, FakeContainer] = {container.name: container for container in containers}
self.client = client

def get(self, container: str) -> FakeContainer:
result = self.containers.get(container, None)
Expand All @@ -93,6 +94,7 @@ def remove(self, container: str) -> None:
# pylint: disable=unused-argument
def run(self, image: str, name: str = "", **kargs: Dict[str, Any]) -> None:
self.containers[name] = FakeContainer(name)
self.containers[name].set_client(self.client)

def list(self) -> List[FakeContainer]:
return list(self.containers.values())
Expand All @@ -118,13 +120,13 @@ class FakeClient:
"""Mocks a docker-py client for testing purposes"""

def __init__(self) -> None:
self.containers = FakeContainers([])
self.containers = FakeContainers([], self)
self.images = FakeImages()

def set_active_dockers(self, containers: List[FakeContainer]) -> None:
for container in containers:
container.set_client(self)
self.containers = FakeContainers(containers)
self.containers = FakeContainers(containers, self)


class FakeLowLevelAPI:
Expand Down

0 comments on commit ffd1556

Please sign in to comment.