Skip to content

Commit 6443413

Browse files
committed
Add nixos test for pg_partman extension
Run upgrade and pg_regress tests for pg_partman extension in NixOS tests.
1 parent 1a1a72b commit 6443413

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

nix/ext/pg_partman.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ pkgs.buildEnv {
9797
inherit versions numberOfVersions switch-ext-version;
9898
pname = "${pname}-all";
9999
hasBackgroundWorker = true;
100+
defaultSchema = "partman";
100101
defaultSettings = {
101-
shared_preload_libraries = [ "pg_partman_bgw" ];
102+
shared_preload_libraries = [ "pg_partman" ];
102103
};
103104
version =
104105
"multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions);

nix/ext/tests/default.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,14 @@ let
146146
"17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "17"))}],
147147
}
148148
extension_name = "${pname}"
149+
support_upgrade = True
149150
pg17_configuration = "${pg17-configuration}"
150151
ext_has_background_worker = ${
151152
if (installedExtension "15") ? hasBackgroundWorker then "True" else "False"
152153
}
153154
sql_test_directory = Path("${../../tests}")
154155
pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}"
156+
ext_schema = "${(installedExtension "15").defaultSchema or "public"}"
155157
156158
${builtins.readFile ./lib.py}
157159
@@ -160,7 +162,8 @@ let
160162
server.wait_for_unit("multi-user.target")
161163
server.wait_for_unit("postgresql.service")
162164
163-
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory)
165+
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema)
166+
test.create_schema()
164167
165168
with subtest("Check upgrade path with postgresql 15"):
166169
test.check_upgrade_path("15")
@@ -224,6 +227,7 @@ builtins.listToAttrs (
224227
"pg_stat_monitor"
225228
"pg_tle"
226229
"pgaudit"
230+
"pg_partman"
227231
"vector"
228232
"wal2json"
229233
"wrappers"

nix/ext/tests/lib.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(
2020
versions: Versions,
2121
sql_test_dir: Path,
2222
support_upgrade: bool = True,
23+
schema: str = "public",
2324
):
2425
"""Initialize the PostgreSQL extension test framework.
2526
@@ -35,6 +36,10 @@ def __init__(
3536
self.versions = versions
3637
self.support_upgrade = support_upgrade
3738
self.sql_test_dir = sql_test_dir
39+
self.schema = schema
40+
41+
def create_schema(self):
42+
self.run_sql(f"CREATE SCHEMA IF NOT EXISTS {self.schema};")
3843

3944
def run_sql(self, query: str) -> str:
4045
return self.vm.succeed(
@@ -50,8 +55,12 @@ def drop_extension(self):
5055
self.run_sql(f"DROP EXTENSION IF EXISTS {self.extension_name};")
5156

5257
def install_extension(self, version: str):
58+
if self.schema != "public":
59+
ext_schema = f"SCHEMA {self.schema} "
60+
else:
61+
ext_schema = ""
5362
self.run_sql(
54-
f"""CREATE EXTENSION {self.extension_name} WITH VERSION '{version}' CASCADE;"""
63+
f"""CREATE EXTENSION {self.extension_name} WITH {ext_schema}VERSION '{version}' CASCADE;"""
5564
)
5665
# Verify version was installed correctly
5766
self.assert_version_matches(version)

nix/tests/expected/pg_partman.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ SELECT partman.create_parent(
1818
t
1919
(1 row)
2020

21+
DROP SCHEMA partman_test CASCADE;
22+
NOTICE: drop cascades to 2 other objects
23+
DETAIL: drop cascades to table partman_test.time_taptest_table
24+
drop cascades to table partman_test.time_taptest_table_template

nix/tests/sql/pg_partman.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ SELECT partman.create_parent(
1818
, p_interval := '1 day'
1919
, p_template_table := 'partman_test.time_taptest_table_template'
2020
);
21+
22+
DROP SCHEMA partman_test CASCADE;

0 commit comments

Comments
 (0)