Skip to content

Commit 4ec98f9

Browse files
andy5995claude
andcommitted
test: improve btrfs clone test coverage and rename variables
- Rename variables for clarity: BTRFS_IMAGE_MOUNTPOINT -> BTRFS_MOUNTPOINT, IMAGE_PATH -> BTRFS_IMAGE, SUBVOLUME_USED -> BTRFS_SUBVOLUME, WASTE_USED -> BTRFS_WASTE_DIR, TEST_DIR -> BTRFS_TEST_DIR, RMW_TEST_CMD_STRING -> BTRFS_RMW_CMD - Derive BTRFS_SUBVOLUME from BTRFS_MOUNTPOINT instead of hardcoding - Inline single-use IS_BTRFS_MOUNTED variable - Add trashinfo assertions after each move, restore, and purge - Add nested directory test (a/b/c/deep_file) covering safe_mv_via_exec Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 28e3c8e commit 4ec98f9

File tree

1 file changed

+80
-41
lines changed

1 file changed

+80
-41
lines changed

test/test_btrfs_clone.sh

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ else
77
. "${MESON_SOURCE_ROOT}/test/COMMON"
88
fi
99

10-
BTRFS_IMAGE_MOUNTPOINT="/tmp/rmw-loop"
11-
IMAGE_PATH="${MESON_SOURCE_ROOT}/test/rmw-btrfs-test.img"
10+
BTRFS_MOUNTPOINT="/tmp/rmw-loop"
11+
BTRFS_IMAGE="${MESON_SOURCE_ROOT}/test/rmw-btrfs-test.img"
1212

13-
if [ ! -f "$IMAGE_PATH" ]; then
13+
if [ ! -f "$BTRFS_IMAGE" ]; then
1414
echo "Test image not found; skipping."
1515
exit 0
1616
fi
@@ -20,63 +20,102 @@ if ! sudo -n true 2>/dev/null; then
2020
exit 0
2121
fi
2222

23-
if [ ! -d "$BTRFS_IMAGE_MOUNTPOINT" ]; then
24-
sudo mkdir "$BTRFS_IMAGE_MOUNTPOINT"
23+
if [ ! -d "$BTRFS_MOUNTPOINT" ]; then
24+
sudo mkdir "$BTRFS_MOUNTPOINT"
2525
fi
26-
IS_BTRFS_MOUNTED="$(mount | grep rmw-btrfs)" || true
27-
if [ -z "$IS_BTRFS_MOUNTED" ]; then
28-
sudo mount -o loop "$IMAGE_PATH" \
29-
"$BTRFS_IMAGE_MOUNTPOINT"
30-
sudo chown "$(id -u)" -R "$BTRFS_IMAGE_MOUNTPOINT"
26+
27+
if ! mount | grep -q rmw-btrfs; then
28+
sudo mount -o loop "$BTRFS_IMAGE" "$BTRFS_MOUNTPOINT"
29+
sudo chown "$(id -u)" -R "$BTRFS_MOUNTPOINT"
3130
fi
3231

33-
cd "$BTRFS_IMAGE_MOUNTPOINT"
34-
RMW_TEST_CMD_STRING="$BIN_DIR/rmw -c ${MESON_SOURCE_ROOT}/test/conf/btrfs_img.testrc"
32+
cd "$BTRFS_MOUNTPOINT"
33+
BTRFS_RMW_CMD="$BIN_DIR/rmw -c ${MESON_SOURCE_ROOT}/test/conf/btrfs_img.testrc"
3534

36-
SUBVOLUME_USED="/tmp/rmw-loop/@two"
35+
BTRFS_SUBVOLUME="$BTRFS_MOUNTPOINT/@two"
36+
BTRFS_WASTE_DIR="$BTRFS_SUBVOLUME/Waste"
3737

38-
WASTE_USED="$SUBVOLUME_USED/Waste"
39-
if [ -d "$WASTE_USED" ]; then
40-
rm -rf "$WASTE_USED"
38+
if [ -d "$BTRFS_WASTE_DIR" ]; then
39+
rm -rf "$BTRFS_WASTE_DIR"
4140
fi
4241

43-
TEST_DIR="$BTRFS_IMAGE_MOUNTPOINT/test_dir"
44-
if [ -d "$TEST_DIR" ]; then
45-
rm -rf "$TEST_DIR"
42+
# --- Test: move a directory with contents across btrfs subvolumes ---
43+
echo "== Test: move a directory with contents across btrfs subvolumes"
44+
BTRFS_TEST_DIR="$BTRFS_MOUNTPOINT/test_dir"
45+
if [ -d "$BTRFS_TEST_DIR" ]; then
46+
rm -rf "$BTRFS_TEST_DIR"
4647
fi
47-
48-
mkdir "$TEST_DIR"
49-
touch "$TEST_DIR/bar"
50-
$RMW_TEST_CMD_STRING "$TEST_DIR"
51-
test ! -d "$TEST_DIR"
52-
53-
$RMW_TEST_CMD_STRING -u
54-
test -d "$TEST_DIR"
55-
48+
mkdir "$BTRFS_TEST_DIR"
49+
touch "$BTRFS_TEST_DIR/bar"
50+
$BTRFS_RMW_CMD "$BTRFS_TEST_DIR"
51+
test ! -d "$BTRFS_TEST_DIR"
52+
test -d "$BTRFS_WASTE_DIR/files/test_dir"
53+
test -f "$BTRFS_WASTE_DIR/files/test_dir/bar"
54+
test -f "$BTRFS_WASTE_DIR/info/test_dir.trashinfo"
55+
56+
echo "== Test: restore the moved directory"
57+
$BTRFS_RMW_CMD -u
58+
test -d "$BTRFS_TEST_DIR"
59+
test -f "$BTRFS_TEST_DIR/bar"
60+
test ! -f "$BTRFS_WASTE_DIR/info/test_dir.trashinfo"
61+
62+
# --- Test: move a deeply nested directory across btrfs subvolumes ---
63+
echo "== Test: move a deeply nested directory across btrfs subvolumes"
64+
BTRFS_NESTED_DIR="$BTRFS_MOUNTPOINT/nested_dir"
65+
if [ -d "$BTRFS_NESTED_DIR" ]; then
66+
rm -rf "$BTRFS_NESTED_DIR"
67+
fi
68+
mkdir -p "$BTRFS_NESTED_DIR/a/b/c"
69+
touch "$BTRFS_NESTED_DIR/a/b/c/deep_file"
70+
$BTRFS_RMW_CMD "$BTRFS_NESTED_DIR"
71+
test ! -d "$BTRFS_NESTED_DIR"
72+
test -d "$BTRFS_WASTE_DIR/files/nested_dir"
73+
test -f "$BTRFS_WASTE_DIR/files/nested_dir/a/b/c/deep_file"
74+
test -f "$BTRFS_WASTE_DIR/info/nested_dir.trashinfo"
75+
76+
echo "== Test: restore the nested directory"
77+
$BTRFS_RMW_CMD -u
78+
test -d "$BTRFS_NESTED_DIR/a/b/c"
79+
test -f "$BTRFS_NESTED_DIR/a/b/c/deep_file"
80+
test ! -f "$BTRFS_WASTE_DIR/info/nested_dir.trashinfo"
81+
82+
# --- Test: move a file across btrfs subvolumes ---
83+
echo "== Test: move a file across btrfs subvolumes"
5684
touch foo
57-
$RMW_TEST_CMD_STRING foo
58-
test -f "$WASTE_USED/files/foo"
59-
test -f "$WASTE_USED/info/foo.trashinfo"
85+
$BTRFS_RMW_CMD foo
86+
test -f "$BTRFS_WASTE_DIR/files/foo"
87+
test -f "$BTRFS_WASTE_DIR/info/foo.trashinfo"
6088
test ! -f foo
61-
$RMW_TEST_CMD_STRING -u
62-
test -f foo
63-
64-
RMW_FAKE_YEAR=true $RMW_TEST_CMD_STRING foo
65-
test -f "$WASTE_USED/files/foo"
66-
$RMW_TEST_CMD_STRING -g
67-
test ! -f "$WASTE_USED/files/foo"
6889

90+
echo "== Test: restore the moved file"
91+
$BTRFS_RMW_CMD -u
92+
test -f foo
93+
test ! -f "$BTRFS_WASTE_DIR/info/foo.trashinfo"
94+
95+
# --- Test: purge an expired file from btrfs waste ---
96+
echo "== Test: purge an expired file from btrfs waste"
97+
RMW_FAKE_YEAR=true $BTRFS_RMW_CMD foo
98+
test -f "$BTRFS_WASTE_DIR/files/foo"
99+
test -f "$BTRFS_WASTE_DIR/info/foo.trashinfo"
100+
$BTRFS_RMW_CMD -g
101+
test ! -f "$BTRFS_WASTE_DIR/files/foo"
102+
test ! -f "$BTRFS_WASTE_DIR/info/foo.trashinfo"
103+
104+
# --- Test: cross-subvolume move from a non-btrfs home directory ---
105+
echo "== Test: move file from non-btrfs home to btrfs waste"
69106
cd "$RMW_FAKE_HOME"
70107
touch foo
71-
$RMW_TEST_CMD_STRING foo -v
108+
$BTRFS_RMW_CMD foo -v
72109
test ! -f foo
73-
$RMW_TEST_CMD_STRING -u
110+
111+
echo "== Test: restore file to non-btrfs home from btrfs waste"
112+
$BTRFS_RMW_CMD -u
74113
test -f foo
75114

76115
cd
77116

78117
if mount | grep -q rmw-btrfs; then
79-
sudo umount "$BTRFS_IMAGE_MOUNTPOINT"
118+
sudo umount "$BTRFS_MOUNTPOINT"
80119
fi
81120

82121
exit 0

0 commit comments

Comments
 (0)