From f766e5f71e68cc4216e0ea071deb5e6640373928 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 16 Apr 2026 16:34:28 -0400 Subject: [PATCH] test: add naming configuration test Exercises the naming option which was previously untested. Verifies fields are applied to Sonarr via config/naming API and validates idempotency (second run reports 'already correct'). --- tests/default.nix | 1 + tests/naming.nix | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/naming.nix diff --git a/tests/default.nix b/tests/default.nix index 00891d7..51d7ae2 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -13,4 +13,5 @@ health-checks = import ./health-checks.nix { inherit pkgs lib self; }; delayed-start = import ./delayed-start.nix { inherit pkgs lib self; }; jellyseerr = import ./jellyseerr.nix { inherit pkgs lib self; }; + naming = import ./naming.nix { inherit pkgs lib self; }; } diff --git a/tests/naming.nix b/tests/naming.nix new file mode 100644 index 0000000..d4393d2 --- /dev/null +++ b/tests/naming.nix @@ -0,0 +1,59 @@ +{ pkgs, lib, self }: +pkgs.testers.runNixOSTest { + name = "arr-init-naming"; + nodes.machine = { pkgs, lib, ... }: { + imports = [ self.nixosModules.default ]; + system.stateVersion = "24.11"; + virtualisation.memorySize = 4096; + environment.systemPackages = with pkgs; [ curl jq gnugrep ]; + + services.sonarr = { + enable = true; + dataDir = "/var/lib/sonarr/.config/NzbDrone"; + settings.server.port = lib.mkDefault 8989; + }; + + services.arrInit.sonarr = { + enable = true; + serviceName = "sonarr"; + dataDir = "/var/lib/sonarr/.config/NzbDrone"; + port = 8989; + healthChecks = false; + naming = { + renameEpisodes = true; + standardEpisodeFormat = "{Series Title} - S{season:00}E{episode:00} - {Episode Title} {Quality Full}"; + seasonFolderFormat = "Season {season}"; + }; + }; + }; + testScript = '' + start_all() + machine.wait_for_unit("sonarr.service") + machine.wait_until_succeeds( + "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/sonarr/.config/NzbDrone/config.xml) && " + "curl -sf http://localhost:8989/api/v3/system/status -H \"X-Api-Key: $API_KEY\"", + timeout=120, + ) + machine.succeed("systemctl restart sonarr-init.service") + machine.wait_for_unit("sonarr-init.service") + + with subtest("Naming configuration was applied"): + machine.succeed( + "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/sonarr/.config/NzbDrone/config.xml) && " + "curl -sf http://localhost:8989/api/v3/config/naming -H \"X-Api-Key: $API_KEY\" | " + "jq -e '.renameEpisodes == true'" + ) + machine.succeed( + "API_KEY=$(grep -oP '(?<=)[^<]+' /var/lib/sonarr/.config/NzbDrone/config.xml) && " + "curl -sf http://localhost:8989/api/v3/config/naming -H \"X-Api-Key: $API_KEY\" | " + "jq -e '.seasonFolderFormat == \"Season {season}\"'" + ) + + with subtest("Naming idempotency - second run does not change anything"): + machine.succeed("systemctl restart sonarr-init.service") + machine.wait_for_unit("sonarr-init.service") + journal = machine.succeed("journalctl -u sonarr-init.service --no-pager") + assert "already correct" in journal.lower(), \ + f"Expected 'already correct' on idempotent run, got: {journal[-500:]}" + ''; +}