1# This tests validates the order of generated sections that may contain
2# other sections.
3# When a `volume` section has both `subvolume` and `target` children,
4# `target` must go before `subvolume`. Otherwise, `target` will become
5# a child of the last `subvolume` instead of `volume`, due to the
6# order-sensitive config format.
7#
8# Issue: https://github.com/NixOS/nixpkgs/issues/195660
9import ./make-test-python.nix (
10 { lib, pkgs, ... }:
11 {
12 name = "btrbk-section-order";
13 meta.maintainers = with lib.maintainers; [ oxalica ];
14
15 nodes.machine =
16 { ... }:
17 {
18 services.btrbk.instances.local = {
19 onCalendar = null;
20 settings = {
21 timestamp_format = "long";
22 target."ssh://global-target/".ssh_user = "root";
23 volume."/btrfs" = {
24 snapshot_dir = "/volume-snapshots";
25 target."ssh://volume-target/".ssh_user = "root";
26 subvolume."@subvolume" = {
27 snapshot_dir = "/subvolume-snapshots";
28 target."ssh://subvolume-target/".ssh_user = "root";
29 };
30 };
31 };
32 };
33 };
34
35 testScript = ''
36 import difflib
37 machine.wait_for_unit("basic.target")
38 got = machine.succeed("cat /etc/btrbk/local.conf").strip()
39 expect = """
40 backend btrfs-progs-sudo
41 stream_compress no
42 timestamp_format long
43 target ssh://global-target/
44 ssh_user root
45 volume /btrfs
46 snapshot_dir /volume-snapshots
47 target ssh://volume-target/
48 ssh_user root
49 subvolume @subvolume
50 snapshot_dir /subvolume-snapshots
51 target ssh://subvolume-target/
52 ssh_user root
53 """.strip()
54 print(got)
55 if got != expect:
56 diff = difflib.unified_diff(expect.splitlines(keepends=True), got.splitlines(keepends=True), fromfile="expected", tofile="got")
57 print("".join(diff))
58 assert got == expect
59 '';
60 }
61)