about summary refs log tree commit diff
path: root/nixos/tests/db-rest.nix
blob: 9249da904acbe6fd9da0a5ded828f53d6d744e5d (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import ./make-test-python.nix ({ pkgs, ... }:
{
  name = "db-rest";
  meta.maintainers = with pkgs.lib.maintainers; [ marie ];

  nodes = {
    database = {
      networking = {
        interfaces.eth1 = {
          ipv4.addresses = [
            { address = "192.168.2.10"; prefixLength = 24; }
          ];
        };
        firewall.allowedTCPPorts = [ 31638 ];
      };

      services.redis.servers.db-rest = {
        enable = true;
        bind = "0.0.0.0";
        requirePass = "choochoo";
        port = 31638;
      };
    };

    serverWithTcp = { pkgs, ... }: {
      environment = {
        etc = {
          "db-rest/password-redis-db".text = ''
            choochoo
          '';
        };
      };

      networking = {
        interfaces.eth1 = {
          ipv4.addresses = [
            { address = "192.168.2.11"; prefixLength = 24; }
          ];
        };
        firewall.allowedTCPPorts = [ 3000 ];
      };

      services.db-rest = {
        enable = true;
        host = "0.0.0.0";
        redis = {
          enable = true;
          createLocally = false;
          host = "192.168.2.10";
          port = 31638;
          passwordFile = "/etc/db-rest/password-redis-db";
          useSSL = false;
        };
      };
    };

    serverWithUnixSocket = { pkgs, ... }: {
      networking = {
        interfaces.eth1 = {
          ipv4.addresses = [
            { address = "192.168.2.12"; prefixLength = 24; }
          ];
        };
        firewall.allowedTCPPorts = [ 3000 ];
      };

      services.db-rest = {
        enable = true;
        host = "0.0.0.0";
        redis = {
          enable = true;
          createLocally = true;
        };
      };
    };

    client = {
      environment.systemPackages = [ pkgs.jq ];
      networking = {
        interfaces.eth1 = {
          ipv4.addresses = [
            { address = "192.168.2.13"; prefixLength = 24; }
          ];
        };
      };
    };
  };

  testScript = ''
    start_all()

    with subtest("db-rest redis with TCP socket"):
      database.wait_for_unit("redis-db-rest.service")
      database.wait_for_open_port(31638)

      serverWithTcp.wait_for_unit("db-rest.service")
      serverWithTcp.wait_for_open_port(3000)

      client.succeed("curl --fail --get http://192.168.2.11:3000/stations --data-urlencode 'query=Köln Hbf' | jq -r '.\"8000207\".name' | grep 'Köln Hbf'")

    with subtest("db-rest redis with Unix socket"):
      serverWithUnixSocket.wait_for_unit("db-rest.service")
      serverWithUnixSocket.wait_for_open_port(3000)

      client.succeed("curl --fail --get http://192.168.2.12:3000/stations --data-urlencode 'query=Köln Hbf' | jq -r '.\"8000207\".name' | grep 'Köln Hbf'")
  '';
})