]> git.scottworley.com Git - syncthing-autoregister/blame - tests/automatic-enrollment.nix
verifyDeviceIDSet() helper
[syncthing-autoregister] / tests / automatic-enrollment.nix
CommitLineData
b00b144b
SW
1import <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;
7fb0951b
SW
12 autoRegister = {
13 enable = true;
64eaba73 14 path = "/tmp/syncthing-auto-register-test-device-ids.nix";
7fb0951b 15 };
b00b144b
SW
16 };
17 environment.systemPackages = with pkgs; [ nix ];
18 }
19 '';
97c3aa62
SW
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 '';
b00b144b
SW
29 in {
30
31 name = "syncthing";
32
cefa20b6
SW
33 nodes = {
34 a = "${configuration}";
35 b = "${configuration}";
36 };
b00b144b
SW
37
38 testScript = ''
97c3aa62
SW
39 def setConfig(machine, config):
40 machine.copy_from_host(config, "/etc/nixos/configuration.nix")
41
42
0a262b79
SW
43 def verifyDeviceIDSet(machine, expectedDevice):
44 machine.succeed(
45 '(( "$(nix eval --raw -f "<nixos/nixos>" config.services.syncthing.declarative.devices.%s.id | wc -c)" == 63 ))'
46 % expectedDevice
47 )
48
49
97c3aa62
SW
50 initialConfiguration = "${configuration}"
51 configurationWithDeviceIDs = (
52 "${configurationWithDeviceIDs}"
b00b144b 53 )
97c3aa62 54
cefa20b6
SW
55 setConfig(a, initialConfiguration)
56 a.wait_for_unit("syncthing-autoregister.service")
57 setConfig(a, configurationWithDeviceIDs)
0a262b79 58 verifyDeviceIDSet(a, "a")
b00b144b
SW
59 '';
60 })