Skip to content

Commit

Permalink
Merge pull request #10 from canonical/juju-version-support
Browse files Browse the repository at this point in the history
Juju version support
  • Loading branch information
PietroPasotti authored Dec 5, 2023
2 parents e8e9389 + a9457ba commit bc4070b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions interface_tester/interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class _InterfaceTestContext:
input_state: Optional[State] = None
"""Initial state that this test should be run with, according to the test."""

juju_version: Optional[str] = None
"""The juju version Scenario will simulate. Defaults to whatever Scenario's default is."""


def check_test_case_validator_signature(fn: Callable):
"""Verify the signature of a test case validator function.
Expand Down Expand Up @@ -371,11 +374,16 @@ def _run(self, event: Union[str, Event]):
def _run_scenario(self, event: Event, state: State):
logger.debug("running scenario with state=%s, event=%s" % (state, event))

kwargs = {}
if self.ctx.juju_version:
kwargs["juju_version"] = self.ctx.juju_version

ctx = Context(
self.ctx.charm_type,
meta=self.ctx.meta,
actions=self.ctx.actions,
config=self.ctx.config,
**kwargs,
)
return ctx.run(event, state)

Expand Down
8 changes: 8 additions & 0 deletions interface_tester/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
self._config = None
self._interface_name = None
self._interface_version = 0
self._juju_version = None
self._state_template = None

self._charm_spec_cache = None
Expand All @@ -62,6 +63,7 @@ def configure(
interface_name: Optional[str] = None,
interface_version: Optional[int] = None,
state_template: Optional[State] = None,
juju_version: Optional[str] = None,
meta: Optional[Dict[str, Any]] = None,
actions: Optional[Dict[str, Any]] = None,
config: Optional[Dict[str, Any]] = None,
Expand All @@ -79,6 +81,8 @@ def configure(
:param meta: charm metadata.yaml contents.
:param actions: charm actions.yaml contents.
:param config: charm config.yaml contents.
:param juju_version: juju version that Scenario will simulate (also sets JUJU_VERSION
envvar at charm runtime.)
"""
if charm_type:
self._charm_type = charm_type
Expand All @@ -100,6 +104,8 @@ def configure(
self._branch = branch
if base_path:
self._base_path = base_path
if juju_version:
self._juju_version = juju_version

def _validate_config(self):
"""Validate the configuration of the tester.
Expand Down Expand Up @@ -290,6 +296,7 @@ def __repr__(self):
\tconfig={self._config}
\tinterface_name={self._interface_name}
\tinterface_version={self._interface_version}
\tjuju_version={self._juju_version}
\tstate_template={self._state_template}>"""

def run(self) -> bool:
Expand All @@ -315,6 +322,7 @@ def run(self) -> bool:
actions=self.actions,
supported_endpoints=self._gather_supported_endpoints(),
test_fn=test_fn,
juju_version=self._juju_version,
)
try:
with tester_context(ctx):
Expand Down

0 comments on commit bc4070b

Please sign in to comment.