Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TakoB222 committed Oct 16, 2023
1 parent f13743c commit 3c60db0
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 10 deletions.
12 changes: 9 additions & 3 deletions tests/integration/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
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');"
BLOOM_EXTENSION_STATEMENT = "CREATE TABLE tbloom_test (i int);CREATE INDEX btreeidx ON tbloom_test USING bloom (i);"
BLOOM_EXTENSION_STATEMENT = (
"CREATE TABLE tbloom_test (i int);CREATE INDEX btreeidx ON tbloom_test USING bloom (i);"
)
BTREEGIN_EXTENSION_STATEMENT = "CREATE TABLE btree_gin_test (a int4);CREATE INDEX btreeginidx ON btree_gin_test USING GIN (a);"
BTREEGIST_EXTENSION_STATEMENT = "CREATE TABLE btree_gist_test (a int4);CREATE INDEX btreegistidx ON btree_gist_test USING GIST (a);"
CUBE_EXTENSION_STATEMENT = "SELECT cube_inter('(0,-1),(1,1)', '(-2),(2)');"
Expand All @@ -37,8 +39,12 @@
LO_EXTENSION_STATEMENT = "CREATE TABLE lo_test (value lo);"
LTREE_EXTENSION_STATEMENT = "CREATE TABLE ltree_test (path ltree);"
OLD_SNAPSHOT_EXTENSION_STATEMENT = "SELECT * from pg_old_snapshot_time_mapping();"
PG_FREESPACEMAP_EXTENSION_STATEMENT = "CREATE TABLE pg_freespacemap_test (i int);SELECT * FROM pg_freespace('pg_freespacemap_test');"
PGROWLOCKS_EXTENSION_STATEMENT = "CREATE TABLE pgrowlocks_test (i int);SELECT * FROM pgrowlocks('pgrowlocks_test');"
PG_FREESPACEMAP_EXTENSION_STATEMENT = (
"CREATE TABLE pg_freespacemap_test (i int);SELECT * FROM pg_freespace('pg_freespacemap_test');"
)
PGROWLOCKS_EXTENSION_STATEMENT = (
"CREATE TABLE pgrowlocks_test (i int);SELECT * FROM pgrowlocks('pgrowlocks_test');"
)
PGSTATTUPLE_EXTENSION_STATEMENT = "SELECT * FROM pgstattuple('pg_catalog.pg_proc');"
PG_VISIBILITY_EXTENSION_STATEMENT = "CREATE TABLE pg_visibility_test (i int);SELECT * FROM pg_visibility('pg_visibility_test'::regclass);"
SEG_EXTENSION_STATEMENT = "SELECT '10(+-)1'::seg as seg;"
Expand Down
83 changes: 76 additions & 7 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_enable_disable_extensions(self):
postgresql_mock.enable_disable_extension.side_effect = None
with self.assertNoLogs("charm", "ERROR"):
self.charm.enable_disable_extensions()
self.assertEqual(postgresql_mock.enable_disable_extension.call_count, 6)
self.assertEqual(postgresql_mock.enable_disable_extension.call_count, 29)

# Test when one extension install/uninstall fails.
postgresql_mock.reset_mock()
Expand All @@ -265,7 +265,7 @@ def test_enable_disable_extensions(self):
)
with self.assertLogs("charm", "ERROR") as logs:
self.charm.enable_disable_extensions()
self.assertEqual(postgresql_mock.enable_disable_extension.call_count, 6)
self.assertEqual(postgresql_mock.enable_disable_extension.call_count, 29)
self.assertIn("failed to disable citext plugin", "".join(logs.output))

# Test when one config option should be skipped (because it's not related
Expand All @@ -289,17 +289,86 @@ def test_enable_disable_extensions(self):
plugin_unaccent_enable:
default: false
type: boolean
profile:
default: production
type: string
plugin_debversion_enable:
default: false
type: boolean"""
type: boolean
plugin_bloom_enable:
default: false
type: boolean
plugin_btree_gin_enable:
default: false
type: boolean
plugin_btree_gist_enable:
default: false
type: boolean
plugin_cube_enable:
default: false
type: boolean
plugin_dict_int_enable:
default: false
type: boolean
plugin_dict_xsyn_enable:
default: false
type: boolean
plugin_earthdistance_enable:
default: false
type: boolean
plugin_fuzzystrmatch_enable:
default: false
type: boolean
plugin_intarray_enable:
default: false
type: boolean
plugin_isn_enable:
default: false
type: boolean
plugin_lo_enable:
default: false
type: boolean
plugin_ltree_enable:
default: false
type: boolean
plugin_old_snapshot_enable:
default: false
type: boolean
plugin_pg_freespacemap_enable:
default: false
type: boolean
plugin_pgrowlocks_enable:
default: false
type: boolean
plugin_pgstattuple_enable:
default: false
type: boolean
plugin_pg_visibility_enable:
default: false
type: boolean
plugin_seg_enable:
default: false
type: boolean
plugin_tablefunc_enable:
default: false
type: boolean
plugin_tcn_enable:
default: false
type: boolean
plugin_tsm_system_rows_enable:
default: false
type: boolean
plugin_tsm_system_time_enable:
default: false
type: boolean
plugin_uuid-ossp_enable:
default: false
type: boolean
profile:
default: production
type: string"""
harness = Harness(PostgresqlOperatorCharm, config=config)
self.addCleanup(harness.cleanup)
harness.begin()
harness.charm.enable_disable_extensions()
self.assertEqual(postgresql_mock.enable_disable_extension.call_count, 6)
self.assertEqual(postgresql_mock.enable_disable_extension.call_count, 29)

@patch("charm.PostgresqlOperatorCharm.enable_disable_extensions")
@patch("charm.snap.SnapCache")
Expand Down

0 comments on commit 3c60db0

Please sign in to comment.