X-Git-Url: http://git.scottworley.com/syncthing-autoregister/blobdiff_plain/4ac4946095213d617adde6b5e7067298c61e6df9..0043dc6823fd9acc5199976084507feb564f4ff0:/tests/automatic-enrollment.nix diff --git a/tests/automatic-enrollment.nix b/tests/automatic-enrollment.nix index 617f672..184bcc7 100644 --- a/tests/automatic-enrollment.nix +++ b/tests/automatic-enrollment.nix @@ -1,11 +1,11 @@ import ({ pkgs, lib, ... }: let deviceIDFilename = "/tmp/syncthing-auto-register-test-device-ids.nix"; - configuration = pkgs.writeText "configuration.nix" '' + vmConfiguration = pkgs.writeText "vm-configuration.nix" '' { pkgs, ... }: { imports = [ + ${../.}/lib/test-nixos-rebuild-switch-config.nix ${../.}/modules/syncthing-autoregister.nix - ]; services.syncthing = { enable = true; @@ -15,37 +15,76 @@ import ({ pkgs, lib, ... }: path = "${deviceIDFilename}"; }; }; + + # For verifyDeviceIDSet() environment.systemPackages = with pkgs; [ nix ]; } ''; - initialConfiguration = pkgs.writeText "initial-configuration.nix" '' - { - imports = [ "${configuration}" ]; + + evaluatedVMConfiguration = import { + system = builtins.currentSystem; + modules = [ "${vmConfiguration}" ]; + }; + + # Also include a syncthing configuration with a declarative device id + # because using this feature pulls in additional dependencies. + evaluatedSyncthingDeclarativeConfiguration = import { + system = builtins.currentSystem; + modules = [ + ../lib/test-nixos-rebuild-switch-config.nix + { + services.syncthing = { + enable = true; + declarative.folders.forDeps.path = "/nope"; + }; + } + ]; + }; + + initialConfiguration = { + imports = [ "${vmConfiguration}" ]; + virtualisation.memorySize = 2048; system.activationScripts.installInitialConfiguration = { - text = ''' + text = '' mkdir -p /etc/nixos - cp "${configuration}" /etc/nixos/configuration.nix - '''; + cp "${vmConfiguration}" /etc/nixos/configuration.nix + ''; deps = [ ]; }; - } - ''; + system.extraDependencies = [ + evaluatedVMConfiguration.config.system.build.toplevel + evaluatedSyncthingDeclarativeConfiguration.config.system.build.toplevel + ]; + }; + configurationWithDeviceIDs = pkgs.writeText "configuration-with-device-ids.nix" '' { imports = [ - ${configuration} + ${vmConfiguration} ${deviceIDFilename} ]; } ''; + + configurationWithFolder = + pkgs.writeText "configuration-with-folder.nix" '' + { config, ... }: { + imports = [ ${configurationWithDeviceIDs} ]; + services.syncthing.declarative.folders.foo = { + devices = [ "a" "b" ]; + path = "''${config.services.syncthing.dataDir}/foo"; + }; + } + ''; + in { name = "syncthing"; nodes = { - a = "${initialConfiguration}"; - b = "${initialConfiguration}"; + a = initialConfiguration; + b = initialConfiguration; }; testScript = '' @@ -81,6 +120,9 @@ import ({ pkgs, lib, ... }: configurationWithDeviceIDs = ( "${configurationWithDeviceIDs}" ) + configurationWithFolder = ( + "${configurationWithFolder}" + ) start_all() a.wait_for_unit("syncthing-autoregister.service") @@ -93,5 +135,18 @@ import ({ pkgs, lib, ... }: setConfig(b, configurationWithDeviceIDs) verifyDeviceIDSet(b, "a") verifyDeviceIDSet(b, "b") + + getDeviceFile(b) + putDeviceFile(a) + setConfig(a, configurationWithFolder) + setConfig(b, configurationWithFolder) + a.succeed("nixos-rebuild switch") + b.succeed("nixos-rebuild switch") + 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") ''; })