Skip to content

Commit

Permalink
SecretNotFoundError should be raised when a secret is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
juditnovak committed Oct 19, 2023
1 parent ca13b72 commit 3b114d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions scenario/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ops.model import (
ModelError,
SecretInfo,
SecretNotFoundError,
SecretRotate,
_format_action_result_dict,
_ModelBackend,
Expand Down Expand Up @@ -134,12 +135,12 @@ def _get_secret(self, id=None, label=None):
try:
return next(filter(lambda s: s.id == id, self._state.secrets))
except StopIteration:
raise RuntimeError(f"not found: secret with id={id}.")
raise SecretNotFoundError(f"not found: secret with id={id}.")
elif label:
try:
return next(filter(lambda s: s.label == label, self._state.secrets))
except StopIteration:
raise RuntimeError(f"not found: secret with label={label}.")
raise SecretNotFoundError(f"not found: secret with label={label}.")
else:
raise RuntimeError("need id or label.")

Expand Down
6 changes: 3 additions & 3 deletions tests/test_e2e/test_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from ops.charm import CharmBase
from ops.framework import Framework
from ops.model import SecretRotate
from ops.model import SecretNotFoundError, SecretRotate

from scenario.state import Relation, Secret, State
from tests.helpers import trigger
Expand All @@ -25,9 +25,9 @@ def _on_event(self, event):

def test_get_secret_no_secret(mycharm):
def post_event(charm: CharmBase):
with pytest.raises(RuntimeError):
with pytest.raises(SecretNotFoundError):
assert charm.model.get_secret(id="foo")
with pytest.raises(RuntimeError):
with pytest.raises(SecretNotFoundError):
assert charm.model.get_secret(label="foo")

trigger(
Expand Down

0 comments on commit 3b114d3

Please sign in to comment.