summary refs log tree commit diff
path: root/nixos/tests/pgjwt.nix
diff options
context:
space:
mode:
authorWilliButz <wbutz@cyberfnord.de>2017-09-29 16:22:51 +0200
committerWilliButz <wbutz@cyberfnord.de>2017-10-01 20:12:58 +0200
commit7d09fc6ea78a9788a74b13e2e13aa2f9e9547bf2 (patch)
tree45daf0d5072a7b87c2e652481ce5a80aee2025c6 /nixos/tests/pgjwt.nix
parent2ebc40f95f5195beffaa47bf7ef192cbd635f9ba (diff)
downloadnixpkgs-7d09fc6ea78a9788a74b13e2e13aa2f9e9547bf2.tar
nixpkgs-7d09fc6ea78a9788a74b13e2e13aa2f9e9547bf2.tar.gz
nixpkgs-7d09fc6ea78a9788a74b13e2e13aa2f9e9547bf2.tar.bz2
nixpkgs-7d09fc6ea78a9788a74b13e2e13aa2f9e9547bf2.tar.lz
nixpkgs-7d09fc6ea78a9788a74b13e2e13aa2f9e9547bf2.tar.xz
nixpkgs-7d09fc6ea78a9788a74b13e2e13aa2f9e9547bf2.tar.zst
nixpkgs-7d09fc6ea78a9788a74b13e2e13aa2f9e9547bf2.zip
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
Diffstat (limited to 'nixos/tests/pgjwt.nix')
-rw-r--r--nixos/tests/pgjwt.nix56
1 files changed, 28 insertions, 28 deletions
diff --git a/nixos/tests/pgjwt.nix b/nixos/tests/pgjwt.nix
index 2cf2963ae31..5af2f38035e 100644
--- a/nixos/tests/pgjwt.nix
+++ b/nixos/tests/pgjwt.nix
@@ -1,42 +1,42 @@
-import ./make-test.nix ({ pkgs, ...} : 
+import ./make-test.nix ({ pkgs, lib, ...}:
 let
-  test = pkgs.writeText "test.sql" ''
-    CREATE EXTENSION pgcrypto;
-    CREATE EXTENSION pgjwt;
-    select sign('{"sub":"1234567890","name":"John Doe","admin":true}', 'secret');
-    select * from verify('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ', 'secret');
+  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;
   '';
 in
-{
+with pkgs; {
   name = "pgjwt";
-  meta = with pkgs.stdenv.lib.maintainers; {
-    maintainers = [ spinus ];
+  meta = with lib.maintainers; {
+    maintainers = [ spinus willibutz ];
   };
 
   nodes = {
-    master =
-      { pkgs, config, ... }:
-
-      {
-        services.postgresql = let mypg = pkgs.postgresql95; in {
-            enable = true;
-            package = mypg;
-            extraPlugins =[pkgs.pgjwt];
-            initialScript =  pkgs.writeText "postgresql-init.sql"
-          ''
-          CREATE ROLE postgres WITH superuser login createdb;
-          '';
-          };
+    master = { pkgs, config, ... }:
+    {
+      services.postgresql = {
+      enable = true;
+      package = postgresql96;
+      extraPlugins = [ pgjwt pgtap ];
+      initialScript =  writeText "postgresql-init.sql"
+      ''
+        CREATE ROLE postgres WITH superuser login createdb;
+      '';
       };
+    };
   };
 
-  testScript = ''
+  testScript = { nodes, ... }:
+  let
+    sqlSU = "${nodes.master.config.services.postgresql.superUser}";
+    pgProve = "${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}";
+  in
+  ''
     startAll;
     $master->waitForUnit("postgresql");
-    $master->succeed("timeout 10 bash -c 'while ! psql postgres -c \"SELECT 1;\";do sleep 1;done;'");
-    $master->succeed("cat ${test} | psql postgres");
-    # I can't make original test working :[
-    # $master->succeed("${pkgs.perlPackages.TAPParserSourceHandlerpgTAP}/bin/pg_prove -d postgres ${pkgs.pgjwt.src}/test.sql");
-
+    $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");
   '';
 })