about summary refs log tree commit diff
path: root/nixpkgs/nixos/tests/hedgedoc.nix
blob: 16e0dc14e947b2e2b7f41b6dccf921c41652fff1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import ./make-test-python.nix ({ pkgs, lib, ... }:
{
  name = "hedgedoc";

  meta = with lib.maintainers; {
    maintainers = [ willibutz ];
  };

  nodes = {
    hedgedocSqlite = { ... }: {
      services.hedgedoc.enable = true;
    };

    hedgedocPostgresWithTCPSocket = { ... }: {
      systemd.services.hedgedoc.after = [ "postgresql.service" ];
      services = {
        hedgedoc = {
          enable = true;
          settings.db = {
            dialect = "postgres";
            user = "hedgedoc";
            password = "$DB_PASSWORD";
            host = "localhost";
            port = 5432;
            database = "hedgedocdb";
          };

          /*
           * Do not use pkgs.writeText for secrets as
           * they will end up in the world-readable Nix store.
           */
          environmentFile = pkgs.writeText "hedgedoc-env" ''
            DB_PASSWORD=snakeoilpassword
          '';
        };
        postgresql = {
          enable = true;
          initialScript = pkgs.writeText "pg-init-script.sql" ''
            CREATE ROLE hedgedoc LOGIN PASSWORD 'snakeoilpassword';
            CREATE DATABASE hedgedocdb OWNER hedgedoc;
          '';
        };
      };
    };

    hedgedocPostgresWithUNIXSocket = { ... }: {
      systemd.services.hedgedoc.after = [ "postgresql.service" ];
      services = {
        hedgedoc = {
          enable = true;
          settings.db = {
            dialect = "postgres";
            user = "hedgedoc";
            password = "$DB_PASSWORD";
            host = "/run/postgresql";
            database = "hedgedocdb";
          };

          environmentFile = pkgs.writeText "hedgedoc-env" ''
            DB_PASSWORD=snakeoilpassword
          '';
        };
        postgresql = {
          enable = true;
          initialScript = pkgs.writeText "pg-init-script.sql" ''
            CREATE ROLE hedgedoc LOGIN PASSWORD 'snakeoilpassword';
            CREATE DATABASE hedgedocdb OWNER hedgedoc;
          '';
        };
      };
    };
  };

  testScript = ''
    start_all()

    with subtest("HedgeDoc sqlite"):
        hedgedocSqlite.wait_for_unit("hedgedoc.service")
        hedgedocSqlite.wait_for_open_port(3000)
        hedgedocSqlite.wait_until_succeeds("curl -sSf http://localhost:3000/new")

    with subtest("HedgeDoc postgres with TCP socket"):
        hedgedocPostgresWithTCPSocket.wait_for_unit("postgresql.service")
        hedgedocPostgresWithTCPSocket.wait_for_unit("hedgedoc.service")
        hedgedocPostgresWithTCPSocket.wait_for_open_port(5432)
        hedgedocPostgresWithTCPSocket.wait_for_open_port(3000)
        hedgedocPostgresWithTCPSocket.wait_until_succeeds("curl -sSf http://localhost:3000/new")

    with subtest("HedgeDoc postgres with UNIX socket"):
        hedgedocPostgresWithUNIXSocket.wait_for_unit("postgresql.service")
        hedgedocPostgresWithUNIXSocket.wait_for_unit("hedgedoc.service")
        hedgedocPostgresWithUNIXSocket.wait_for_open_port(5432)
        hedgedocPostgresWithUNIXSocket.wait_for_open_port(3000)
        hedgedocPostgresWithUNIXSocket.wait_until_succeeds("curl -sSf http://localhost:3000/new")
  '';
})