Skip to content

Commit c4eeb23

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 4194335 commit c4eeb23

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,71 +7,110 @@ 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, but exiting with zero anyway."
1515
exit 0
1616
fi
1717

18-
if [ ! -d "$BTRFS_IMAGE_MOUNTPOINT" ]; then
19-
sudo mkdir "$BTRFS_IMAGE_MOUNTPOINT"
18+
if [ ! -d "$BTRFS_MOUNTPOINT" ]; then
19+
sudo mkdir "$BTRFS_MOUNTPOINT"
2020
fi
21-
IS_BTRFS_MOUNTED="$(mount | grep rmw-btrfs)" || true
22-
if [ -z "$IS_BTRFS_MOUNTED" ]; then
23-
sudo mount -o loop "$IMAGE_PATH" \
24-
"$BTRFS_IMAGE_MOUNTPOINT"
25-
sudo chown "$(id -u)" -R "$BTRFS_IMAGE_MOUNTPOINT"
21+
22+
if ! mount | grep -q rmw-btrfs; then
23+
sudo mount -o loop "$BTRFS_IMAGE" "$BTRFS_MOUNTPOINT"
24+
sudo chown "$(id -u)" -R "$BTRFS_MOUNTPOINT"
2625
fi
2726

28-
cd "$BTRFS_IMAGE_MOUNTPOINT"
29-
RMW_TEST_CMD_STRING="$BIN_DIR/rmw -c ${MESON_SOURCE_ROOT}/test/conf/btrfs_img.testrc"
27+
cd "$BTRFS_MOUNTPOINT"
28+
BTRFS_RMW_CMD="$BIN_DIR/rmw -c ${MESON_SOURCE_ROOT}/test/conf/btrfs_img.testrc"
3029

31-
SUBVOLUME_USED="/tmp/rmw-loop/@two"
30+
BTRFS_SUBVOLUME="$BTRFS_MOUNTPOINT/@two"
31+
BTRFS_WASTE_DIR="$BTRFS_SUBVOLUME/Waste"
3232

33-
WASTE_USED="$SUBVOLUME_USED/Waste"
34-
if [ -d "$WASTE_USED" ]; then
35-
rm -rf "$WASTE_USED"
33+
if [ -d "$BTRFS_WASTE_DIR" ]; then
34+
rm -rf "$BTRFS_WASTE_DIR"
3635
fi
3736

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

85+
echo "== Test: restore the moved file"
86+
$BTRFS_RMW_CMD -u
87+
test -f foo
88+
test ! -f "$BTRFS_WASTE_DIR/info/foo.trashinfo"
89+
90+
# --- Test: purge an expired file from btrfs waste ---
91+
echo "== Test: purge an expired file from btrfs waste"
92+
RMW_FAKE_YEAR=true $BTRFS_RMW_CMD foo
93+
test -f "$BTRFS_WASTE_DIR/files/foo"
94+
test -f "$BTRFS_WASTE_DIR/info/foo.trashinfo"
95+
$BTRFS_RMW_CMD -g
96+
test ! -f "$BTRFS_WASTE_DIR/files/foo"
97+
test ! -f "$BTRFS_WASTE_DIR/info/foo.trashinfo"
98+
99+
# --- Test: cross-subvolume move from a non-btrfs home directory ---
100+
echo "== Test: move file from non-btrfs home to btrfs waste"
64101
cd "$RMW_FAKE_HOME"
65102
touch foo
66-
$RMW_TEST_CMD_STRING foo -v
103+
$BTRFS_RMW_CMD foo -v
67104
test ! -f foo
68-
$RMW_TEST_CMD_STRING -u
105+
106+
echo "== Test: restore file to non-btrfs home from btrfs waste"
107+
$BTRFS_RMW_CMD -u
69108
test -f foo
70109

71110
cd
72111

73112
if mount | grep -q rmw-btrfs; then
74-
sudo umount "$BTRFS_IMAGE_MOUNTPOINT"
113+
sudo umount "$BTRFS_MOUNTPOINT"
75114
fi
76115

77116
exit 0

0 commit comments

Comments
 (0)