diff mbox series

[v2,9/9] btrfs-progs: mkfs-tests: introduce a test case to verify --subvol option

Message ID d97df89c85038dfb0393eec0a93039d64f443b40.1697754500.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: mkfs: introduce an experimental --subvol option | expand

Commit Message

Qu Wenruo Oct. 19, 2023, 10:30 p.m. UTC
This test case would try the following combinations:

- Valid cases
  * subvolume directly under fs tree
  * subvolume with several parent directories
  * subvolume path with unnecessary too many duplicated '/'s

- Invalid cases
  * subvolume path without any filename, e.g. "/////"
  * subvolume path with ".."

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 tests/mkfs-tests/031-subvol-option/test.sh | 39 ++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100755 tests/mkfs-tests/031-subvol-option/test.sh
diff mbox series

Patch

diff --git a/tests/mkfs-tests/031-subvol-option/test.sh b/tests/mkfs-tests/031-subvol-option/test.sh
new file mode 100755
index 000000000000..eedd257b746e
--- /dev/null
+++ b/tests/mkfs-tests/031-subvol-option/test.sh
@@ -0,0 +1,39 @@ 
+#!/bin/bash
+# Verify "mkfs.btrfs --subvol" option can handle valid and invalid subvolume
+# paths correctly
+
+source "$TEST_TOP/common" || exit
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev
+
+# Make sure we have enabled experimental features
+output=$(run_check_stdout "$TOP/mkfs.btrfs" --help 2>&1 | grep -- --subvol)
+
+if [ -z "$output" ]; then
+	_not_run "experimental features are not enabled"
+fi
+
+# Valid case, simple subvolume directly under fs root.
+run_check_mkfs_test_dev --subvol "subv"
+run_check "$TOP/btrfs" check $TEST_DEV
+
+# Valid case, subvolume with several parent directories.
+run_check_mkfs_test_dev --subvol "dir1/dir2/dir3/subv"
+run_check "$TOP/btrfs" check $TEST_DEV
+
+# Valid case, subvolume with several parent directories, and
+# unnecessarily too many '/'s
+run_check_mkfs_test_dev --subvol "////dir1/dir2//dir3/dir4/////subv////"
+run_check "$TOP/btrfs" check $TEST_DEV
+
+# Invalid case, subvolume path contains no filename
+run_mustfail "invalid subvolume without filename should fail" \
+	"$TOP/mkfs.btrfs" -f --subvol "//////" $TEST_DEV
+
+# Invalid case, subvolume path contains ".."
+run_mustfail "invalid subvolume without filename should fail" \
+	"$TOP/mkfs.btrfs" -f --subvol "../subvol" $TEST_DEV