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').
This commit is contained in:
@@ -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; };
|
||||
}
|
||||
|
||||
58
tests/naming.nix
Normal file
58
tests/naming.nix
Normal file
@@ -0,0 +1,58 @@
|
||||
{ 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;
|
||||
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 '(?<=<ApiKey>)[^<]+' /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 '(?<=<ApiKey>)[^<]+' /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 '(?<=<ApiKey>)[^<]+' /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:]}"
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user