2017-09-29 08:22:51 -06:00
|
|
|
import ./make-test.nix ({ pkgs, lib, ...}:
|
2017-02-26 03:14:32 -07:00
|
|
|
let
|
2017-09-29 08:22:51 -06:00
|
|
|
test = with pkgs; runCommand "patch-test" {
|
|
|
|
nativeBuildInputs = [ pgjwt ];
|
|
|
|
}
|
|
|
|
''
|
|
|
|
sed -e '12 i CREATE EXTENSION pgcrypto;\nCREATE EXTENSION pgtap;\nSET search_path TO tap,public;' ${pgjwt.src}/test.sql > $out;
|
2017-02-26 03:14:32 -07:00
|
|
|
'';
|
|
|
|
in
|
2017-09-29 08:22:51 -06:00
|
|
|
with pkgs; {
|
2017-02-26 03:14:32 -07:00
|
|
|
name = "pgjwt";
|
2017-09-29 08:22:51 -06:00
|
|
|
meta = with lib.maintainers; {
|
|
|
|
maintainers = [ spinus willibutz ];
|
2017-02-26 03:14:32 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
2017-09-29 08:22:51 -06:00
|
|
|
master = { pkgs, config, ... }:
|
|
|
|
{
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
package = postgresql96;
|
|
|
|
extraPlugins = [ pgjwt pgtap ];
|
|
|
|
initialScript = writeText "postgresql-init.sql"
|
|
|
|
''
|
|
|
|
CREATE ROLE postgres WITH superuser login createdb;
|
|
|
|
'';
|
2017-02-26 03:14:32 -07:00
|
|
|
};
|
2017-09-29 08:22:51 -06:00
|
|
|
};
|
2017-02-26 03:14:32 -07:00
|
|
|
};
|
|
|
|
|
2017-09-29 08:22:51 -06:00
|
|
|
testScript = { nodes, ... }:
|
|
|
|
let
|
|
|
|
sqlSU = "${nodes.master.config.services.postgresql.superUser}";
|
|
|
|
pgProve = "${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}";
|
|
|
|
in
|
|
|
|
''
|
2017-02-26 03:14:32 -07:00
|
|
|
startAll;
|
|
|
|
$master->waitForUnit("postgresql");
|
2017-09-29 08:22:51 -06:00
|
|
|
$master->copyFileFromHost("${test}","/tmp/test.sql");
|
|
|
|
$master->succeed("${pkgs.sudo}/bin/sudo -u ${sqlSU} PGOPTIONS=--search_path=tap,public ${pgProve}/bin/pg_prove -d postgres -v -f /tmp/test.sql");
|
2017-02-26 03:14:32 -07:00
|
|
|
'';
|
|
|
|
})
|