]> arthur.barton.de Git - bup.git/commitdiff
Add tests for index --no-check-device, and support for t/mnt.
authorRob Browning <rlb@defaultvalue.org>
Sun, 17 Feb 2013 03:20:50 +0000 (21:20 -0600)
committerRob Browning <rlb@defaultvalue.org>
Mon, 18 Mar 2013 01:22:33 +0000 (20:22 -0500)
Add support for t/mnt; anything mounted there will be cleaned up
during "make clean".

Thanks to Zak Wilcox <iwilcox@iwilcox.me.uk> for an earlier version of
these tests.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Makefile
t/lib.sh
t/test-index-check-device.sh [new file with mode: 0755]
t/test-meta.sh
wvtest-bup.sh

index 560a8580c1b2ca9c0701bc0326cfa3f4e19ad960..241a4bc82efcf9711f004eebd5488cd373c5eca7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -89,6 +89,7 @@ runtests-cmdline: all
        t/test.sh
        t/test-meta.sh
        t/test-restore-single-file.sh
+       t/test-index-check-device.sh
 
 stupid:
        PATH=/bin:/usr/bin $(MAKE) test
@@ -158,6 +159,9 @@ clean: Documentation/clean config/clean
                bup bup-* cmd/bup-* lib/bup/_version.py randomgen memtest \
                out[12] out2[tc] tags[12] tags2[tc] \
                testfs.img lib/bup/t/testfs.img
+       umount t/mnt/* || true
+       if test -e t/mnt; then rm -r t/mnt; fi
+        # FIXME: migrate these to t/mnt/
        if test -e bupmeta.tmp/testfs; \
          then umount bupmeta.tmp/testfs || true; fi
        if test -e lib/bup/t/testfs; \
index e8e526812eee939e288595039b99c25b6b6ed5ee..5696c61ed4b9b58170d9a5dfaa13594371e3d7dc 100644 (file)
--- a/t/lib.sh
+++ b/t/lib.sh
@@ -1,3 +1,9 @@
+# Assumes shell is Bash.
+
+actually-root()
+{
+    test "$(whoami)" == root -a -z "$FAKEROOTKEY"
+}
 
 force-delete()
 {
diff --git a/t/test-index-check-device.sh b/t/test-index-check-device.sh
new file mode 100755 (executable)
index 0000000..de7f7ed
--- /dev/null
@@ -0,0 +1,80 @@
+#!/usr/bin/env bash
+. ./wvtest-bup.sh
+. ./t/lib.sh
+
+set -ex -o pipefail
+
+if ! actually-root; then
+    echo 'Not root: skipping --check-device tests.'
+    exit 0 # FIXME: add WVSKIP.
+fi
+
+if test -z "$(type -p losetup)"; then
+    echo 'Unable to find losetup: skipping --check-device tests.'
+    exit 0 # FIXME: add WVSKIP.
+fi
+
+if test -z "$(type -p mke2fs)"; then
+    echo 'Unable to find mke2fs: skipping --check-device tests.'
+    exit 0 # FIXME: add WVSKIP.
+fi
+
+WVSTART '--check-device'
+
+top="$(pwd)"
+tmpdir="$(wvmktempdir)"
+export BUP_DIR="$tmpdir/bup"
+
+bup() { "$top/bup" "$@"; }
+
+srcmnt="$(wvmkmountpt)"
+tmpmnt1="$(wvmkmountpt)"
+tmpmnt2="$(wvmkmountpt)"
+
+cd "$tmpdir"
+
+dd if=/dev/zero of=testfs.img bs=1M count=32
+mke2fs -F -j -m 0 testfs.img
+mount -o loop testfs.img "$tmpmnt1"
+# Hide, so that tests can't create risks.
+chown root:root "$tmpmnt1"
+chmod 0700 "$tmpmnt1"
+
+# Create trivial content.
+date > "$tmpmnt1/foo"
+umount "$tmpmnt1"
+
+# Mount twice, so we'll have the same content with different devices.
+mount -oro,loop testfs.img "$tmpmnt1"
+mount -oro,loop testfs.img "$tmpmnt2"
+
+# Test default behavior: --check-device.
+mount -oro --bind "$tmpmnt1" "$srcmnt"
+bup init
+bup index --fake-valid "$srcmnt"
+umount "$srcmnt"
+mount -oro --bind "$tmpmnt2" "$srcmnt"
+bup index "$srcmnt"
+WVPASSEQ "$(bup index --status "$srcmnt")" \
+"M $srcmnt/lost+found/
+M $srcmnt/foo
+M $srcmnt/"
+umount "$srcmnt"
+
+WVSTART '--no-check-device'
+mount -oro --bind "$tmpmnt1" "$srcmnt"
+bup index --clear
+bup index --fake-valid "$srcmnt"
+umount "$srcmnt"
+mount -oro --bind "$tmpmnt2" "$srcmnt"
+bup index --no-check-device "$srcmnt"
+bup index --status "$srcmnt"
+WVPASSEQ "$(bup index --status "$srcmnt")" \
+"  $srcmnt/lost+found/
+  $srcmnt/foo
+  $srcmnt/"
+
+umount "$srcmnt"
+umount "$tmpmnt1"
+umount "$tmpmnt2"
+rm -r "$tmpmnt1" "$tmpmnt2" "$tmpdir"
index 1354505253f34ebc5569a7ea10919977e5877928..29c182813a35d38bb8b28a29c7faab6210c9b881 100755 (executable)
@@ -30,11 +30,6 @@ genstat()
     )
 }
 
-actually-root()
-{
-    test "$(whoami)" == root -a -z "$FAKEROOTKEY"
-}
-
 test-src-create-extract()
 {
     # Test bup meta create/extract for ./src -> ./src-restore.
index e7e7752eb43e4a9278b65b148af00e2c4d3817e2..2529da3ad0dd96a8715317da44317bf52065fb97 100644 (file)
@@ -9,8 +9,16 @@ _wvtop="$(pwd)"
 
 wvmktempdir ()
 (
-    local script_name="$(basename $0)"
+    script_name="$(basename $0)"
     set -e -o pipefail
     mkdir -p "$_wvtop/t/tmp"
-    echo "$(mktemp -d "$_wvtop/t/tmp/$script_name-XXXXXXX")"
+    mktemp -d "$_wvtop/t/tmp/$script_name-XXXXXXX"
+)
+
+wvmkmountpt ()
+(
+    script_name="$(basename $0)"
+    set -e -o pipefail
+    mkdir -p "$_wvtop/t/mnt"
+    mktemp -d "$_wvtop/t/mnt/$script_name-XXXXXXX"
 )