Skip to content

Commit

Permalink
Bump coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirp committed Sep 26, 2023
1 parent 5355879 commit 31a013f
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions tests/unit/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,6 @@ def test_on_s3_credential_changed(
_can_use_s3_repository,
_initialise_stanza,
):
with self.harness.hooks_disabled():
self.harness.set_leader()

# Test when the cluster was not initialised yet.
self.relate_to_s3_integrator()
self.charm.backup.s3_client.on.credentials_changed.emit(
Expand Down Expand Up @@ -693,6 +690,29 @@ def test_on_s3_credential_changed(
_can_use_s3_repository.assert_not_called()
_initialise_stanza.assert_not_called()

# Test that followers will not initialise the bucket
self.charm.unit.status = ActiveStatus()
_render_pgbackrest_conf_file.reset_mock()
with self.harness.hooks_disabled():
self.harness.update_relation_data(
self.peer_rel_id,
self.charm.app.name,
{"cluster_initialised": "True"},
)
_render_pgbackrest_conf_file.return_value = True

self.charm.backup.s3_client.on.credentials_changed.emit(
relation=self.harness.model.get_relation(S3_PARAMETERS_RELATION, self.s3_rel_id)
)
_render_pgbackrest_conf_file.assert_called_once()
_create_bucket_if_not_exists.assert_not_called()
self.assertIsInstance(self.charm.unit.status, ActiveStatus)
_can_use_s3_repository.assert_not_called()
_initialise_stanza.assert_not_called()

with self.harness.hooks_disabled():
self.harness.set_leader()

# Test when the charm render the pgBackRest configuration file, but fails to
# access or create the S3 bucket.
for error in [
Expand All @@ -702,16 +722,8 @@ def test_on_s3_credential_changed(
),
ValueError,
]:
self.charm.unit.status = ActiveStatus()
_render_pgbackrest_conf_file.reset_mock()
_create_bucket_if_not_exists.reset_mock()
with self.harness.hooks_disabled():
self.harness.update_relation_data(
self.peer_rel_id,
self.charm.app.name,
{"cluster_initialised": "True"},
)
_render_pgbackrest_conf_file.return_value = True
_create_bucket_if_not_exists.side_effect = error
self.charm.backup.s3_client.on.credentials_changed.emit(
relation=self.harness.model.get_relation(S3_PARAMETERS_RELATION, self.s3_rel_id)
Expand Down Expand Up @@ -747,6 +759,17 @@ def test_on_s3_credential_changed(
_can_use_s3_repository.assert_called_once()
_initialise_stanza.assert_called_once()

def test_on_s3_credential_gone(self):
# Test that unrelated blocks will remain
self.charm.unit.status = BlockedStatus("test block")
self.charm.backup._on_s3_credential_gone(None)
self.assertIsInstance(self.charm.unit.status, BlockedStatus)

# Test that s3 related blocks will be cleared
self.charm.unit.status = BlockedStatus(ANOTHER_CLUSTER_REPOSITORY_ERROR_MESSAGE)
self.charm.backup._on_s3_credential_gone(None)
self.assertIsInstance(self.charm.unit.status, ActiveStatus)

@patch("charm.PostgresqlOperatorCharm.update_config")
@patch("charm.PostgreSQLBackups._change_connectivity_to_database")
@patch("charm.PostgreSQLBackups._list_backups")
Expand Down

0 comments on commit 31a013f

Please sign in to comment.