Skip to content

Commit 743cd3d

Browse files
committed
nixosTests.pgadmin4: Use runTest
See #386873
1 parent 082193e commit 743cd3d

File tree

2 files changed

+73
-75
lines changed

2 files changed

+73
-75
lines changed

nixos/tests/all-tests.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ in {
870870
peering-manager = handleTest ./web-apps/peering-manager.nix {};
871871
peertube = handleTestOn ["x86_64-linux"] ./web-apps/peertube.nix {};
872872
peroxide = handleTest ./peroxide.nix {};
873-
pgadmin4 = handleTest ./pgadmin4.nix {};
873+
pgadmin4 = runTest ./pgadmin4.nix;
874874
pgbouncer = handleTest ./pgbouncer.nix {};
875875
pghero = runTest ./pghero.nix;
876876
pgweb = runTest ./pgweb.nix;

nixos/tests/pgadmin4.nix

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,86 @@
1-
import ./make-test-python.nix (
2-
{ pkgs, lib, ... }:
1+
{ lib, ... }:
32

4-
{
5-
name = "pgadmin4";
6-
meta.maintainers = with lib.maintainers; [
7-
mkg20001
8-
gador
9-
];
3+
{
4+
name = "pgadmin4";
5+
meta.maintainers = with lib.maintainers; [
6+
mkg20001
7+
gador
8+
];
109

11-
nodes = {
12-
machine =
13-
{ pkgs, ... }:
14-
{
10+
nodes = {
11+
machine =
12+
{ pkgs, ... }:
13+
{
1514

16-
imports = [ ./common/user-account.nix ];
15+
imports = [ ./common/user-account.nix ];
1716

18-
environment.systemPackages = with pkgs; [
19-
wget
20-
curl
21-
pgadmin4-desktopmode
22-
];
17+
environment.systemPackages = with pkgs; [
18+
wget
19+
curl
20+
pgadmin4-desktopmode
21+
];
2322

24-
services.postgresql = {
25-
enable = true;
26-
authentication = ''
27-
host all all localhost trust
28-
'';
29-
};
23+
services.postgresql = {
24+
enable = true;
25+
authentication = ''
26+
host all all localhost trust
27+
'';
28+
};
3029

31-
services.pgadmin = {
32-
port = 5051;
33-
enable = true;
34-
initialEmail = "[email protected]";
35-
initialPasswordFile = pkgs.writeText "pw" "bruh2012!";
36-
};
30+
services.pgadmin = {
31+
port = 5051;
32+
enable = true;
33+
initialEmail = "[email protected]";
34+
initialPasswordFile = pkgs.writeText "pw" "bruh2012!";
3735
};
38-
machine2 =
39-
{ pkgs, ... }:
40-
{
36+
};
37+
machine2 =
38+
{ pkgs, ... }:
39+
{
4140

42-
imports = [ ./common/user-account.nix ];
41+
imports = [ ./common/user-account.nix ];
4342

44-
services.postgresql = {
45-
enable = true;
46-
};
43+
services.postgresql = {
44+
enable = true;
45+
};
4746

48-
services.pgadmin = {
49-
enable = true;
50-
initialEmail = "[email protected]";
51-
initialPasswordFile = pkgs.writeText "pw" "bruh2012!";
52-
minimumPasswordLength = 12;
53-
};
47+
services.pgadmin = {
48+
enable = true;
49+
initialEmail = "[email protected]";
50+
initialPasswordFile = pkgs.writeText "pw" "bruh2012!";
51+
minimumPasswordLength = 12;
5452
};
55-
};
53+
};
54+
};
5655

57-
testScript = ''
58-
with subtest("Check pgadmin module"):
59-
machine.wait_for_unit("postgresql")
60-
machine.wait_for_unit("pgadmin")
61-
machine.wait_until_succeeds("curl -sS localhost:5051")
62-
machine.wait_until_succeeds("curl -sS localhost:5051/login | grep \"<title>pgAdmin 4</title>\" > /dev/null")
63-
# 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
64-
machine.succeed("wget -nv --level=1 --spider --recursive localhost:5051/login")
65-
# test idempotenceny
66-
machine.systemctl("restart pgadmin.service")
67-
machine.wait_for_unit("pgadmin")
68-
machine.wait_until_succeeds("curl -sS localhost:5051")
69-
machine.wait_until_succeeds("curl -sS localhost:5051/login | grep \"<title>pgAdmin 4</title>\" > /dev/null")
56+
testScript = ''
57+
with subtest("Check pgadmin module"):
58+
machine.wait_for_unit("postgresql")
59+
machine.wait_for_unit("pgadmin")
60+
machine.wait_until_succeeds("curl -sS localhost:5051")
61+
machine.wait_until_succeeds("curl -sS localhost:5051/login | grep \"<title>pgAdmin 4</title>\" > /dev/null")
62+
# 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
63+
machine.succeed("wget -nv --level=1 --spider --recursive localhost:5051/login")
64+
# test idempotenceny
65+
machine.systemctl("restart pgadmin.service")
66+
machine.wait_for_unit("pgadmin")
67+
machine.wait_until_succeeds("curl -sS localhost:5051")
68+
machine.wait_until_succeeds("curl -sS localhost:5051/login | grep \"<title>pgAdmin 4</title>\" > /dev/null")
7069
71-
# pgadmin4 module saves the configuration to /etc/pgadmin/config_system.py
72-
# pgadmin4-desktopmode tries to read that as well. This normally fails with a PermissionError, as the config file
73-
# is owned by the user of the pgadmin module. With the check-system-config-dir.patch this will just throw a warning
74-
# but will continue and not read the file.
75-
# If we run pgadmin4-desktopmode as root (something one really shouldn't do), it can read the config file and fail,
76-
# because of the wrong config for desktopmode.
77-
with subtest("Check pgadmin standalone desktop mode"):
78-
machine.execute("sudo -u alice pgadmin4 >&2 &", timeout=60)
79-
machine.wait_until_succeeds("curl -sS localhost:5050")
80-
machine.wait_until_succeeds("curl -sS localhost:5050/browser/ | grep \"<title>pgAdmin 4</title>\" > /dev/null")
81-
machine.succeed("wget -nv --level=1 --spider --recursive localhost:5050/browser")
70+
# pgadmin4 module saves the configuration to /etc/pgadmin/config_system.py
71+
# pgadmin4-desktopmode tries to read that as well. This normally fails with a PermissionError, as the config file
72+
# is owned by the user of the pgadmin module. With the check-system-config-dir.patch this will just throw a warning
73+
# but will continue and not read the file.
74+
# If we run pgadmin4-desktopmode as root (something one really shouldn't do), it can read the config file and fail,
75+
# because of the wrong config for desktopmode.
76+
with subtest("Check pgadmin standalone desktop mode"):
77+
machine.execute("sudo -u alice pgadmin4 >&2 &", timeout=60)
78+
machine.wait_until_succeeds("curl -sS localhost:5050")
79+
machine.wait_until_succeeds("curl -sS localhost:5050/browser/ | grep \"<title>pgAdmin 4</title>\" > /dev/null")
80+
machine.succeed("wget -nv --level=1 --spider --recursive localhost:5050/browser")
8281
83-
with subtest("Check pgadmin minimum password length"):
84-
machine2.wait_for_unit("postgresql")
85-
machine2.wait_for_console_text("Password must be at least 12 characters long")
86-
'';
87-
}
88-
)
82+
with subtest("Check pgadmin minimum password length"):
83+
machine2.wait_for_unit("postgresql")
84+
machine2.wait_for_console_text("Password must be at least 12 characters long")
85+
'';
86+
}

0 commit comments

Comments
 (0)