refactor: use later begin
rather than re-instantiating the harness charm
#147
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The charm conditionally sets the unit status (and does some other work, including observing) based on the result of setting up a configuration object during
__init__
. This isn't a practice that Charm Tech recommends, and it's one that currently works in production (if defer is not used) but is not supported by Harness (which won't be changed, unfortunately).At the moment, the tests have a workaround where the harness charm is reinstantiated using private methods of both the harness framework and harness itself. This PR removes the reinstantiation, so that the private use is not required.
The actual change is pretty straightforward: it just waits until all the setup is complete (in particular, setting the config values) before calling
harness.begin()
(which executes the charm's__init__
).This PR does not change any of the tests, other than replacing the
reinstantiate_charm()
call withself.harness.begin()
. To minimise the impact of the change, these tests are moved to a separateTestCase
subclass. An alternative that would result in fewer lines changing (e.g. in blame) would be to remove thebegin()
from the existing class and add it in explicitly to each test case (that doesn't do thereinstantiate()
), but this change seemed cleaner.Checklist: