canonical / ops-scenario

State-transition testing SDK for Operator Framework Juju charms.
Apache License 2.0
10 stars 7 forks source link

feat!: make action events more like other events #161

Closed tonyandrewmeyer closed 1 month ago

tonyandrewmeyer commented 1 month ago

This adjusts emitting action events to align with emitting other events.

When needing to pass params, instead of having to create an Action object, these can just be passed in the run call in the same way that extra parameters for notices, relations, etc are. When using params, the code is about the same size - when there are no parameters it's a little longer than just having a string, but much more consistent, both with the other events, and with using observe.

Example:

# Non-action event
ctx = Context(MyCharm)
ctx.run(ctx.on.start(), State())

# Action event, no params
ctx = Context(MyCharm)
ctx.run(ctx.on.action("foo"), State())

# Action event, params
ctx = Context(MyCharm)
ctx.run(ctx.on.action("foo", params={"bar": 123}), State())