forked from canonical/operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for testing actions with Harness (canonical#1053)
Adds support for testing actions with `ops.testing.Harness`. ### New classes in `ops.testing` * `ActionOutput`: contains the logs and results from (simulating) running an action. * `ActionFailed`: raised when a (simulated) action run calls `ActionEvent.fail()`. * `_RunningAction`: bundles data about an action run. ### New `ops.testing.Harness` method: `run_action()` * This simulates running an action with Juju, e.g. `juju run name/ord action-name param=value`. Optionally takes additional parameters, and either returns an `ActionOutput` object or raises `ActionFailed`. ### Minor changes * Adds `additionalProperties` to `CharmMeta` (to allow validating that additional parameters are not passed) * Removes the check in `ActionEvent`'s restore that `JUJU_ACTION_NAME` matches the event's action. This was only a sanity check, and the complexity it caused in implementing the simulated action was not worth the minimal value of the check. ### Comments on state A reasonable amount of additional state is added to `_TestingModelBackend` (a `_RunningAction` instance, which contains `None`, and empty dict, and an `ActionOutput` instance, which itself has an empty list and empty dict), which is only required during the `run_action` call. After a `run_action` call this state still exists, but may also contain logs, results, and a failure message from the event handler. ### Other Notes See [OP041](https://docs.google.com/document/d/1nxyiR7H7ZJZUIOfyIrEudmTg64jDJvPnPLCAeD1R7w0) (Canonical internal link). Fixes canonical#762.
- Loading branch information
1 parent
bee7833
commit bc8a5f7
Showing
7 changed files
with
274 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.