about summary refs log tree commit diff
path: root/nixos/tests/promscale.nix
blob: da18628f2482c5003966e8c2e26a6d9acfead8cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# mostly copied from ./timescaledb.nix which was copied from ./postgresql.nix
# as it seemed unapproriate to test additional extensions for postgresql there.

{ system ? builtins.currentSystem
, config ? { }
, pkgs ? import ../.. { inherit system config; }
}:

with import ../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;

let
  postgresql-versions = import ../../pkgs/servers/sql/postgresql pkgs;
  test-sql = pkgs.writeText "postgresql-test" ''
    CREATE USER promscale SUPERUSER PASSWORD 'promscale';
    CREATE DATABASE promscale OWNER promscale;
  '';

  make-postgresql-test = postgresql-name: postgresql-package: makeTest {
    name = postgresql-name;
    meta = with pkgs.lib.maintainers; {
      maintainers = [ anpin ];
    };

    nodes.machine = { config, pkgs, ... }:
      {
        services.postgresql = {
          enable = true;
          package = postgresql-package;
          extraPlugins = ps: with ps; [
            timescaledb
            promscale_extension
          ];
          settings = { shared_preload_libraries = "timescaledb, promscale"; };
        };
        environment.systemPackages = with pkgs; [ promscale ];
      };

    testScript = ''
      machine.start()
      machine.wait_for_unit("postgresql")
      with subtest("Postgresql with extensions timescaledb and promscale is available just after unit start"):
          print(machine.succeed("sudo -u postgres psql -f ${test-sql}"))
          machine.succeed("sudo -u postgres psql promscale -c 'SHOW shared_preload_libraries;' | grep promscale")
          machine.succeed(
            "promscale --db.name promscale --db.password promscale --db.user promscale --db.ssl-mode allow --startup.install-extensions --startup.only"
          )
      machine.succeed("sudo -u postgres psql promscale -c 'SELECT ps_trace.get_trace_retention_period();' | grep '(1 row)'")
      machine.shutdown()
    '';
  };
  #version 15 is not supported yet
  applicablePostgresqlVersions = filterAttrs (_: value: versionAtLeast value.version "12" && !(versionAtLeast value.version "15")) postgresql-versions;
in
mapAttrs'
  (name: package: {
    inherit name;
    value = make-postgresql-test name package;
  })
  applicablePostgresqlVersions