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