summaryrefslogtreecommitdiffstats
path: root/nixos/tests/autobrr.nix
blob: 96f62b892dbd1d0333d88d191f512c1f780a6c1b (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
{ lib, ... }:

{
  name = "autobrr";
  meta.maintainers = with lib.maintainers; [ av-gal ];

  nodes.machine =
    { pkgs, ... }:
    let
      # We create this secret in the Nix store (making it readable by everyone).
      # DO NOT DO THIS OUTSIDE OF TESTS!!
      testSecretFile = pkgs.writeText "session_secret" "not-secret";
    in
    {
      services.autobrr = {
        enable = true;
        secretFile = testSecretFile;
      };

      # Use port other than default to test if settings options work.
      specialisation.settingsPort.configuration = {
        services.autobrr = {
          enable = true;
          secretFile = testSecretFile;
          settings.port = 7777;
        };
      };
    };

  testScript =
    { nodes, ... }:
    let
      settingsPort = "${nodes.machine.system.build.toplevel}/specialisation/settingsPort";
    in
    # python
    ''
      def test_webui(port):
        machine.wait_for_unit("autobrr.service")
        machine.wait_for_open_port(port)
        machine.wait_until_succeeds(f"curl --fail http://localhost:{port}")

      test_webui(7474)

      machine.succeed("${settingsPort}/bin/switch-to-configuration test")
      test_webui(7777)
    '';
}