Merge branch 'staging-next' into staging
[NixPkgs.git] / nixos / tests / hedgedoc.nix
blob16e0dc14e947b2e2b7f41b6dccf921c41652fff1
1 import ./make-test-python.nix ({ pkgs, lib, ... }:
3   name = "hedgedoc";
5   meta = with lib.maintainers; {
6     maintainers = [ willibutz ];
7   };
9   nodes = {
10     hedgedocSqlite = { ... }: {
11       services.hedgedoc.enable = true;
12     };
14     hedgedocPostgresWithTCPSocket = { ... }: {
15       systemd.services.hedgedoc.after = [ "postgresql.service" ];
16       services = {
17         hedgedoc = {
18           enable = true;
19           settings.db = {
20             dialect = "postgres";
21             user = "hedgedoc";
22             password = "$DB_PASSWORD";
23             host = "localhost";
24             port = 5432;
25             database = "hedgedocdb";
26           };
28           /*
29            * Do not use pkgs.writeText for secrets as
30            * they will end up in the world-readable Nix store.
31            */
32           environmentFile = pkgs.writeText "hedgedoc-env" ''
33             DB_PASSWORD=snakeoilpassword
34           '';
35         };
36         postgresql = {
37           enable = true;
38           initialScript = pkgs.writeText "pg-init-script.sql" ''
39             CREATE ROLE hedgedoc LOGIN PASSWORD 'snakeoilpassword';
40             CREATE DATABASE hedgedocdb OWNER hedgedoc;
41           '';
42         };
43       };
44     };
46     hedgedocPostgresWithUNIXSocket = { ... }: {
47       systemd.services.hedgedoc.after = [ "postgresql.service" ];
48       services = {
49         hedgedoc = {
50           enable = true;
51           settings.db = {
52             dialect = "postgres";
53             user = "hedgedoc";
54             password = "$DB_PASSWORD";
55             host = "/run/postgresql";
56             database = "hedgedocdb";
57           };
59           environmentFile = pkgs.writeText "hedgedoc-env" ''
60             DB_PASSWORD=snakeoilpassword
61           '';
62         };
63         postgresql = {
64           enable = true;
65           initialScript = pkgs.writeText "pg-init-script.sql" ''
66             CREATE ROLE hedgedoc LOGIN PASSWORD 'snakeoilpassword';
67             CREATE DATABASE hedgedocdb OWNER hedgedoc;
68           '';
69         };
70       };
71     };
72   };
74   testScript = ''
75     start_all()
77     with subtest("HedgeDoc sqlite"):
78         hedgedocSqlite.wait_for_unit("hedgedoc.service")
79         hedgedocSqlite.wait_for_open_port(3000)
80         hedgedocSqlite.wait_until_succeeds("curl -sSf http://localhost:3000/new")
82     with subtest("HedgeDoc postgres with TCP socket"):
83         hedgedocPostgresWithTCPSocket.wait_for_unit("postgresql.service")
84         hedgedocPostgresWithTCPSocket.wait_for_unit("hedgedoc.service")
85         hedgedocPostgresWithTCPSocket.wait_for_open_port(5432)
86         hedgedocPostgresWithTCPSocket.wait_for_open_port(3000)
87         hedgedocPostgresWithTCPSocket.wait_until_succeeds("curl -sSf http://localhost:3000/new")
89     with subtest("HedgeDoc postgres with UNIX socket"):
90         hedgedocPostgresWithUNIXSocket.wait_for_unit("postgresql.service")
91         hedgedocPostgresWithUNIXSocket.wait_for_unit("hedgedoc.service")
92         hedgedocPostgresWithUNIXSocket.wait_for_open_port(5432)
93         hedgedocPostgresWithUNIXSocket.wait_for_open_port(3000)
94         hedgedocPostgresWithUNIXSocket.wait_until_succeeds("curl -sSf http://localhost:3000/new")
95   '';