Towards charm unit test case (semi-)auto generation

I am working on a tool called scenario.snapshot that is able, given a unit name, to gather from juju all individual bits and pieces of its State and output that as a monolithic data structure.

That data structure is useful in several ways.

Firstly, it contains data drawn from show-unit, models, status, and several in-unit hook tool call return values, that can be useful in debugging and figuring out what is wrong.

Secondly, you can use that data structure as starting point for writing a unittest able to reproduce locally the same bug in a unittest!

If you come from Harness, think of this as a tool that would output the right sequence of Harness calls necessary to drive the local simulation to the desired state.

You can watch the work progress (and contribute) at: https://github.com/canonical/ops-scenario/pull/1

The core idea

For example, suppose I have a traefik-k8s unit erroring out on update-status.

I can run scenario snapshot trfk/0 -f > ./test.py And in test.py I will obtain a test case that I can rapidly fit to my needs and turn into a unittest:

8 Likes