]>
Commit | Line | Data |
---|---|---|
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 | initialConfiguration = pkgs.writeText "initial-configuration.nix" '' | |
21 | { | |
22 | imports = [ "${configuration}" ]; | |
23 | system.activationScripts.installInitialConfiguration = { | |
24 | text = ''' | |
25 | mkdir -p /etc/nixos | |
26 | cp "${configuration}" /etc/nixos/configuration.nix | |
27 | '''; | |
28 | deps = [ ]; | |
29 | }; | |
30 | } | |
31 | ''; | |
32 | configurationWithDeviceIDs = | |
33 | pkgs.writeText "configuration-with-device-ids.nix" '' | |
34 | { | |
35 | imports = [ | |
36 | ${configuration} | |
37 | /tmp/syncthing-auto-register-test-device-ids.nix | |
38 | ]; | |
39 | } | |
40 | ''; | |
41 | in { | |
42 | ||
43 | name = "syncthing"; | |
44 | ||
45 | nodes = { | |
46 | a = "${initialConfiguration}"; | |
47 | b = "${initialConfiguration}"; | |
48 | }; | |
49 | ||
50 | testScript = '' | |
51 | def setConfig(machine, config): | |
52 | machine.copy_from_host(config, "/etc/nixos/configuration.nix") | |
53 | ||
54 | ||
55 | def verifyDeviceIDSet(machine, expectedDevice): | |
56 | machine.succeed( | |
57 | '(( "$(nix eval --raw -f "<nixos/nixos>" config.services.syncthing.declarative.devices.%s.id | wc -c)" == 63 ))' | |
58 | % expectedDevice | |
59 | ) | |
60 | ||
61 | ||
62 | configurationWithDeviceIDs = ( | |
63 | "${configurationWithDeviceIDs}" | |
64 | ) | |
65 | ||
66 | a.wait_for_unit("syncthing-autoregister.service") | |
67 | setConfig(a, configurationWithDeviceIDs) | |
68 | verifyDeviceIDSet(a, "a") | |
69 | ''; | |
70 | }) |