summaryrefslogtreecommitdiffstats
path: root/nixos/tests/ersatztv.nix
blob: 12a41e19c9aa1135935504597e4b433d77f91706 (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
{ lib, ... }:

{
  name = "ersatztv";
  meta.maintainers = with lib.maintainers; [ allout58 ];

  nodes.basic =
    { ... }:
    {
      services.ersatztv.enable = true;
    };
  nodes.reconfigured =
    { ... }:
    {
      services.ersatztv.enable = true;
      services.ersatztv.environment.ETV_UI_PORT = 8123;
      services.ersatztv.openFirewall = true;
    };

  # ErsatzTV doesn't really have an API to speak of currently, so just check if it responds at all
  testScript =
    { nodes, ... }:
    let
      basicIp = (lib.head nodes.basic.networking.interfaces.eth1.ipv4.addresses).address;
      reconfiguredIp = (lib.head nodes.reconfigured.networking.interfaces.eth1.ipv4.addresses).address;
    in
    ''
      start_all()
      basic.wait_for_unit("ersatztv.service")
      basic.wait_for_open_port(8409)
      basic.succeed("curl --fail http://localhost:8409/api/sessions")

      reconfigured.wait_for_unit("ersatztv.service")
      reconfigured.wait_for_open_port(8123)
      reconfigured.succeed("curl --fail http://localhost:8123/api/sessions")

      # Test that the firewall is open
      reconfigured.fail("curl --fail --connect-timeout 5 http://${basicIp}:8409/api/sessions")
      basic.succeed("curl --fail http://${reconfiguredIp}:8123/api/sessions")
    '';
}