at 25.11-pre 2.1 kB view raw
1import ./make-test-python.nix ( 2 { lib, pkgs, ... }: 3 { 4 name = "syncthing"; 5 meta.maintainers = with pkgs.lib.maintainers; [ chkno ]; 6 7 nodes = rec { 8 a = { 9 environment.systemPackages = with pkgs; [ 10 curl 11 libxml2 12 syncthing 13 ]; 14 services.syncthing = { 15 enable = true; 16 openDefaultPorts = true; 17 }; 18 }; 19 b = a; 20 }; 21 22 testScript = '' 23 import json 24 import shlex 25 26 confdir = "/var/lib/syncthing/.config/syncthing" 27 28 29 def addPeer(host, name, deviceID): 30 APIKey = host.succeed( 31 "xmllint --xpath 'string(configuration/gui/apikey)' %s/config.xml" % confdir 32 ).strip() 33 oldConf = host.succeed( 34 "curl -Ssf -H 'X-API-Key: %s' 127.0.0.1:8384/rest/config" % APIKey 35 ) 36 conf = json.loads(oldConf) 37 conf["devices"].append({"deviceID": deviceID, "id": name}) 38 conf["folders"].append( 39 { 40 "devices": [{"deviceID": deviceID}], 41 "id": "foo", 42 "path": "/var/lib/syncthing/foo", 43 "rescanIntervalS": 1, 44 } 45 ) 46 newConf = json.dumps(conf) 47 host.succeed( 48 "curl -Ssf -H 'X-API-Key: %s' 127.0.0.1:8384/rest/config -X PUT -d %s" 49 % (APIKey, shlex.quote(newConf)) 50 ) 51 52 53 start_all() 54 a.wait_for_unit("syncthing.service") 55 b.wait_for_unit("syncthing.service") 56 a.wait_for_open_port(22000) 57 b.wait_for_open_port(22000) 58 59 aDeviceID = a.succeed("syncthing -home=%s -device-id" % confdir).strip() 60 bDeviceID = b.succeed("syncthing -home=%s -device-id" % confdir).strip() 61 addPeer(a, "b", bDeviceID) 62 addPeer(b, "a", aDeviceID) 63 64 a.wait_for_file("/var/lib/syncthing/foo") 65 b.wait_for_file("/var/lib/syncthing/foo") 66 a.succeed("echo a2b > /var/lib/syncthing/foo/a2b") 67 b.succeed("echo b2a > /var/lib/syncthing/foo/b2a") 68 a.wait_for_file("/var/lib/syncthing/foo/b2a") 69 b.wait_for_file("/var/lib/syncthing/foo/a2b") 70 ''; 71 } 72)