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

storage #65

Merged
merged 4 commits into from
Oct 18, 2023
Merged

storage #65

merged 4 commits into from
Oct 18, 2023

Conversation

PietroPasotti
Copy link
Collaborator

This PR implements storage mocks for Scenario and adds API to State and Context to work with them.

from scenario import Storage, Context, State

# some charm with a 'foo' filesystem-type storage defined in metadata.yaml 
ctx = Context(MyCharm)
storage = Storage("foo")
# setup storage with some content
(storage.get_filesystem(ctx) / "myfile.txt").write_text("helloworld")

with ctx.manager("update-status", State(storage=[storage])) as mgr:
    foo = mgr.charm.model.storages["foo"][0]
    loc = foo.location
    path = loc / "myfile.txt"
    assert path.exists()
    assert path.read_text() == "helloworld"

    myfile = loc / "path.py"
    myfile.write_text("helloworlds")

# post-mortem: inspect fs contents.
assert (
    storage.get_filesystem(ctx) / "path.py"
).read_text() == "helloworlds"

Feature creeps:

  • _EntityStatus now supports subclass checks: isinstance(State.unit_status, ops.ActiveStatus)
  • State.planned_units mock

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! API seems consistent with the rest of Scenario.

Just left a couple of style nit comments.

scenario/mocking.py Outdated Show resolved Hide resolved
scenario/mocking.py Outdated Show resolved Hide resolved
scenario/state.py Show resolved Hide resolved
@PietroPasotti PietroPasotti merged commit 55cb4e0 into main Oct 18, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants