1import ./make-test-python.nix ({ pkgs, ... } :
2let
3 testAuthFile = pkgs.writeTextFile {
4 name = "authFile";
5 text = ''
6 "testuser" "testpass"
7 '';
8 };
9in
10{
11 name = "pgbouncer";
12 meta = with pkgs.lib.maintainers; {
13 maintainers = [ _1000101 ];
14 };
15 nodes = {
16 one = { config, pkgs, ... }: {
17
18 systemd.services.postgresql = {
19 postStart = ''
20 ${pkgs.postgresql}/bin/psql -U postgres -c "ALTER ROLE testuser WITH LOGIN PASSWORD 'testpass'";
21 ${pkgs.postgresql}/bin/psql -U postgres -c "ALTER DATABASE testdb OWNER TO testuser;";
22 '';
23 };
24
25 services = {
26 postgresql = {
27 enable = true;
28 ensureDatabases = [ "testdb" ];
29 ensureUsers = [
30 {
31 name = "testuser";
32 }];
33 authentication = ''
34 local testdb testuser scram-sha-256
35 '';
36 };
37
38 pgbouncer = {
39 enable = true;
40 listenAddress = "localhost";
41 databases = { test = "host=/run/postgresql/ port=5432 auth_user=testuser dbname=testdb"; };
42 authType = "scram-sha-256";
43 authFile = testAuthFile;
44 };
45 };
46 };
47 };
48
49 testScript = ''
50 start_all()
51 one.wait_for_unit("default.target")
52 one.require_unit_state("pgbouncer.service", "active")
53
54 # Test if we can make a query through PgBouncer
55 one.wait_until_succeeds(
56 "psql 'postgres://testuser:testpass@localhost:6432/test' -c 'SELECT 1;'"
57 )
58 '';
59})