Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/charms/data_platform_libs/v0/data_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_content(self) -> Dict[str, str]:
"""Getting cached secret content."""
if not self._secret_content:
if self.meta:
self._secret_content = self.meta.get_content()
self._secret_content = self.meta.peek_content()
return self._secret_content

def set_content(self, content: Dict[str, str]) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_data_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_set_additional_fields_secrets(self):
}

secret = self.harness.charm.model.get_secret(id=secret_id)
assert secret.get_content() == {
assert secret.peek_content() == {
"tls": "True",
"tls-ca": "Canonical",
}
Expand Down Expand Up @@ -661,7 +661,7 @@ def test_set_additional_fields_secrets(self):
}

secret = self.harness.charm.model.get_secret(id=secret_id)
assert secret.get_content() == {
assert secret.peek_content() == {
"tls": "True",
"tls-ca": "Canonical",
}
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_data_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ def test_cached_secret_is_cached(harness, mocker):
assert patched_get_content.called_once()


@pytest.mark.usefixtures("only_with_juju_secrets")
def test_add_multiple_secrets(harness):
"""Test that more than one secret key:value can be set."""
cache = SecretCache(harness.charm)

secret = cache.get("label1")
assert not secret
cache.add("label1", {"best-2020-picture": "Nomadland"}, scope="app")

secret = cache.get("label1")
assert secret
content = secret.get_content()
content["best-2021-picture"] = "CODA"
secret.set_content(content)

secret = cache.get("label1")
assert secret
content = secret.get_content()
content["best-2022-picture"] = "Everything Everywhere All at Once"
secret.set_content(content)

# Verify that it made it to Juju, not just to the cache.
secret = harness.model.get_secret(label="label1")
assert secret.get_content() == {
"best-2020-picture": "Nomadland",
"best-2021-picture": "CODA",
"best-2022-picture": "Everything Everywhere All at Once",
}


@pytest.mark.usefixtures("only_with_juju_secrets")
def test_secret_cache(harness):
"""Testing the SecretCache class."""
Expand Down