Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add plpgsql extension #262

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,25 @@
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(
charm,
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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Loading