summaryrefslogtreecommitdiffstats
path: root/nixos/tests/envoy.nix
blob: 6cbf782a421f1fedf3925184d71bd756b5968e9a (plain)
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
{ envoyPackage, lib, ... }:
{
  name = envoyPackage.pname;

  meta = with lib.maintainers; {
    maintainers = [ cameronnemo ];
  };

  nodes.machine = {
    services.envoy.enable = true;
    services.envoy.package = envoyPackage;
    services.envoy.settings = {
      admin = {
        access_log_path = "/dev/null";
        address = {
          socket_address = {
            protocol = "TCP";
            address = "127.0.0.1";
            port_value = 80;
          };
        };
      };
      static_resources = {
        listeners = [ ];
        clusters = [ ];
      };
    };
    specialisation = {
      withoutConfigValidation.configuration =
        { ... }:
        {
          services.envoy = {
            requireValidConfig = false;
            settings.admin.access_log_path = lib.mkForce "/var/log/envoy/access.log";
          };
        };
    };
  };

  testScript =
    { nodes, ... }:
    let
      specialisations = "${nodes.machine.system.build.toplevel}/specialisation";
    in
    ''
      machine.start()

      with subtest("envoy.service starts and responds with ready"):
        machine.wait_for_unit("envoy.service")
        machine.wait_for_open_port(80)
        machine.wait_until_succeeds("curl -fsS localhost:80/ready")

      with subtest("envoy.service works with config path not available at eval time"):
        machine.succeed('${specialisations}/withoutConfigValidation/bin/switch-to-configuration test')
        machine.wait_for_unit("envoy.service")
        machine.wait_for_open_port(80)
        machine.wait_until_succeeds("curl -fsS localhost:80/ready")
        machine.succeed('test -f /var/log/envoy/access.log')
    '';
}