]> arthur.barton.de Git - bup.git/blob - test/ext/test-fuse
Teach pytest to handle WVSKIP and use it where we can
[bup.git] / test / ext / test-fuse
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3 . dev/lib.sh || exit $?
4
5 set -o pipefail
6
7 unset BLOCKSIZE BLOCK_SIZE DF_BLOCK_SIZE
8
9 root_status="$(dev/root-status)" || exit $?
10
11 if ! bup-python -c 'import fuse' 2> /dev/null; then
12     WVSKIP 'unable to import fuse; skipping test'
13     exit 0
14 fi
15
16 if test -n "$(type -p modprobe)" && ! modprobe fuse; then
17     WVSKIP 'Unable to load fuse module; skipping dependent tests.'
18     exit 0
19 fi
20
21 if ! fusermount -V; then
22     WVSKIP 'skipping FUSE tests: fusermount does not appear to work'
23     exit 0
24 fi
25
26 if ! groups | grep -q fuse && test "$root_status" != root; then
27     WVSKIP 'skipping FUSE tests: you are not root and not in the fuse group'
28     exit 0
29 fi
30
31
32 clean_up() { fusermount -uz mnt || true; }
33 trap clean_up EXIT
34
35
36 top="$(WVPASS pwd)" || exit $?
37 tmpdir="$(WVPASS wvmktempdir)" || exit $?
38
39 export BUP_DIR="$tmpdir/bup"
40 export GIT_DIR="$tmpdir/bup"
41
42 bup() { "$top/bup" "$@"; }
43
44 # Some versions of bash's printf don't support the relevant date expansion.
45 savename()
46 {
47     readonly secs="$1"
48     WVPASS bup-cfg-py -c "from time import strftime, localtime; \
49        print(strftime('%Y-%m-%d-%H%M%S', localtime($secs)))"
50 }
51
52 export TZ=UTC
53
54 WVPASS bup init
55 WVPASS cd "$tmpdir"
56
57 savestamp1=$(WVPASS bup-cfg-py -c 'import time; print(int(time.time()))') || exit $?
58 savestamp2=$(($savestamp1 + 1))
59
60 savename1="$(savename "$savestamp1")" || exit $?
61 savename2="$(savename "$savestamp2")" || exit $?
62
63 WVPASS mkdir src
64 WVPASS echo content > src/foo
65 WVPASS chmod 644 src/foo
66 WVPASS touch -t 201111111111 src/foo
67 # FUSE, python-fuse, something, can't handle negative epoch times.
68 # Use pre-epoch to make sure bup properly "bottoms out" at 0 for now.
69 WVPASS echo content > src/pre-epoch
70 WVPASS chmod 644 src/pre-epoch
71 WVPASS touch -t 196907202018 src/pre-epoch
72 WVPASS bup index src
73 WVPASS bup save -n src -d "$savestamp1" --strip src
74
75 WVSTART "basics"
76 WVPASS mkdir mnt
77
78 bup fuse -f mnt &
79 fuse_pid=$!
80 while ! test -d mnt/src; do
81     sleep 0.1
82 done
83
84 result=$(WVPASS ls mnt) || exit $?
85 WVPASSEQ src "$result"
86
87 result=$(WVPASS ls mnt/src) || exit $?
88 WVPASSEQ "$result" "$savename1
89 latest"
90
91 result=$(WVPASS ls mnt/src/latest) || exit $?
92 WVPASSEQ "$result" "foo
93 pre-epoch"
94
95 result=$(WVPASS cat mnt/src/latest/foo) || exit $?
96 WVPASSEQ "$result" "content"
97
98 # Right now we don't detect new saves.
99 WVPASS bup save -n src -d "$savestamp2" --strip src
100 result=$(WVPASS ls mnt/src) || exit $?
101 WVPASSEQ "$result" "$savename1
102 latest"
103
104 WVPASS fusermount -uz mnt
105 WVPASS wait "$fuse_pid"
106 fuse_pid=''
107
108 WVSTART "extended metadata"
109
110 bup fuse -f --meta mnt &
111 fuse_pid=$!
112 while ! test -d mnt/src; do
113     sleep 0.1
114 done
115
116 readonly user=$(WVPASS id -un) || $?
117 readonly group=$(WVPASS id -gn) || $?
118 result="$(stat --format='%A %U %G %x' mnt/src/latest/foo)"
119 WVPASSEQ "$result" "-rw-r--r-- $user $group 2011-11-11 11:11:00.000000000 +0000"
120 result="$(stat --format='%A %U %G %x' mnt/src/latest/pre-epoch)"
121 WVPASSEQ "$result" "-rw-r--r-- $user $group 1970-01-01 00:00:00.000000000 +0000"
122
123 WVPASS fusermount -uz mnt
124 WVPASS rm -rf "$tmpdir"