Skip to content

Commit b9db725

Browse files
committed
fix: add PostgreSQL authentication config to extension tests
The index_advisor and http extension tests were missing PostgreSQL authentication configuration that allows the supabase_admin user to connect, causing test failures with 'Peer authentication failed'. Also fixed OrioleDB extension testing where schemas were not recreated after database reinitialization when switching to OrioleDB specialization. Additionally addressed all PR review comments: - Added missing test.create_schema() call in http.nix after OrioleDB switch - Added missing test.create_schema() call in index_advisor.nix after OrioleDB switch - Made PostgresExtensionTest instantiation consistent across all test files - Added explicit support_upgrade, ext_schema, and lib_name parameters - Added create_schema() call after test instantiation - Fixed background worker library path to use lib_name instead of pname Code quality improvements (nitpicks): - Standardized system references to use pkgs.stdenv.hostPlatform.system throughout - Added safety checks before rm -rf operations to prevent accidental deletion - Improved consistency across all extension test files - Fixed shared library path resolution for background worker tests Changes made: - Added authentication, identMap, and ensureUsers configuration - Added default settings to postgresql17 specializations - Added schema creation after OrioleDB switch to handle reinitialization in all files - Fixed PostgreSQL peer authentication for test infrastructure - Standardized extension test patterns across all test files - Added safety guards for data directory deletion operations - Consistent cross-compilation support with hostPlatform.system - Updated library path resolution to use proper libName for .so files This ensures extension tests can properly connect to PostgreSQL instances, that schemas exist for extension installation during upgrade path and pg_regress testing with OrioleDB, and that background worker tests use the correct shared library names.
1 parent a4a591f commit b9db725

File tree

3 files changed

+75
-12
lines changed

3 files changed

+75
-12
lines changed

nix/ext/tests/default.nix

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let
5353
in
5454
pkg;
5555
psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15;
56-
psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17;
56+
psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17;
5757
orioledb_17 =
5858
postgresqlWithExtension
5959
self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17;
@@ -148,7 +148,9 @@ let
148148

149149
specialisation.orioledb17.configuration = {
150150
services.postgresql = {
151-
package = lib.mkForce (postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17);
151+
package = lib.mkForce (
152+
postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17
153+
);
152154
settings = lib.mkForce (
153155
((installedExtension "17").defaultSettings or { })
154156
// {
@@ -183,11 +185,17 @@ let
183185
};
184186
script =
185187
let
186-
newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17;
188+
newPostgresql =
189+
postgresqlWithExtension
190+
self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17;
187191
in
188192
''
189193
set -x
190194
systemctl cat postgresql.service
195+
if [[ -z "${newPostgresql.psqlSchema}" ]]; then
196+
echo "Error: psqlSchema is empty, refusing to rm -rf"
197+
exit 1
198+
fi
191199
rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}
192200
'';
193201
};
@@ -276,6 +284,7 @@ let
276284
)
277285
installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""")
278286
assert "orioledb" in installed_extensions
287+
test.create_schema()
279288
280289
with subtest("Check upgrade path with orioledb 17"):
281290
test.check_upgrade_path("orioledb-17")

nix/ext/tests/http.nix

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ let
4444
};
4545
in
4646
pkg;
47-
psql_15 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_15;
48-
psql_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_17;
49-
orioledb_17 = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17;
47+
psql_15 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15;
48+
psql_17 = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17;
49+
orioledb_17 =
50+
postgresqlWithExtension
51+
self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17;
5052
in
5153
self.inputs.nixpkgs.lib.nixos.runTest {
5254
name = pname;
@@ -70,6 +72,20 @@ self.inputs.nixpkgs.lib.nixos.runTest {
7072
services.postgresql = {
7173
enable = true;
7274
package = postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_15;
75+
authentication = ''
76+
local all postgres peer map=postgres
77+
local all all peer map=root
78+
'';
79+
identMap = ''
80+
root root supabase_admin
81+
postgres postgres postgres
82+
'';
83+
ensureUsers = [
84+
{
85+
name = "supabase_admin";
86+
ensureClauses.superuser = true;
87+
}
88+
];
7389
initialScript = pkgs.writeText "init-postgres" ''
7490
CREATE TABLE IF NOT EXISTS test_config (key TEXT PRIMARY KEY, value TEXT);
7591
INSERT INTO test_config (key, value) VALUES ('http_mock_port', '8880') ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value;
@@ -91,6 +107,7 @@ self.inputs.nixpkgs.lib.nixos.runTest {
91107
package = lib.mkForce (
92108
postgresqlWithExtension self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_17
93109
);
110+
settings = ((installedExtension "17").defaultSettings or { });
94111
};
95112

96113
systemd.services.postgresql-migrate = {
@@ -172,11 +189,17 @@ self.inputs.nixpkgs.lib.nixos.runTest {
172189
};
173190
script =
174191
let
175-
newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17;
192+
newPostgresql =
193+
postgresqlWithExtension
194+
self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17;
176195
in
177196
''
178197
set -x
179198
systemctl cat postgresql.service
199+
if [[ -z "${newPostgresql.psqlSchema}" ]]; then
200+
echo "Error: psqlSchema is empty, refusing to rm -rf"
201+
exit 1
202+
fi
180203
rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}
181204
'';
182205
};
@@ -205,11 +228,14 @@ self.inputs.nixpkgs.lib.nixos.runTest {
205228
}],
206229
}
207230
extension_name = "${pname}"
231+
support_upgrade = True
208232
ext_has_background_worker = ${
209233
if (installedExtension "15") ? hasBackgroundWorker then "True" else "False"
210234
}
211235
sql_test_directory = Path("${../../tests}")
212236
pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}"
237+
ext_schema = "${(installedExtension "15").defaultSchema or "public"}"
238+
lib_name = "${(installedExtension "15").libName or pname}"
213239
214240
${builtins.readFile ./lib.py}
215241
@@ -218,7 +244,8 @@ self.inputs.nixpkgs.lib.nixos.runTest {
218244
server.wait_for_unit("multi-user.target")
219245
server.wait_for_unit("postgresql.service")
220246
221-
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory)
247+
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema, lib_name)
248+
test.create_schema()
222249
223250
with subtest("Check upgrade path with postgresql 15"):
224251
test.check_upgrade_path("15")
@@ -232,7 +259,7 @@ self.inputs.nixpkgs.lib.nixos.runTest {
232259
233260
if ext_has_background_worker:
234261
with subtest("Test switch_${pname}_version"):
235-
test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15")
262+
test.check_switch_extension_with_background_worker(Path(f"${psql_15}/lib/{lib_name}.so"), "15")
236263
237264
with subtest("Check pg_regress with postgresql 15 after installing the last version"):
238265
test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name)
@@ -263,6 +290,7 @@ self.inputs.nixpkgs.lib.nixos.runTest {
263290
)
264291
installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""")
265292
assert "orioledb" in installed_extensions
293+
test.create_schema()
266294
267295
with subtest("Check upgrade path with orioledb 17"):
268296
test.check_upgrade_path("orioledb-17")

nix/ext/tests/index_advisor.nix

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ self.inputs.nixpkgs.lib.nixos.runTest {
6969
enable = true;
7070
package = psql_15;
7171
enableTCPIP = true;
72+
authentication = ''
73+
local all postgres peer map=postgres
74+
local all all peer map=root
75+
'';
76+
identMap = ''
77+
root root supabase_admin
78+
postgres postgres postgres
79+
'';
80+
ensureUsers = [
81+
{
82+
name = "supabase_admin";
83+
ensureClauses.superuser = true;
84+
}
85+
];
7286
settings = (installedExtension "15").defaultSettings or { };
7387
};
7488

@@ -77,6 +91,7 @@ self.inputs.nixpkgs.lib.nixos.runTest {
7791
specialisation.postgresql17.configuration = {
7892
services.postgresql = {
7993
package = lib.mkForce psql_17;
94+
settings = (installedExtension "17").defaultSettings or { };
8095
};
8196

8297
systemd.services.postgresql-migrate = {
@@ -150,11 +165,17 @@ self.inputs.nixpkgs.lib.nixos.runTest {
150165
};
151166
script =
152167
let
153-
newPostgresql = postgresqlWithExtension self.packages.${pkgs.system}.postgresql_orioledb-17;
168+
newPostgresql =
169+
postgresqlWithExtension
170+
self.packages.${pkgs.stdenv.hostPlatform.system}.postgresql_orioledb-17;
154171
in
155172
''
156173
set -x
157174
systemctl cat postgresql.service
175+
if [[ -z "${newPostgresql.psqlSchema}" ]]; then
176+
echo "Error: psqlSchema is empty, refusing to rm -rf"
177+
exit 1
178+
fi
158179
rm -rf ${builtins.dirOf config.services.postgresql.dataDir}/${newPostgresql.psqlSchema}
159180
'';
160181
};
@@ -179,11 +200,14 @@ self.inputs.nixpkgs.lib.nixos.runTest {
179200
"orioledb-17": [${lib.concatStringsSep ", " (map (s: ''"${s}"'') (versions "orioledb-17"))}],
180201
}
181202
extension_name = "${pname}"
203+
support_upgrade = True
182204
ext_has_background_worker = ${
183205
if (installedExtension "15") ? hasBackgroundWorker then "True" else "False"
184206
}
185207
sql_test_directory = Path("${../../tests}")
186208
pg_regress_test_name = "${(installedExtension "15").pgRegressTestName or pname}"
209+
ext_schema = "${(installedExtension "15").defaultSchema or "public"}"
210+
lib_name = "${(installedExtension "15").libName or pname}"
187211
188212
${builtins.readFile ./lib.py}
189213
@@ -192,7 +216,8 @@ self.inputs.nixpkgs.lib.nixos.runTest {
192216
server.wait_for_unit("multi-user.target")
193217
server.wait_for_unit("postgresql.service")
194218
195-
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory)
219+
test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema, lib_name)
220+
test.create_schema()
196221
197222
with subtest("Check upgrade path with postgresql 15"):
198223
test.check_upgrade_path("15")
@@ -206,7 +231,7 @@ self.inputs.nixpkgs.lib.nixos.runTest {
206231
207232
if ext_has_background_worker:
208233
with subtest("Test switch_${pname}_version"):
209-
test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15")
234+
test.check_switch_extension_with_background_worker(Path(f"${psql_15}/lib/{lib_name}.so"), "15")
210235
211236
with subtest("Check pg_regress with postgresql 15 after installing the last version"):
212237
test.check_pg_regress(Path("${psql_15}/lib/pgxs/src/test/regress/pg_regress"), "15", pg_regress_test_name)
@@ -237,6 +262,7 @@ self.inputs.nixpkgs.lib.nixos.runTest {
237262
)
238263
installed_extensions=test.run_sql("""SELECT extname FROM pg_extension WHERE extname = 'orioledb';""")
239264
assert "orioledb" in installed_extensions
265+
test.create_schema()
240266
241267
with subtest("Check upgrade path with orioledb 17"):
242268
test.check_upgrade_path("orioledb-17")

0 commit comments

Comments
 (0)