diff --git a/tests/integration/test_opensearch_charm.py b/tests/integration/test_opensearch_charm.py index a8064102..276bcfd4 100644 --- a/tests/integration/test_opensearch_charm.py +++ b/tests/integration/test_opensearch_charm.py @@ -7,7 +7,7 @@ import pytest from pytest_operator.plugin import OpsTest -from .helpers import get_application_relation_data +from .helpers import get_application_relation_data, get_juju_secret logger = logging.getLogger(__name__) @@ -41,6 +41,7 @@ async def test_deploy_charms(ops_test: OpsTest, application_charm, opensearch_ch @pytest.mark.abort_on_fail +@pytest.mark.usefixtures("only_without_juju_secrets") async def test_opensearch_relation_with_charm_libraries(ops_test: OpsTest): """Test basic functionality of opensearch relation interface.""" # Relate the charms and wait for them exchanging some connection data. @@ -71,3 +72,39 @@ async def test_opensearch_relation_with_charm_libraries(ops_test: OpsTest): assert password == "password" assert endpoints == "host1:port,host2:port" assert index == "test-index" + + +@pytest.mark.abort_on_fail +@pytest.mark.usefixtures("only_with_juju_secrets") +async def test_opensearch_relation_with_charm_libraries_secrets(ops_test: OpsTest): + """Test basic functionality of opensearch relation interface.""" + # Relate the charms and wait for them exchanging some connection data. + await ops_test.model.add_relation(OPENSEARCH_APP_NAME, APPLICATION_APP_NAME) + await ops_test.model.wait_for_idle(apps=APP_NAMES, status="active") + + # check unit messagge to check if the index_created_event is triggered + for unit in ops_test.model.applications[APPLICATION_APP_NAME].units: + assert unit.workload_status_message == "opensearch_index_created" + # check if index access is granted + for unit in ops_test.model.applications[OPENSEARCH_APP_NAME].units: + assert "granted" in unit.workload_status_message + + secret_uri = await get_application_relation_data( + ops_test, APPLICATION_APP_NAME, RELATION_NAME, "secret" + ) + + secret_content = await get_juju_secret(ops_test, secret_uri) + username = secret_content["username"] + password = secret_content["password"] + + endpoints = await get_application_relation_data( + ops_test, APPLICATION_APP_NAME, RELATION_NAME, "endpoints" + ) + index = await get_application_relation_data( + ops_test, APPLICATION_APP_NAME, RELATION_NAME, "index" + ) + + assert username == "admin" + assert password == "password" + assert endpoints == "host1:port,host2:port" + assert index == "test-index"