1+ # we don't use the default nixos test because we don't support plv8 with pg 17
12{ self , pkgs } :
23let
34 pname = "plv8" ;
3536 } ;
3637 in
3738 pkg ;
39+ psql_15 = postgresqlWithExtension self . packages . ${ pkgs . system } . postgresql_15 ;
3840in
3941self . inputs . nixpkgs . lib . nixos . runTest {
4042 name = pname ;
4143 hostPkgs = pkgs ;
4244 nodes . server =
43- { config , ... } :
45+ { ... } :
4446 {
4547 virtualisation = {
4648 forwardPorts = [
@@ -59,98 +61,46 @@ self.inputs.nixpkgs.lib.nixos.runTest {
5961 enable = true ;
6062 package = postgresqlWithExtension self . packages . ${ pkgs . system } . postgresql_15 ;
6163 } ;
62-
63- specialisation . postgresql17 . configuration = {
64- services . postgresql = {
65- package = lib . mkForce ( postgresqlWithExtension self . packages . ${ pkgs . system } . postgresql_17 ) ;
66- } ;
67-
68- systemd . services . postgresql-migrate = {
69- serviceConfig = {
70- Type = "oneshot" ;
71- RemainAfterExit = true ;
72- User = "postgres" ;
73- Group = "postgres" ;
74- StateDirectory = "postgresql" ;
75- WorkingDirectory = "${ builtins . dirOf config . services . postgresql . dataDir } " ;
76- } ;
77- script =
78- let
79- oldPostgresql = postgresqlWithExtension self . packages . ${ pkgs . system } . postgresql_15 ;
80- newPostgresql = postgresqlWithExtension self . packages . ${ pkgs . system } . postgresql_17 ;
81- oldDataDir = "${ builtins . dirOf config . services . postgresql . dataDir } /${ oldPostgresql . psqlSchema } " ;
82- newDataDir = "${ builtins . dirOf config . services . postgresql . dataDir } /${ newPostgresql . psqlSchema } " ;
83- in
84- ''
85- if [[ ! -d ${ newDataDir } ]]; then
86- install -d -m 0700 -o postgres -g postgres "${ newDataDir } "
87- ${ newPostgresql } /bin/initdb -D "${ newDataDir } "
88- ${ newPostgresql } /bin/pg_upgrade --old-datadir "${ oldDataDir } " --new-datadir "${ newDataDir } " \
89- --old-bindir "${ oldPostgresql } /bin" --new-bindir "${ newPostgresql } /bin"
90- else
91- echo "${ newDataDir } already exists"
92- fi
93- '' ;
94- } ;
95-
96- systemd . services . postgresql = {
97- after = [ "postgresql-migrate.service" ] ;
98- requires = [ "postgresql-migrate.service" ] ;
99- } ;
100- } ;
101-
10264 } ;
10365 testScript =
104- { nodes , ... } :
105- let
106- pg17-configuration = "${ nodes . server . system . build . toplevel } /specialisation/postgresql17" ;
107- in
66+ { ... } :
10867 ''
68+ from pathlib import Path
10969 versions = {
11070 "15": [${ lib . concatStringsSep ", " ( map ( s : ''"${ s } "'' ) ( versions "15" ) ) } ],
111- "17": [${ lib . concatStringsSep ", " ( map ( s : ''"${ s } "'' ) ( versions "17" ) ) } ],
11271 }
72+ extension_name = "${ pname } "
73+ support_upgrade = False
74+ ext_has_background_worker = ${
75+ if ( installedExtension "15" ) ? hasBackgroundWorker then "True" else "False"
76+ }
77+ sql_test_directory = Path("${ ../../tests } ")
78+ pg_regress_test_name = "${ ( installedExtension "15" ) . pgRegressTestName or pname } "
11379
114- def run_sql(query):
115- return server.succeed(f"""sudo -u postgres psql -t -A -F\",\" -c \"{query}\" """).strip()
116-
117- def check_upgrade_path(pg_version):
118- with subtest("Check ${ pname } upgrade path"):
119- firstVersion = versions[pg_version][0]
120- server.succeed("sudo -u postgres psql -c 'DROP EXTENSION IF EXISTS ${ pname } ;'")
121- run_sql(f"""CREATE EXTENSION ${ pname } WITH VERSION '{firstVersion}' CASCADE;""")
122- installed_version = run_sql(r"""SELECT extversion FROM pg_extension WHERE extname = '${ pname } ';""")
123- assert installed_version == firstVersion, f"Expected ${ pname } version {firstVersion}, but found {installed_version}"
124- for version in versions[pg_version][1:]:
125- server.succeed("sudo -u postgres psql -c 'DROP EXTENSION IF EXISTS ${ pname } ;'")
126- run_sql(f"""CREATE EXTENSION ${ pname } WITH VERSION '{version}' CASCADE;""")
127- installed_version = run_sql(r"""SELECT extversion FROM pg_extension WHERE extname = '${ pname } ';""")
128- assert installed_version == version, f"Expected ${ pname } version {version}, but found {installed_version}"
80+ ${ builtins . readFile ./lib.py }
12981
13082 start_all()
13183
13284 server.wait_for_unit("multi-user.target")
13385 server.wait_for_unit("postgresql.service")
13486
135- check_upgrade_path("15")
87+ test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade)
88+
89+ with subtest("Check upgrade path with postgresql 15"):
90+ test.check_upgrade_path("15")
13691
137- with subtest("Check ${ pname } latest extension version"):
138- server.succeed("sudo -u postgres psql -c 'DROP EXTENSION ${ pname } ;'")
139- server.succeed("sudo -u postgres psql -c 'CREATE EXTENSION ${ pname } CASCADE;'")
140- installed_extensions=run_sql(r"""SELECT extname, extversion FROM pg_extension;""")
141- latestVersion = versions["15"][-1]
142- assert f"${ pname } ,{latestVersion}" in installed_extensions
92+ with subtest("Check pg_regress with postgresql 15 after extension upgrade"):
93+ test.check_pg_regress(Path("${ psql_15 } /lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name)
14394
144- with subtest("switch to postgresql 17"):
145- server.succeed(
146- "${ pg17-configuration } /bin/switch-to-configuration test >&2"
147- )
95+ last_version = None
96+ with subtest("Check the install of the last version of the extension"):
97+ last_version = test.check_install_last_version("15")
14898
149- with subtest("Check ${ pname } latest extension version after upgrade"):
150- installed_extensions=run_sql(r"""SELECT extname, extversion FROM pg_extension;""")
151- latestVersion = versions["17"][-1]
152- assert f"${ pname } ,{latestVersion}" in installed_extensions
99+ if ext_has_background_worker:
100+ with subtest("Test switch_${ pname } _version"):
101+ test.check_switch_extension_with_background_worker(Path("${ psql_15 } /lib/${ pname } .so"), "15")
153102
154- check_upgrade_path("17")
103+ with subtest("Check pg_regress with postgresql 15 after installing the last version"):
104+ test.check_pg_regress(Path("${ psql_15 } /lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name)
155105 '' ;
156106}
0 commit comments