From 39ef4d2fe9ac549af31b24dab75ac08fab255f5c Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sat, 15 Jul 2017 14:54:42 +0100 Subject: [PATCH 1/3] nixos tests: fix postgresql tests 1. Needs to call makeTest or else nothing happens when you run `nix-build nixos/tests/postgresql.nix`. 2. Tests run as root, so there needs to be a corresponding user in PostgreSQL. --- nixos/tests/postgresql.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nixos/tests/postgresql.nix b/nixos/tests/postgresql.nix index 1f4f43a26669..b5f4e1a4c14c 100644 --- a/nixos/tests/postgresql.nix +++ b/nixos/tests/postgresql.nix @@ -14,7 +14,7 @@ let INSERT INTO sth (id) VALUES (1); INSERT INTO sth (id) VALUES (1); ''; - make-postgresql-test = postgresql-name: postgresql-package: { + make-postgresql-test = postgresql-name: postgresql-package: makeTest { name = postgresql-name; meta = with pkgs.stdenv.lib.maintainers; { maintainers = [ zagy ]; @@ -24,6 +24,9 @@ let { services.postgresql.package=postgresql-package; services.postgresql.enable = true; + services.postgresql.initialScript = pkgs.writeText "init.sql" '' + CREATE USER root WITH SUPERUSER; + ''; }; testScript = '' From 502a272ee78727712c53d316cacba1b416e37d5e Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sat, 15 Jul 2017 14:58:17 +0100 Subject: [PATCH 2/3] postgresql: enable XML functions I suspect these functions aren't widely used, but they are enabled in PostgreSQL on Ubuntu and Arch. --- nixos/tests/postgresql.nix | 3 +++ pkgs/servers/sql/postgresql/default.nix | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nixos/tests/postgresql.nix b/nixos/tests/postgresql.nix index b5f4e1a4c14c..54e7ec9ba17b 100644 --- a/nixos/tests/postgresql.nix +++ b/nixos/tests/postgresql.nix @@ -13,6 +13,8 @@ let INSERT INTO sth (id) VALUES (1); INSERT INTO sth (id) VALUES (1); INSERT INTO sth (id) VALUES (1); + CREATE TABLE xmltest ( doc xml ); + INSERT INTO xmltest (doc) VALUES ('ok'); -- check if libxml2 enabled ''; make-postgresql-test = postgresql-name: postgresql-package: makeTest { name = postgresql-name; @@ -41,6 +43,7 @@ let $machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 3'); $machine->succeed('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 5'); $machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 4'); + $machine->succeed('test $(psql postgres -tAc "SELECT xpath(\'/test/text()\', doc) FROM xmltest;"|wc -l) -eq 1'); $machine->shutdown; ''; diff --git a/pkgs/servers/sql/postgresql/default.nix b/pkgs/servers/sql/postgresql/default.nix index 2362ee843296..363fbe51adfb 100644 --- a/pkgs/servers/sql/postgresql/default.nix +++ b/pkgs/servers/sql/postgresql/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, glibc, fetchurl, zlib, readline, libossp_uuid, openssl, makeWrapper }: +{ lib, stdenv, glibc, fetchurl, zlib, readline, libossp_uuid, openssl, libxml2, makeWrapper }: let @@ -15,7 +15,7 @@ let setOutputFlags = false; # $out retains configureFlags :-/ buildInputs = - [ zlib readline openssl makeWrapper ] + [ zlib readline openssl libxml2 makeWrapper ] ++ lib.optionals (!stdenv.isDarwin) [ libossp_uuid ]; enableParallelBuilding = true; @@ -24,6 +24,7 @@ let configureFlags = [ "--with-openssl" + "--with-libxml" "--sysconfdir=/etc" "--libdir=$(lib)/lib" ] From 0b027720af00264b142e1ecade0e4fb576889909 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Wed, 19 Jul 2017 22:13:02 +0100 Subject: [PATCH 3/3] nixos tests: run postgresql tests with postgres user --- nixos/tests/postgresql.nix | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/nixos/tests/postgresql.nix b/nixos/tests/postgresql.nix index 54e7ec9ba17b..0ce37b55bb7b 100644 --- a/nixos/tests/postgresql.nix +++ b/nixos/tests/postgresql.nix @@ -26,24 +26,26 @@ let { services.postgresql.package=postgresql-package; services.postgresql.enable = true; - services.postgresql.initialScript = pkgs.writeText "init.sql" '' - CREATE USER root WITH SUPERUSER; - ''; }; testScript = '' + sub check_count { + my ($select, $nlines) = @_; + return 'test $(sudo -u postgres psql postgres -tAc "' . $select . '"|wc -l) -eq ' . $nlines; + } + $machine->start; $machine->waitForUnit("postgresql"); # postgresql should be available just after unit start - $machine->succeed("cat ${test-sql} | psql postgres"); + $machine->succeed("cat ${test-sql} | sudo -u postgres psql"); $machine->shutdown; # make sure that postgresql survive restart (bug #1735) sleep(2); $machine->start; $machine->waitForUnit("postgresql"); - $machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 3'); - $machine->succeed('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 5'); - $machine->fail('test $(psql postgres -tAc "SELECT * FROM sth;"|wc -l) -eq 4'); - $machine->succeed('test $(psql postgres -tAc "SELECT xpath(\'/test/text()\', doc) FROM xmltest;"|wc -l) -eq 1'); + $machine->fail(check_count("SELECT * FROM sth;", 3)); + $machine->succeed(check_count("SELECT * FROM sth;", 5)); + $machine->fail(check_count("SELECT * FROM sth;", 4)); + $machine->succeed(check_count("SELECT xpath(\'/test/text()\', doc) FROM xmltest;", 1)); $machine->shutdown; '';