Skip to content

Commit

Permalink
Fix relatior error when extra user roles field has no value (#44)
Browse files Browse the repository at this point in the history
* Fix relatior error when extra user roles field has no value

* Add test
  • Loading branch information
marceloneppel authored Feb 10, 2023
1 parent afbab16 commit 2d58de0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/relations/pgbouncer_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _on_database_requested(self, event: DatabaseRequestedEvent) -> None:

# Retrieve the database name and extra user roles using the charm library.
databases = event.database
extra_user_roles = event.extra_user_roles
extra_user_roles = event.extra_user_roles or ""
rel_id = event.relation.id

# Creates the user and the database for this specific relation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
logger = logging.getLogger(__name__)

CLIENT_APP_NAME = "application"
DATA_INTEGRATOR_APP_NAME = "data-integrator"
CLIENT_UNIT_NAME = f"{CLIENT_APP_NAME}/0"
TEST_DBNAME = "application_first_database"
ANOTHER_APPLICATION_APP_NAME = "another-application"
Expand Down Expand Up @@ -424,3 +425,17 @@ async def test_relation_broken(ops_test: OpsTest):
cfg = await get_cfg(ops_test, pgb_unit_name)
assert "first-database" not in cfg["databases"].keys()
assert "first-database_readonly" not in cfg["databases"].keys()


@pytest.mark.client_relation
async def test_relation_with_data_integrator(ops_test: OpsTest):
"""Test that the charm can be related to the data integrator without extra user roles."""
config = {"database-name": "test-database"}
await ops_test.model.deploy(
DATA_INTEGRATOR_APP_NAME,
channel="edge",
config=config,
)
await ops_test.model.add_relation(f"{PGB}:database", DATA_INTEGRATOR_APP_NAME)
async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(status="active")
1 change: 0 additions & 1 deletion tests/integration/relations/test_peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ async def test_scaling(ops_test: OpsTest):
# Ensure the initial number of units in the application.
initial_scale = 4
async with ops_test.fast_forward():

await scale_application(ops_test, PGB, initial_scale)
await asyncio.gather(
ops_test.model.wait_for_idle(apps=[MAILMAN], status="active", timeout=600),
Expand Down

0 comments on commit 2d58de0

Please sign in to comment.