Skip to content

Commit

Permalink
chore: mock out everything needed for old idle loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Oct 3, 2024
1 parent 22922d4 commit 968a35e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
4 changes: 4 additions & 0 deletions juju/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@


class Unit(model.ModelEntity):
@property
def name(self) -> str:
return self.entity_id

@property
def agent_status(self):
"""Returns the current agent status string.
Expand Down
57 changes: 54 additions & 3 deletions tests/unit/test_wait_for_idle.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,35 @@ def status_message(self) -> str:

@property
def units(self) -> List[Unit]:
1/0
return self._units

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._units = []


class UnitFake(Unit):
_agent_status: str = ""
_agent_status_message: str = ""
_workload_status: str = ""
_workload_status_message: str = ""

@property
def agent_status(self) -> str:
return self._agent_status

@property
def agent_status_message(self) -> str:
return self._agent_status_message

@property
def workload_status(self) -> str:
return self._workload_status

@property
def workload_status_message(self) -> str:
return self._workload_status_message


@pytest.fixture
def kwargs() -> Dict[str, Any]:
Expand All @@ -103,8 +129,33 @@ def kwargs() -> Dict[str, Any]:
async def test_something(full_status_response, kwargs: Dict[str, Any]):
m = ModelFake()
m._response = full_status_response
m._applications["hexanator"] = ApplicationFake("hexanator", m)
m._applications["grafana-agent-k8s"] = ApplicationFake("grafana-agent-k8s", m)

# FIXME fill these in from response JSON, assert equivalence
app = m._applications["hexanator"] = ApplicationFake("hexanator", m)
app._units.append(u := UnitFake("hexanator/0", m))
u._agent_status = "FIXME"
u._agent_status_message = "FIXME"
u._workload_status = "FIXME"
u._workload_status_message = "FIXME"

app = m._applications["grafana-agent-k8s"] = ApplicationFake("grafana-agent-k8s", m)
app._units.append(u := UnitFake("grafana-agent-k8s/0", m))
u._agent_status = "FIXME"
u._agent_status_message = "FIXME"
u._workload_status = "FIXME"
u._workload_status_message = "FIXME"

app = m._applications["mysql-test-app"] = ApplicationFake("mysql-test-app", m)
app._units.append(u := UnitFake("mysql-test-app/0", m))
u._agent_status = "FIXME"
u._agent_status_message = "FIXME"
u._workload_status = "FIXME"
u._workload_status_message = "FIXME"
app._units.append(u := UnitFake("mysql-test-app/1", m))
u._agent_status = "FIXME"
u._agent_status_message = "FIXME"
u._workload_status = "FIXME"
u._workload_status_message = "FIXME"

try:
idle = await m._check_idle(**kwargs)
Expand Down

0 comments on commit 968a35e

Please sign in to comment.