summaryrefslogtreecommitdiff
path: root/test/test-common.sh
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-01-05 18:39:47 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2014-01-05 18:50:17 -0500
commitfa6e7ccf3914081504681679645fd7cfd803cfdd (patch)
tree021ae0f16368db8b4be9c3b6bcc6cec949e9522e /test/test-common.sh
parentb07f84783a9b3e4e799e93173977882de6c16fa8 (diff)
test/: re-jigger the chroot tests to be fast on btrfs
Diffstat (limited to 'test/test-common.sh')
-rw-r--r--test/test-common.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/test-common.sh b/test/test-common.sh
index aadd8f2..46e584d 100644
--- a/test/test-common.sh
+++ b/test/test-common.sh
@@ -26,6 +26,29 @@ _after_sudo() {
fi
}
+_setup_chrootdir() {
+ if [[ -z "$chrootdir" ]]; then
+ export chrootdir="$(mktemp -d --tmpdir "test-chrootdir.XXXXXXXXXXXX")"
+ trap "$(printf '_cleanup_chrootdir %q' "$chrootdir")" EXIT
+ fi
+}
+
+_cleanup_chrootdir() (
+ chrootdir=$1
+ shopt -s nullglob
+ if [[ $SUDO ]]; then
+ for copydir in "$chrootdir"/*/*/; do
+ local chroottype=$(stat -f -c %T "$copydir")
+ if [[ "$chroottype" == btrfs ]] && ! mountpoint -q "$copydir"; then
+ sudo btrfs subvolume delete "$copydir" >/dev/null
+ fi
+ done
+ sudo rm -rf -- "$chrootdir"
+ else
+ rm -rf -- "$chrootdir"
+ fi
+)
+
require() (
set +x
local missing=()