diff options
author | Lassulus <github@lassul.us> | 2020-07-25 11:40:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-25 11:40:06 +0200 |
commit | 032775d0acbd901bcaf30e2e603d836a68eb016b (patch) | |
tree | f83e4773bcf749bd474181b90d5dd53316a67ab2 /nixos | |
parent | bd437f83ba0dbebdec0ebb7c83c798323bdf12fd (diff) | |
parent | 140247cd8a290e71c951d2b8de676cf688a7ea6b (diff) | |
download | nixpkgs-032775d0acbd901bcaf30e2e603d836a68eb016b.tar nixpkgs-032775d0acbd901bcaf30e2e603d836a68eb016b.tar.gz nixpkgs-032775d0acbd901bcaf30e2e603d836a68eb016b.tar.bz2 nixpkgs-032775d0acbd901bcaf30e2e603d836a68eb016b.tar.lz nixpkgs-032775d0acbd901bcaf30e2e603d836a68eb016b.tar.xz nixpkgs-032775d0acbd901bcaf30e2e603d836a68eb016b.tar.zst nixpkgs-032775d0acbd901bcaf30e2e603d836a68eb016b.zip |
Merge pull request #93788 from chkno/syncthing-test
nixos/tests: Add test for syncthing
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/tests/all-tests.nix | 1 | ||||
-rw-r--r-- | nixos/tests/syncthing.nix | 65 |
2 files changed, 66 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 7f3bb9bcc81..60a99838ae6 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -319,6 +319,7 @@ in sudo = handleTest ./sudo.nix {}; switchTest = handleTest ./switch-test.nix {}; sympa = handleTest ./sympa.nix {}; + syncthing = handleTest ./syncthing.nix {}; syncthing-init = handleTest ./syncthing-init.nix {}; syncthing-relay = handleTest ./syncthing-relay.nix {}; systemd = handleTest ./systemd.nix {}; diff --git a/nixos/tests/syncthing.nix b/nixos/tests/syncthing.nix new file mode 100644 index 00000000000..9e2a8e01e3f --- /dev/null +++ b/nixos/tests/syncthing.nix @@ -0,0 +1,65 @@ +import ./make-test-python.nix ({ lib, pkgs, ... }: { + name = "syncthing"; + meta.maintainers = with pkgs.stdenv.lib.maintainers; [ chkno ]; + + nodes = rec { + a = { + environment.systemPackages = with pkgs; [ curl libxml2 syncthing ]; + services.syncthing = { + enable = true; + openDefaultPorts = true; + }; + }; + b = a; + }; + + testScript = '' + import json + import shlex + + confdir = "/var/lib/syncthing/.config/syncthing" + + + def addPeer(host, name, deviceID): + APIKey = host.succeed( + "xmllint --xpath 'string(configuration/gui/apikey)' %s/config.xml" % confdir + ).strip() + oldConf = host.succeed( + "curl -Ss -H 'X-API-Key: %s' 127.0.0.1:8384/rest/system/config" % APIKey + ) + conf = json.loads(oldConf) + conf["devices"].append({"deviceID": deviceID, "id": name}) + conf["folders"].append( + { + "devices": [{"deviceID": deviceID}], + "id": "foo", + "path": "/var/lib/syncthing/foo", + "rescanIntervalS": 1, + } + ) + newConf = json.dumps(conf) + host.succeed( + "curl -Ss -H 'X-API-Key: %s' 127.0.0.1:8384/rest/system/config -d %s" + % (APIKey, shlex.quote(newConf)) + ) + + + start_all() + a.wait_for_unit("syncthing.service") + b.wait_for_unit("syncthing.service") + a.wait_for_open_port(22000) + b.wait_for_open_port(22000) + + aDeviceID = a.succeed("syncthing -home=%s -device-id" % confdir).strip() + bDeviceID = b.succeed("syncthing -home=%s -device-id" % confdir).strip() + addPeer(a, "b", bDeviceID) + addPeer(b, "a", aDeviceID) + + a.wait_for_file("/var/lib/syncthing/foo") + b.wait_for_file("/var/lib/syncthing/foo") + a.succeed("echo a2b > /var/lib/syncthing/foo/a2b") + b.succeed("echo b2a > /var/lib/syncthing/foo/b2a") + a.wait_for_file("/var/lib/syncthing/foo/b2a") + b.wait_for_file("/var/lib/syncthing/foo/a2b") + ''; +}) |