git.iko.soy/typeable/nixpkgs
on master help sign in
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

commit7d09fc6ea78a9788a74b13e2e13aa2f9e9547bf2 authorWilliButz <wbutz@cyberfnord.de> dateFri 29 Sep 2017, 16:22 (9 years ago) parent2ebc40f
1 file changed+28−28
nixos/tests/pgjwt.nix+28−28
nixos/tests/pgjwt.nix+28−28
@@ -1,42 +1,42 @@
1−import ./make-test.nix ({ pkgs, ...} :
1+import ./make-test.nix ({ pkgs, lib, ...}:
22let
3− test = pkgs.writeText "test.sql" ''
4− CREATE EXTENSION pgcrypto;
5− CREATE EXTENSION pgjwt;
6− select sign('{"sub":"1234567890","name":"John Doe","admin":true}', 'secret');
7− select * from verify('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ', 'secret');
3+ test = with pkgs; runCommand "patch-test" {
4+ nativeBuildInputs = [ pgjwt ];
5+ }
6+ ''
7+ sed -e '12 i CREATE EXTENSION pgcrypto;\nCREATE EXTENSION pgtap;\nSET search_path TO tap,public;' ${pgjwt.src}/test.sql > $out;
88 '';
99in
10−{
10+with pkgs; {
1111 name = "pgjwt";
12− meta = with pkgs.stdenv.lib.maintainers; {
13− maintainers = [ spinus ];
12+ meta = with lib.maintainers; {
13+ maintainers = [ spinus willibutz ];
1414 };
1515
1616 nodes = {
17− master =
18− { pkgs, config, ... }:
19−
20− {
21− services.postgresql = let mypg = pkgs.postgresql95; in {
22− enable = true;
23− package = mypg;
24− extraPlugins =[pkgs.pgjwt];
25− initialScript = pkgs.writeText "postgresql-init.sql"
26− ''
27− CREATE ROLE postgres WITH superuser login createdb;
28− '';
29− };
17+ master = { pkgs, config, ... }:
18+ {
19+ services.postgresql = {
20+ enable = true;
21+ package = postgresql96;
22+ extraPlugins = [ pgjwt pgtap ];
23+ initialScript = writeText "postgresql-init.sql"
24+ ''
25+ CREATE ROLE postgres WITH superuser login createdb;
26+ '';
3027 };
28+ };
3129 };
3230
33− testScript = ''
31+ testScript = { nodes, ... }:
32+ let
33+ sqlSU = "${nodes.master.config.services.postgresql.superUser}";
34+ pgProve = "${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}";
35+ in
36+ ''
3437 startAll;
3538 $master->waitForUnit("postgresql");
36− $master->succeed("timeout 10 bash -c 'while ! psql postgres -c \"SELECT 1;\";do sleep 1;done;'");
37− $master->succeed("cat ${test} | psql postgres");
38− # I can't make original test working :[
39− # $master->succeed("${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}/bin/pg_prove -d postgres ${pkgs.pgjwt.src}/test.sql");
40−
39+ $master->copyFileFromHost("${test}","/tmp/test.sql");
40+ $master->succeed("${pkgs.sudo}/bin/sudo -u ${sqlSU} PGOPTIONS=--search_path=tap,public ${pgProve}/bin/pg_prove -d postgres -v -f /tmp/test.sql");
4141 '';
4242})