canonical / ops-scenario

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

refactor!: rename Container.exec_mocks to Container.execs and extend mocking #124

Closed tonyandrewmeyer closed 4 weeks ago

tonyandrewmeyer commented 5 months ago

Firstly, some simple renaming:

A behaviour change that is a bugfix:

Some more substantial changes:

We could add more of the functionality that Harness has, but I think this is a solid subset (I've wanted to be able to get to the stdin in writing tests myself, and the simple mock matching seems handy). It should be easy enough to extend in the future without needing API changes, I think, since this now has both input and output. The key parts that are missing are properly supporting binary IO and the execution context.

tonyandrewmeyer commented 3 months ago

The PR description seems to suggest this isn't quite ready for review. Gave it a quick look and found a couple of things that need clarification.

Ah indeed, I missed that when moving a bunch to ready. Should be ok for review now, although there are some things to decide before it could actually be mergable.

benhoyt commented 3 months ago

We (Tony, Dima, me) briefly discussed in our daily sync today and agreed:

1) execs should be a set (like other top-level types are now) 2) The prefix-matching in Harness.handle_exec has been very useful, and we think we should replicate it here. The first argument of scenario.Exec will be command_prefix (not keyword-only). Often just saying execs={scenario.Exec(['ls'])} or similar will be enough. 3) The stdin field is an output field, so we need a way to get the Exec output instance. We'd add a Container.get_exec() method where the lookup argument was either the command_prefix or the input exec instance -- same as other get_foo methods at the top level.

tonyandrewmeyer commented 4 weeks ago

@PietroPasotti are you good with how this has ended up?