about summary refs log tree commit diff
path: root/nixos/tests/btrbk-section-order.nix
blob: 20f1afcf80ec770400e13eab99df6aa8834d915a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# This tests validates the order of generated sections that may contain
# other sections.
# When a `volume` section has both `subvolume` and `target` children,
# `target` must go before `subvolume`. Otherwise, `target` will become
# a child of the last `subvolume` instead of `volume`, due to the
# order-sensitive config format.
#
# Issue: https://github.com/NixOS/nixpkgs/issues/195660
import ./make-test-python.nix ({ lib, pkgs, ... }: {
  name = "btrbk-section-order";
  meta.maintainers = with lib.maintainers; [ oxalica ];

  nodes.machine = { ... }: {
    services.btrbk.instances.local = {
      onCalendar = null;
      settings = {
        timestamp_format = "long";
        target."ssh://global-target/".ssh_user = "root";
        volume."/btrfs" = {
          snapshot_dir = "/volume-snapshots";
          target."ssh://volume-target/".ssh_user = "root";
          subvolume."@subvolume" = {
            snapshot_dir = "/subvolume-snapshots";
            target."ssh://subvolume-target/".ssh_user = "root";
          };
        };
      };
    };
  };

  testScript = ''
    machine.wait_for_unit("basic.target")
    got = machine.succeed("cat /etc/btrbk/local.conf")
    expect = """
    backend btrfs-progs-sudo
    timestamp_format long
    target ssh://global-target/
     ssh_user root
    volume /btrfs
     snapshot_dir /volume-snapshots
     target ssh://volume-target/
      ssh_user root
     subvolume @subvolume
      snapshot_dir /subvolume-snapshots
      target ssh://subvolume-target/
       ssh_user root
    """.strip()
    print(got)
    assert got == expect
  '';
})