Files
arr-init/tests/error-handling.nix
Simon Gardling f86a5f1b39 refactor: split module.nix into per-service modules
Replace the 1301-line monolithic module.nix with focused modules:
- modules/servarr.nix  (Sonarr/Radarr/Prowlarr)
- modules/bazarr.nix   (Bazarr provider connections)
- modules/jellyseerr.nix (Jellyseerr quality profiles)
- modules/default.nix  (import aggregator)

Python scripts (from prior commit) are referenced as standalone
files via PYTHONPATH, with config passed as a JSON file argument.

New options and behavioral changes:
- Add bindAddress option to all services (default 127.0.0.1)
- Change healthChecks default from false to true
- Replace hardcoded wg.service dependency with configurable
  networkNamespaceService option
- Add systemd hardening: PrivateTmp, NoNewPrivileges, ProtectHome,
  ProtectKernelTunables/Modules, ProtectControlGroups,
  RestrictSUIDSGID, SystemCallArchitectures=native

Test updates:
- Extract mock qBittorrent/SABnzbd servers into tests/lib/mocks.nix
- Add healthChecks=false to tests not exercising health checks
- Fix duplicate wait_for_unit calls in integration test
2026-04-16 16:34:04 -04:00

107 lines
3.2 KiB
Nix

{
pkgs,
lib,
self,
}:
pkgs.testers.runNixOSTest {
name = "arr-init-error-handling";
nodes.machine =
{ pkgs, lib, ... }:
{
imports = [ self.nixosModules.default ];
system.stateVersion = "24.11";
virtualisation.memorySize = 2048;
environment.systemPackages = with pkgs; [
curl
jq
gnugrep
];
# Configure arrInit for a service that doesn't exist
# The dataDir points to a non-existent config.xml
services.arrInit.sonarr = {
enable = true;
healthChecks = false;
serviceName = "sonarr";
dataDir = "/var/lib/nonexistent";
port = 8989;
downloadClients = [
{
name = "qBittorrent";
implementation = "QBittorrent";
configContract = "QBittorrentSettings";
protocol = "torrent";
fields = {
host = "127.0.0.1";
port = 6011;
useSsl = false;
};
}
];
rootFolders = [ "/media/tv" ];
};
# Also test bazarrInit with missing config
services.bazarrInit = {
enable = true;
dataDir = "/var/lib/nonexistent-bazarr";
port = 6767;
sonarr = {
enable = true;
dataDir = "/var/lib/nonexistent";
port = 8989;
serviceName = "sonarr";
};
};
# Override service dependencies since we're testing without real services
systemd.services.sonarr-init = {
requires = lib.mkForce [ ];
after = lib.mkForce [ ];
};
systemd.services.bazarr-init = {
requires = lib.mkForce [ ];
after = lib.mkForce [ ];
};
};
testScript = ''
start_all()
# Trigger sonarr-init service - it should exit gracefully
# because config.xml doesn't exist
machine.succeed("systemctl start sonarr-init.service || true")
machine.wait_for_unit("sonarr-init.service")
# Verify the service exited with ExitCode=0 (success)
# The module exits 0 when config.xml is missing
exit_code = machine.succeed(
"systemctl show sonarr-init.service --property=ExecMainStatus | cut -d= -f2"
).strip()
assert exit_code == "0", f"Expected ExitCode 0 for missing config.xml, got {exit_code}"
# Check journal for the skipping message
journal = machine.succeed("journalctl -u sonarr-init.service --no-pager")
assert "skipping" in journal.lower(), f"Expected 'skipping' message in journal, got: {journal}"
# Trigger bazarr-init service - it should also exit gracefully
machine.succeed("systemctl start bazarr-init.service || true")
machine.wait_for_unit("bazarr-init.service")
# Verify bazarr-init also exited with ExitCode=0
exit_code = machine.succeed(
"systemctl show bazarr-init.service --property=ExecMainStatus | cut -d= -f2"
).strip()
assert exit_code == "0", f"Expected ExitCode 0 for missing config.yaml, got {exit_code}"
# Check journal for the skipping message
journal = machine.succeed("journalctl -u bazarr-init.service --no-pager")
assert "skipping" in journal.lower(), f"Expected 'skipping' message in journal, got: {journal}"
'';
}