Skip to content

Commit

Permalink
Explicitly use the Scenario classes, per review.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Jun 7, 2024
1 parent b5eddbe commit cc64da4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ With that, we can write the simplest possible scenario test:
def test_scenario_base():
ctx = scenario.Context(MyCharm, meta={"name": "foo"})
out = ctx.run(ctx.on.start(), scenario.State())
assert out.unit_status == UnknownStatus()
assert out.unit_status == scenario.UnknownStatus()
```

Now let's start making it more complicated. Our charm sets a special state if it has leadership on 'start':
Expand All @@ -110,7 +110,7 @@ class MyCharm(ops.CharmBase):
def test_status_leader(leader):
ctx = scenario.Context(MyCharm, meta={"name": "foo"})
out = ctx.run(ctx.on.start(), scenario.State(leader=leader))
assert out.unit_status == ActiveStatus('I rule' if leader else 'I am ruled')
assert out.unit_status == scenario.ActiveStatus('I rule' if leader else 'I am ruled')
```

By defining the right state we can programmatically define what answers will the charm get to all the questions it can
Expand Down Expand Up @@ -165,15 +165,15 @@ def test_statuses():
ctx = scenario.Context(MyCharm, meta={"name": "foo"})
out = ctx.run(ctx.on.start(), scenario.State(leader=False))
assert ctx.unit_status_history == [
UnknownStatus(),
MaintenanceStatus('determining who the ruler is...'),
WaitingStatus('checking this is right...'),
scenario.UnknownStatus(),
scenario.MaintenanceStatus('determining who the ruler is...'),
scenario.WaitingStatus('checking this is right...'),
]
assert out.unit_status == ActiveStatus("I am ruled")
assert out.unit_status == scenario.ActiveStatus("I am ruled")

# similarly you can check the app status history:
assert ctx.app_status_history == [
UnknownStatus(),
scenario.UnknownStatus(),
...
]
```
Expand All @@ -198,9 +198,9 @@ class MyCharm(ops.CharmBase):

# ...
ctx = scenario.Context(MyCharm, meta={"name": "foo"})
ctx.run(ctx.on.start(), scenario.State(unit_status=ActiveStatus('foo')))
ctx.run(ctx.on.start(), scenario.State(unit_status=scenario.ActiveStatus('foo')))
assert ctx.unit_status_history == [
ActiveStatus('foo'), # now the first status is active: 'foo'!
scenario.ActiveStatus('foo'), # now the first status is active: 'foo'!
# ...
]
```
Expand Down

0 comments on commit cc64da4

Please sign in to comment.