Skip to content

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juditnovak committed Jan 29, 2024
1 parent 3d1753e commit f500c1a
Show file tree
Hide file tree
Showing 3 changed files with 287 additions and 125 deletions.
22 changes: 22 additions & 0 deletions tests/integration/database-charm/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ set-peer-relation-field:
type: string
description: Value of the field to set

set-peer-secret:
description: Set fields from the second-database relation
params:
component:
type: string
description: app/unit
field:
type: string
description: Relation field
value:
type: string
description: Value of the field to set
individual:
type: boolean
default: False
group:
type: string
default: ''

delete-peer-relation-field:
description: Delete fields from the sedond-database relation
params:
Expand All @@ -95,3 +114,6 @@ delete-peer-secret:
component:
type: string
description: app/unit
group:
type: string
default: ''
38 changes: 36 additions & 2 deletions tests/integration/database-charm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(self, *args):
self.framework.observe(
self.on.set_peer_relation_field_action, self._on_set_peer_relation_field
)
self.framework.observe(self.on.set_peer_secret_action, self._on_set_peer_secret)
self.framework.observe(
self.on.delete_peer_relation_field_action, self._on_delete_peer_relation_field
)
Expand Down Expand Up @@ -310,6 +311,38 @@ def _on_set_peer_relation_field(self, event: ActionEvent):
relation.id, {event.params["field"]: event.params["value"]}
)

def _on_set_peer_secret(self, event: ActionEvent):
"""Set requested relation field."""
component = event.params["component"]

# Charms should be compatible with old vesrions, to simulate rolling upgrade
if DATA_INTERFACES_VERSION <= 17:
relation = self.model.get_relation(PEER)
if component == "app":
relation.data[self.app][event.params["field"]] = event.params["value"]
else:
relation.data[self.unit][event.params["field"]] = event.params["value"]
return

if component == "app":
relation = self.peer_relation_app.relations[0]
self.peer_relation_app.add_secret(
relation.id,
event.params["field"],
event.params["value"],
event.params["individual"],
event.params["group"],
)
else:
relation = self.peer_relation_unit.relations[0]
self.peer_relation_unit.add_secret(
relation.id,
event.params["field"],
event.params["value"],
event.params["individual"],
event.params["group"],
)

def _on_delete_peer_relation_field(self, event: ActionEvent):
"""Delete requested relation field."""
component = event.params["component"]
Expand Down Expand Up @@ -339,10 +372,11 @@ def _on_delete_peer_secret(self, event: ActionEvent):
return

secret = None
group_str = "" if not event.params["group"] else f".{event.params['group']}"
if component == "app":
secret = self.model.get_secret(label="database.app")
secret = self.model.get_secret(label=f"database.app{group_str}")
else:
secret = self.model.get_secret(label="database.unit")
secret = self.model.get_secret(label=f"database.unit{group_str}")

if secret:
secret.remove_all_revisions()
Expand Down
Loading

0 comments on commit f500c1a

Please sign in to comment.