Files
home-manager/tests/modules/services/syncthing/linux/ignore-patterns.nix
Sighery a7209b6794 syncthing: fix badly escaped ignore patterns test
The previous test would pass no matter what the `ignoreString` was. I
don't know enough Bash/Grep to explain it, but it was easy to test by
just changing the pattern to have `WRONG` instead of `val1`, and that
would still pass the `assertFileContains` test.

I've hopefully fixed it now, by using `lib.escapeShellArg` before
passing it to `assertFileContains`, and I've also added a negative test
case, to ensure that a bad ignore string is _not_ found in the merge
script.
2026-07-04 22:02:21 -05:00

41 lines
1.2 KiB
Nix

{ lib, ... }:
{
services.syncthing = {
enable = true;
settings.folders = {
"Folder1" = {
id = "ew8bc-4uanl";
path = "/home/username/folder1";
ignorePatterns = [
"val1"
"!val2"
"*al3"
"val'4"
"val\"5"
];
};
};
};
nmt.script =
let
ignoreString = ''{"ignore":["val1","!val2","*al3","val'\'''4","val\"5"]}'';
ignoreStringBad = ''{"ignore":["WRONG","!val2","*al3","val'\'''4","val\"5"]}'';
in
''
serviceFile=home-files/.config/systemd/user/syncthing-init.service
assertFileExists "$serviceFile"
assertFileExists home-files/.config/systemd/user/default.target.wants/syncthing-init.service
assertFileContains "$serviceFile" "ExecStart="
updateScript=$(grep -o '/nix/store/[^ ]*-merge-syncthing-config' "$TESTED/$serviceFile")
assertFileContains "$updateScript" "/rest/db/ignores?folder=ew8bc-4uanl"
assertFileContains "$updateScript" ${lib.escapeShellArg ignoreString}
if grep -qF ${lib.escapeShellArg ignoreStringBad} "$(_abs "$updateScript")"; then
fail "syncthing bad ignore string shouldn't be found in updateScript"
fi
'';
}