btrfs-progs: tests: Test if mkfs.btrfs --rootdir can handle ng symlink
authorQu Wenruo <wqu@suse.com>
Thu, 29 Mar 2018 01:26:44 +0000 (09:26 +0800)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Mar 2018 20:15:55 +0000 (22:15 +0200)
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
tests/mkfs-tests/016-rootdir-bad-symbolic-link/test.sh [new file with mode: 0755]

diff --git a/tests/mkfs-tests/016-rootdir-bad-symbolic-link/test.sh b/tests/mkfs-tests/016-rootdir-bad-symbolic-link/test.sh
new file mode 100755 (executable)
index 0000000..39387ec
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+# Regression test for mkfs.btrfs --rootdir with dangling symlink (points to
+# non-existing location)
+#
+# Since mkfs.btrfs --rootdir will just create symbolic link rather than
+# follow it, we shouldn't hit any problem
+
+source "$TEST_TOP/common"
+
+check_prereq mkfs.btrfs
+prepare_test_dev
+
+tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX)
+
+non_existing="/no/such/file$RANDOM$RANDOM"
+
+if [ -f "$non_existing" ]; then
+       _not_run "Some one created $non_existing, which is not expect to exist"
+fi
+
+run_check ln -sf "$non_existing" "$tmp/foobar"
+
+run_check "$TOP/mkfs.btrfs" -f --rootdir "$tmp" "$TEST_DEV"
+run_check "$TOP/btrfs" check "$TEST_DEV"
+
+rm -rf -- "$tmp"