]> git.scottworley.com Git - syncthing-autoregister/blobdiff - tests/automatic-enrollment.nix
Two machines
[syncthing-autoregister] / tests / automatic-enrollment.nix
index cac1b28ba83956bea3ea77f67fbe355ea4b81411..46940488a952c7d87319dc737ef5fdf720ba8759 100644 (file)
@@ -9,24 +9,47 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
         services.syncthing = {
           enable = true;
           openDefaultPorts = true;
         services.syncthing = {
           enable = true;
           openDefaultPorts = true;
+          autoRegister = {
+            enable = true;
+            path = "/tmp/syncthing-auto-register-test-device-ids.nix";
+          };
         };
         environment.systemPackages = with pkgs; [ nix ];
       }
     '';
         };
         environment.systemPackages = with pkgs; [ nix ];
       }
     '';
+    configurationWithDeviceIDs =
+      pkgs.writeText "configuration-with-device-ids.nix" ''
+        {
+          imports = [
+            ${configuration}
+            /tmp/syncthing-auto-register-test-device-ids.nix
+          ];
+        }
+      '';
   in {
 
     name = "syncthing";
 
   in {
 
     name = "syncthing";
 
-    machine = "${configuration}";
+    nodes = {
+      a = "${configuration}";
+      b = "${configuration}";
+    };
 
     testScript = ''
 
     testScript = ''
-      machine.copy_from_host(
-          "${configuration}",
-          "/etc/nixos/configuration.nix",
+      def setConfig(machine, config):
+          machine.copy_from_host(config, "/etc/nixos/configuration.nix")
+
+
+      initialConfiguration = "${configuration}"
+      configurationWithDeviceIDs = (
+          "${configurationWithDeviceIDs}"
       )
       )
-      machine.wait_for_unit("syncthing-autoregister.service")
-      machine.succeed(
-          '(( "$(nix eval --raw -f /tmp/syncthing-auto-register-test-device-ids.nix services.syncthing.declarative.devices.machine.id | wc -c)" == 63 ))'
+
+      setConfig(a, initialConfiguration)
+      a.wait_for_unit("syncthing-autoregister.service")
+      setConfig(a, configurationWithDeviceIDs)
+      a.succeed(
+          '(( "$(nix eval --raw -f "<nixos/nixos>" config.services.syncthing.declarative.devices.a.id | wc -c)" == 63 ))'
       )
     '';
   })
       )
     '';
   })