]> git.scottworley.com Git - syncthing-autoregister/blob - tests/automatic-enrollment.nix
46940488a952c7d87319dc737ef5fdf720ba8759
[syncthing-autoregister] / tests / automatic-enrollment.nix
1 import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
2 let
3 configuration = pkgs.writeText "configuration.nix" ''
4 { pkgs, ... }: {
5 imports = [
6 ${../.}/modules/syncthing-autoregister.nix
7 <nixos/nixos/modules/installer/cd-dvd/channel.nix>
8 ];
9 services.syncthing = {
10 enable = true;
11 openDefaultPorts = true;
12 autoRegister = {
13 enable = true;
14 path = "/tmp/syncthing-auto-register-test-device-ids.nix";
15 };
16 };
17 environment.systemPackages = with pkgs; [ nix ];
18 }
19 '';
20 configurationWithDeviceIDs =
21 pkgs.writeText "configuration-with-device-ids.nix" ''
22 {
23 imports = [
24 ${configuration}
25 /tmp/syncthing-auto-register-test-device-ids.nix
26 ];
27 }
28 '';
29 in {
30
31 name = "syncthing";
32
33 nodes = {
34 a = "${configuration}";
35 b = "${configuration}";
36 };
37
38 testScript = ''
39 def setConfig(machine, config):
40 machine.copy_from_host(config, "/etc/nixos/configuration.nix")
41
42
43 initialConfiguration = "${configuration}"
44 configurationWithDeviceIDs = (
45 "${configurationWithDeviceIDs}"
46 )
47
48 setConfig(a, initialConfiguration)
49 a.wait_for_unit("syncthing-autoregister.service")
50 setConfig(a, configurationWithDeviceIDs)
51 a.succeed(
52 '(( "$(nix eval --raw -f "<nixos/nixos>" config.services.syncthing.declarative.devices.a.id | wc -c)" == 63 ))'
53 )
54 '';
55 })