Testing the action event
Right now there is no option how to test action event with Harness. I believed it should be added as a feature and if I'm not mistaken, it could be an easy task.
Example, how I'm testing it now:
os.environ["JUJU_ACTION_NAME"] = "<action-name>"
harness.charm.framework.model._backend.action_get = mock_action_get = MagicMock()
harness.charm.framework.model._backend.action_set = mock_action_set = MagicMock()
harness.charm.framework.model._backend.action_fail = mock_action_fail = MagicMock()
harness.charm.on.<action-name>_action.emit()
This should be pretty straight forward. We'll need to add something similar to Harness.update_config that allows tests to set what the action params/args are when the event is triggered - e.g. harness.run_action(*args). And then implementing action-get/set/etc funcs for the testing backend.
So it is already possible to do something like:
harness.charm.on.some_action.emit()
And get the actual action event to be emitted. However action_get/action_set/etc are not implemented.
I do think a cleaner mechanism for calling an action and evaluating its results would be useful. (For the lifetime of the action that is running, we should have content for action_get to return the parameters that have been supplied, and we could easily return the dict represented by calls to action_set at the end of the function (and raise an exception? for action_fail).
It probably needs to be some sort of context object, because you only one those values to exist for the lifetime of the action being run.
(I ran into this again trying to test one of my old charms that has an action in it.)
I still have to implement this in scenario as well, good to keep in mind :)
For the record, this would still be very useful. Also for the record, Pietro has now included this in Scenario.
@tonyandrewmeyer is going to try to tackle this in the next few weeks.