nixos/tests: rewrite pgjwt test

- now using the test contained in the pgjwt source repo
- also compatible with the new `superUser` option of the
  `postgresql` service
This commit is contained in:
WilliButz 2017-09-29 16:22:51 +02:00
parent 2ebc40f95f
commit 7d09fc6ea7
No known key found for this signature in database
GPG key ID: 92582A10F1179CB2

View file

@ -1,42 +1,42 @@
import ./make-test.nix ({ pkgs, ...} : import ./make-test.nix ({ pkgs, lib, ...}:
let let
test = pkgs.writeText "test.sql" '' test = with pkgs; runCommand "patch-test" {
CREATE EXTENSION pgcrypto; nativeBuildInputs = [ pgjwt ];
CREATE EXTENSION pgjwt; }
select sign('{"sub":"1234567890","name":"John Doe","admin":true}', 'secret'); ''
select * from verify('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ', 'secret'); sed -e '12 i CREATE EXTENSION pgcrypto;\nCREATE EXTENSION pgtap;\nSET search_path TO tap,public;' ${pgjwt.src}/test.sql > $out;
''; '';
in in
{ with pkgs; {
name = "pgjwt"; name = "pgjwt";
meta = with pkgs.stdenv.lib.maintainers; { meta = with lib.maintainers; {
maintainers = [ spinus ]; maintainers = [ spinus willibutz ];
}; };
nodes = { nodes = {
master = master = { pkgs, config, ... }:
{ pkgs, config, ... }: {
services.postgresql = {
{ enable = true;
services.postgresql = let mypg = pkgs.postgresql95; in { package = postgresql96;
enable = true; extraPlugins = [ pgjwt pgtap ];
package = mypg; initialScript = writeText "postgresql-init.sql"
extraPlugins =[pkgs.pgjwt]; ''
initialScript = pkgs.writeText "postgresql-init.sql" CREATE ROLE postgres WITH superuser login createdb;
'' '';
CREATE ROLE postgres WITH superuser login createdb;
'';
};
}; };
};
}; };
testScript = '' testScript = { nodes, ... }:
let
sqlSU = "${nodes.master.config.services.postgresql.superUser}";
pgProve = "${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}";
in
''
startAll; startAll;
$master->waitForUnit("postgresql"); $master->waitForUnit("postgresql");
$master->succeed("timeout 10 bash -c 'while ! psql postgres -c \"SELECT 1;\";do sleep 1;done;'"); $master->copyFileFromHost("${test}","/tmp/test.sql");
$master->succeed("cat ${test} | psql postgres"); $master->succeed("${pkgs.sudo}/bin/sudo -u ${sqlSU} PGOPTIONS=--search_path=tap,public ${pgProve}/bin/pg_prove -d postgres -v -f /tmp/test.sql");
# I can't make original test working :[
# $master->succeed("${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}/bin/pg_prove -d postgres ${pkgs.pgjwt.src}/test.sql");
''; '';
}) })