diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 5b17b838e343..96b117c3f9e5 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1585,6 +1585,7 @@ in sx = runTest ./sx.nix; sympa = runTest ./sympa.nix; syncthing = runTest ./syncthing/main.nix; + syncthing-defaults = runTest ./syncthing/defaults.nix; syncthing-folders = runTest ./syncthing/folders.nix; syncthing-guiPassword = runTest ./syncthing/guiPassword.nix; syncthing-guiPasswordFile = runTest ./syncthing/guiPasswordFile.nix; diff --git a/nixos/tests/syncthing/defaults.nix b/nixos/tests/syncthing/defaults.nix new file mode 100644 index 000000000000..cd90d40770e5 --- /dev/null +++ b/nixos/tests/syncthing/defaults.nix @@ -0,0 +1,42 @@ +{ lib, pkgs, ... }: +let + expectedPath = "/tmp/syncthing-default"; +in +{ + name = "syncthing-defaults"; + meta.maintainers = with pkgs.lib.maintainers; [ seudonym ]; + + nodes.machine = + { pkgs, ... }: + { + environment.systemPackages = [ + pkgs.libxml2 + pkgs.curl + ]; + services.syncthing = { + enable = true; + settings.defaults.folder.path = expectedPath; + }; + }; + + testScript = '' + import json + + machine.wait_for_unit("syncthing.service") + machine.wait_for_unit("syncthing-init.service") + + # Get the API key by parsing the config.xml + api_key = machine.succeed( + "xmllint --xpath 'string(configuration/gui/apikey)' /var/lib/syncthing/.config/syncthing/config.xml" + ).strip() + + # Query the defaults/folder endpoint via Syncthing's REST API + config = json.loads(machine.succeed( + f"curl -Ssf -H 'X-API-Key: {api_key}' http://127.0.0.1:8384/rest/config/defaults/folder" + )) + + actual_path = config.get('path') + assert actual_path == "${expectedPath}", f"Default folder path is '{actual_path}', but expected '${expectedPath}'" + machine.log(f"Success: Default folder path is correctly set to '{actual_path}'") + ''; +}