From 743cd3dfaf9d9c4a2573a506584c41cf57e738f0 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 4 Mar 2025 00:42:31 +0100 Subject: [PATCH] nixosTests.pgadmin4: Use runTest See https://github.com/NixOS/nixpkgs/issues/386873 --- nixos/tests/all-tests.nix | 2 +- nixos/tests/pgadmin4.nix | 152 +++++++++++++++++++------------------- 2 files changed, 76 insertions(+), 78 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index a9b33559d1c7..061aac6ca93f 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -870,7 +870,7 @@ in { peering-manager = handleTest ./web-apps/peering-manager.nix {}; peertube = handleTestOn ["x86_64-linux"] ./web-apps/peertube.nix {}; peroxide = handleTest ./peroxide.nix {}; - pgadmin4 = handleTest ./pgadmin4.nix {}; + pgadmin4 = runTest ./pgadmin4.nix; pgbouncer = handleTest ./pgbouncer.nix {}; pghero = runTest ./pghero.nix; pgweb = runTest ./pgweb.nix; diff --git a/nixos/tests/pgadmin4.nix b/nixos/tests/pgadmin4.nix index 0a87d053f324..2d08e95a2c18 100644 --- a/nixos/tests/pgadmin4.nix +++ b/nixos/tests/pgadmin4.nix @@ -1,88 +1,86 @@ -import ./make-test-python.nix ( - { pkgs, lib, ... }: +{ lib, ... }: - { - name = "pgadmin4"; - meta.maintainers = with lib.maintainers; [ - mkg20001 - gador - ]; +{ + name = "pgadmin4"; + meta.maintainers = with lib.maintainers; [ + mkg20001 + gador + ]; - nodes = { - machine = - { pkgs, ... }: - { + nodes = { + machine = + { pkgs, ... }: + { - imports = [ ./common/user-account.nix ]; + imports = [ ./common/user-account.nix ]; - environment.systemPackages = with pkgs; [ - wget - curl - pgadmin4-desktopmode - ]; + environment.systemPackages = with pkgs; [ + wget + curl + pgadmin4-desktopmode + ]; - services.postgresql = { - enable = true; - authentication = '' - host all all localhost trust - ''; - }; - - services.pgadmin = { - port = 5051; - enable = true; - initialEmail = "bruh@localhost.de"; - initialPasswordFile = pkgs.writeText "pw" "bruh2012!"; - }; + services.postgresql = { + enable = true; + authentication = '' + host all all localhost trust + ''; }; - machine2 = - { pkgs, ... }: - { - imports = [ ./common/user-account.nix ]; - - services.postgresql = { - enable = true; - }; - - services.pgadmin = { - enable = true; - initialEmail = "bruh@localhost.de"; - initialPasswordFile = pkgs.writeText "pw" "bruh2012!"; - minimumPasswordLength = 12; - }; + services.pgadmin = { + port = 5051; + enable = true; + initialEmail = "bruh@localhost.de"; + initialPasswordFile = pkgs.writeText "pw" "bruh2012!"; }; - }; + }; + machine2 = + { pkgs, ... }: + { - testScript = '' - with subtest("Check pgadmin module"): - machine.wait_for_unit("postgresql") - machine.wait_for_unit("pgadmin") - machine.wait_until_succeeds("curl -sS localhost:5051") - machine.wait_until_succeeds("curl -sS localhost:5051/login | grep \"pgAdmin 4\" > /dev/null") - # check for missing support files (css, js etc). Should catch not-generated files during build. See e.g. https://github.com/NixOS/nixpkgs/pull/229184 - machine.succeed("wget -nv --level=1 --spider --recursive localhost:5051/login") - # test idempotenceny - machine.systemctl("restart pgadmin.service") - machine.wait_for_unit("pgadmin") - machine.wait_until_succeeds("curl -sS localhost:5051") - machine.wait_until_succeeds("curl -sS localhost:5051/login | grep \"pgAdmin 4\" > /dev/null") + imports = [ ./common/user-account.nix ]; - # pgadmin4 module saves the configuration to /etc/pgadmin/config_system.py - # pgadmin4-desktopmode tries to read that as well. This normally fails with a PermissionError, as the config file - # is owned by the user of the pgadmin module. With the check-system-config-dir.patch this will just throw a warning - # but will continue and not read the file. - # If we run pgadmin4-desktopmode as root (something one really shouldn't do), it can read the config file and fail, - # because of the wrong config for desktopmode. - with subtest("Check pgadmin standalone desktop mode"): - machine.execute("sudo -u alice pgadmin4 >&2 &", timeout=60) - machine.wait_until_succeeds("curl -sS localhost:5050") - machine.wait_until_succeeds("curl -sS localhost:5050/browser/ | grep \"pgAdmin 4\" > /dev/null") - machine.succeed("wget -nv --level=1 --spider --recursive localhost:5050/browser") + services.postgresql = { + enable = true; + }; - with subtest("Check pgadmin minimum password length"): - machine2.wait_for_unit("postgresql") - machine2.wait_for_console_text("Password must be at least 12 characters long") - ''; - } -) + services.pgadmin = { + enable = true; + initialEmail = "bruh@localhost.de"; + initialPasswordFile = pkgs.writeText "pw" "bruh2012!"; + minimumPasswordLength = 12; + }; + }; + }; + + testScript = '' + with subtest("Check pgadmin module"): + machine.wait_for_unit("postgresql") + machine.wait_for_unit("pgadmin") + machine.wait_until_succeeds("curl -sS localhost:5051") + machine.wait_until_succeeds("curl -sS localhost:5051/login | grep \"pgAdmin 4\" > /dev/null") + # check for missing support files (css, js etc). Should catch not-generated files during build. See e.g. https://github.com/NixOS/nixpkgs/pull/229184 + machine.succeed("wget -nv --level=1 --spider --recursive localhost:5051/login") + # test idempotenceny + machine.systemctl("restart pgadmin.service") + machine.wait_for_unit("pgadmin") + machine.wait_until_succeeds("curl -sS localhost:5051") + machine.wait_until_succeeds("curl -sS localhost:5051/login | grep \"pgAdmin 4\" > /dev/null") + + # pgadmin4 module saves the configuration to /etc/pgadmin/config_system.py + # pgadmin4-desktopmode tries to read that as well. This normally fails with a PermissionError, as the config file + # is owned by the user of the pgadmin module. With the check-system-config-dir.patch this will just throw a warning + # but will continue and not read the file. + # If we run pgadmin4-desktopmode as root (something one really shouldn't do), it can read the config file and fail, + # because of the wrong config for desktopmode. + with subtest("Check pgadmin standalone desktop mode"): + machine.execute("sudo -u alice pgadmin4 >&2 &", timeout=60) + machine.wait_until_succeeds("curl -sS localhost:5050") + machine.wait_until_succeeds("curl -sS localhost:5050/browser/ | grep \"pgAdmin 4\" > /dev/null") + machine.succeed("wget -nv --level=1 --spider --recursive localhost:5050/browser") + + with subtest("Check pgadmin minimum password length"): + machine2.wait_for_unit("postgresql") + machine2.wait_for_console_text("Password must be at least 12 characters long") + ''; +}