-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DPE-4335] Do not trigger secret revision change if the relation cont…
…ent is the same (#169) * fix: Compare content before updating relation-based secret * tests: Assert that relation-based secret revision changes with new content * refactor: Move fix to CachedSecret.set_content * tests: Extract secret revision test in its own test * tests: Add non peer relation test for secret revision * fix: Use correct var in integration charm * fix: Use correct label name in test * tests: Add unit test for data interface cached secret * chore: Revert uneeded changes * tests: Add interface-focused test for secret revision changes * chore: Format
- Loading branch information
Showing
6 changed files
with
211 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Component level tests.""" | ||
|
||
from unittest.mock import Mock | ||
|
||
import pytest | ||
from ops.charm import CharmBase | ||
from ops.testing import Harness | ||
|
||
from charms.data_platform_libs.v0.data_interfaces import CachedSecret | ||
|
||
|
||
class EmptyCharm(CharmBase): | ||
"""Mock database charm to use in units tests.""" | ||
|
||
def __init__(self, *args): | ||
super().__init__(*args) | ||
|
||
|
||
@pytest.fixture | ||
def harness() -> Harness: | ||
harness = Harness(EmptyCharm) | ||
harness.set_leader(True) | ||
harness.begin_with_initial_hooks() | ||
return harness | ||
|
||
|
||
@pytest.mark.usefixtures("only_with_juju_secrets") | ||
@pytest.mark.parametrize("scope", [("app"), ("unit")]) | ||
def test_cached_secret_no_update(scope, harness: Harness[EmptyCharm], monkeypatch): | ||
"""Check that a cached secret do not trigger a revision if no update to content.""" | ||
# Given | ||
content = {"value": "initialvalue"} | ||
secret = CachedSecret(harness.model, getattr(harness.charm, scope), "my-label") | ||
secret.add_secret(content) | ||
patched = Mock() | ||
# When | ||
with monkeypatch.context() as m: | ||
m.setattr(secret.meta, "set_content", patched) | ||
secret.set_content(content) | ||
|
||
secret.set_content({"value": "newvalue"}) | ||
|
||
# Then | ||
patched.assert_called_once() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters