mirror of
https://github.com/nix-community/home-manager.git
synced 2026-10-03 03:59:23 +00:00
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.
41 lines
1.2 KiB
Nix
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
|
|
'';
|
|
}
|