diff --git a/config.yaml b/config.yaml index 781c213e62..e86db9a62e 100644 --- a/config.yaml +++ b/config.yaml @@ -123,6 +123,10 @@ options: default: false type: boolean description: Enable unaccent extension + plugin_plpgsql_enable: + default: true + type: boolean + description: Enable plpgsql extension profile: description: | Profile representing the scope of deployment, and used to tune resource allocation. diff --git a/tests/integration/test_plugins.py b/tests/integration/test_plugins.py index 9d9edea3be..5c0680c8bc 100644 --- a/tests/integration/test_plugins.py +++ b/tests/integration/test_plugins.py @@ -24,12 +24,17 @@ PG_TRGM_EXTENSION_STATEMENT = "SELECT word_similarity('word', 'two words');" PLPYTHON3U_EXTENSION_STATEMENT = 'CREATE FUNCTION plpython_test() RETURNS varchar[] AS $$ return "hello" $$ LANGUAGE plpython3u;' UNACCENT_EXTENSION_STATEMENT = "SELECT ts_lexize('unaccent','Hôtel');" +PLPGSQL_EXTENSION_STATEMENT = "CREATE FUNCTION add_one (integer) RETURNS INTEGER AS $$ BEGIN RETURN $1 + 1; END; $$ LANGUAGE plpgsql;" @pytest.mark.abort_on_fail async def test_plugins(ops_test: OpsTest) -> None: """Build and deploy one unit of PostgreSQL and then test the available plugins.""" # Build and deploy the PostgreSQL charm. + logger.info("disabling plugins enabled by default") + config = { + "plugin_plpgsql_enable": "False", + } async with ops_test.fast_forward(): charm = await ops_test.build_charm(".") await ops_test.model.deploy( @@ -37,6 +42,7 @@ async def test_plugins(ops_test: OpsTest) -> None: num_units=2, series=CHARM_SERIES, ) + await ops_test.model.applications[DATABASE_APP_NAME].set_config(config) await ops_test.model.wait_for_idle(apps=[DATABASE_APP_NAME], status="active") # Check that the available plugins are disabled. @@ -70,6 +76,10 @@ async def test_plugins(ops_test: OpsTest) -> None: # Test unaccent extension disabled. with pytest.raises(psycopg2.Error): connection.cursor().execute(UNACCENT_EXTENSION_STATEMENT) + + # Test plpgsql extension disabled. + with pytest.raises(psycopg2.Error): + connection.cursor().execute(PLPGSQL_EXTENSION_STATEMENT) connection.close() # Enable the plugins. @@ -107,4 +117,7 @@ async def test_plugins(ops_test: OpsTest) -> None: # Test unaccent extension enabled. connection.cursor().execute(UNACCENT_EXTENSION_STATEMENT) + + # Test plpgsql extension enabled. + connection.cursor().execute(PLPGSQL_EXTENSION_STATEMENT) connection.close()