]> arthur.barton.de Git - bup.git/blob - t/test.sh
test.sh: separate index and split/join tests
[bup.git] / t / test.sh
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . wvtest-bup.sh
4 . t/lib.sh
5
6 set -o pipefail
7
8 top="$(WVPASS /bin/pwd)" || exit $?
9 tmpdir="$(WVPASS wvmktempdir)" || exit $?
10 export BUP_DIR="$tmpdir/bup"
11
12 bup() { "$top/bup" "$@"; }
13
14 WVPASS cd "$tmpdir"
15
16 WVSTART "init"
17
18 WVPASS bup init
19
20 D=bupdata.tmp
21 WVPASS force-delete $D
22 WVPASS mkdir $D
23 WVPASS touch $D/a
24 WVPASS bup random 128k >$D/b
25 WVPASS mkdir $D/d $D/d/e
26 WVPASS bup random 512 >$D/f
27 WVPASS touch $D/d/z
28 WVPASS touch $D/d/z
29 WVPASS bup index $D
30 WVPASS bup save -t $D
31
32 WVSTART "bloom"
33 WVPASS bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
34 WVPASS rm "$BUP_DIR"/objects/pack/bup.bloom
35 WVPASS bup bloom -k 4
36 WVPASS bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
37 WVPASS bup bloom -d "$BUP_DIR"/objects/pack --ruin --force
38 WVFAIL bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
39 WVPASS bup bloom --force -k 5
40 WVPASS bup bloom -c $(ls -1 "$BUP_DIR"/objects/pack/*.idx|head -n1)
41
42 WVSTART "memtest"
43 WVPASS bup memtest -c1 -n100
44 WVPASS bup memtest -c1 -n100 --existing
45
46 WVSTART "save/git-fsck"
47 (
48     WVPASS cd "$BUP_DIR"
49     #git repack -Ad
50     #git prune
51     WVPASS bup random 4k | WVPASS bup split -b
52     (WVPASS cd "$top/t/sampledata" && WVPASS bup save -vvn master /) || exit $?
53     result="$(git fsck --full --strict 2>&1)" || exit $?
54     n=$(echo "$result" |
55         WVFAIL egrep -v 'dangling (commit|tree|blob)' |
56         WVPASS tee -a /dev/stderr |
57         WVPASS wc -l) || exit $?
58     WVPASS [ "$n" -eq 0 ]
59 ) || exit $?
60
61 WVSTART "restore"
62 WVPASS force-delete buprestore.tmp
63 WVFAIL bup restore boink
64 WVPASS touch "$tmpdir/$D/$D"
65 WVPASS bup index -u "$tmpdir/$D"
66 WVPASS bup save -n master /
67 WVPASS bup restore -C buprestore.tmp "/master/latest/$tmpdir/$D"
68 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
69 WVPASS force-delete buprestore.tmp
70 WVPASS bup restore -C buprestore.tmp "/master/latest/$tmpdir/$D/"
71 WVPASS touch $D/non-existent-file buprestore.tmp/non-existent-file # else diff fails
72 WVPASS diff -ur $D/ buprestore.tmp/
73 WVPASS force-delete buprestore.tmp
74 WVPASS echo -n "" | WVPASS bup split -n split_empty_string.tmp
75 WVPASS bup restore -C buprestore.tmp split_empty_string.tmp/latest/
76 WVPASSEQ "$(cat buprestore.tmp/data)" ""
77
78 (
79     tmp=testrestore.tmp
80     WVPASS force-delete $tmp
81     WVPASS mkdir $tmp
82     export BUP_DIR="$(pwd)/$tmp/bup"
83     WVPASS WVPASS bup init
84     WVPASS mkdir -p $tmp/src/x/y/z
85     WVPASS bup random 8k > $tmp/src/x/y/random-1
86     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
87     WVPASS bup index -u $tmp/src
88     WVPASS bup save --strip -n foo $tmp/src
89
90     WVSTART "restore /foo/latest"
91     WVPASS bup restore -C $tmp/restore /foo/latest
92     WVPASS "$top/t/compare-trees" $tmp/src/ $tmp/restore/latest/
93
94     WVSTART "restore /foo/latest/"
95     WVPASS force-delete "$tmp/restore"
96     WVPASS bup restore -C $tmp/restore /foo/latest/
97     for x in $tmp/src/*; do
98         WVPASS "$top/t/compare-trees" $x/ $tmp/restore/$(basename $x);
99     done
100
101     WVSTART "restore /foo/latest/."
102     WVPASS force-delete "$tmp/restore"
103     WVPASS bup restore -C $tmp/restore /foo/latest/.
104     WVPASS "$top/t/compare-trees" $tmp/src/ $tmp/restore/
105
106     WVSTART "restore /foo/latest/x"
107     WVPASS force-delete "$tmp/restore"
108     WVPASS bup restore -C $tmp/restore /foo/latest/x
109     WVPASS "$top/t/compare-trees" $tmp/src/x/ $tmp/restore/x/
110
111     WVSTART "restore /foo/latest/x/"
112     WVPASS force-delete "$tmp/restore"
113     WVPASS bup restore -C $tmp/restore /foo/latest/x/
114     for x in $tmp/src/x/*; do
115         WVPASS "$top/t/compare-trees" $x/ $tmp/restore/$(basename $x);
116     done
117
118     WVSTART "restore /foo/latest/x/."
119     WVPASS force-delete "$tmp/restore"
120     WVPASS bup restore -C $tmp/restore /foo/latest/x/.
121     WVPASS "$top/t/compare-trees" $tmp/src/x/ $tmp/restore/
122 ) || exit $?
123
124
125 WVSTART "ftp"
126 WVPASS bup ftp "cat /master/latest/$tmpdir/$D/b" >$D/b.new
127 WVPASS bup ftp "cat /master/latest/$tmpdir/$D/f" >$D/f.new
128 WVPASS bup ftp "cat /master/latest/$tmpdir/$D/f"{,} >$D/f2.new
129 WVPASS bup ftp "cat /master/latest/$tmpdir/$D/a" >$D/a.new
130 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
131 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
132 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
133 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
134
135 WVSTART "tag"
136 WVFAIL bup tag -d v0.n 2>/dev/null
137 WVFAIL bup tag v0.n non-existant 2>/dev/null
138 WVPASSEQ "$(bup tag)" ""
139 WVPASS bup tag v0.1 master
140 WVPASSEQ "$(bup tag)" "v0.1"
141 WVFAIL bup tag v0.1 master
142 WVPASS bup tag -f v0.1 master
143 WVPASS bup tag -d v0.1
144 WVPASS bup tag -f -d v0.1
145 WVFAIL bup tag -d v0.1
146
147
148 WVSTART "save (no index)"
149 (
150     tmp=save-no-index.tmp
151     WVPASS force-delete $tmp
152     WVPASS mkdir $tmp
153     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
154     WVPASS bup init
155     WVFAIL bup save -n nothing /
156     WVPASS rm -r "$tmp"
157 ) || exit $?
158
159 WVSTART "indexfile"
160 D=indexfile.tmp
161 INDEXFILE=tmpindexfile.tmp
162 WVPASS rm -f $INDEXFILE
163 WVPASS force-delete $D
164 WVPASS mkdir $D
165 export BUP_DIR="$D/.bup"
166 WVPASS bup init
167 WVPASS touch $D/a
168 WVPASS touch $D/b
169 WVPASS mkdir $D/c
170 WVPASS bup index -ux $D
171 WVPASS bup save --strip -n bupdir $D
172 WVPASSEQ "$(bup ls -F bupdir/latest/)" "a
173 b
174 c/"
175 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
176 WVPASS bup save --strip -n indexfile -f $INDEXFILE $D
177 WVPASSEQ "$(bup ls indexfile/latest/)" "a
178 b"
179
180
181 WVSTART "import-rsnapshot"
182 D=rsnapshot.tmp
183 export BUP_DIR="$tmpdir/$D/.bup"
184 WVPASS force-delete $D
185 WVPASS mkdir $D
186 WVPASS bup init
187 WVPASS mkdir -p $D/hourly.0/buptest/a
188 WVPASS touch $D/hourly.0/buptest/a/b
189 WVPASS mkdir -p $D/hourly.0/buptest/c/d
190 WVPASS touch $D/hourly.0/buptest/c/d/e
191 WVPASS true
192 WVPASS bup import-rsnapshot $D/
193 WVPASSEQ "$(bup ls -F buptest/latest/)" "a/
194 c/"
195
196
197 WVSTART "save disjoint top-level directories"
198 (
199     # Resolve any symlinks involving the top top-level dirs.
200     real_pwd="$(WVPASS realpath .)" || exit $?
201     real_tmp="$(WVPASS realpath /tmp/.)" || exit $?
202     pwd_top="$(echo $real_pwd | WVPASS awk -F "/" '{print $2}')" || exit $?
203     tmp_top="$(echo $real_tmp | WVPASS awk -F "/" '{print $2}')" || exit $?
204
205     if [ "$pwd_top" = "$tmp_top" ]; then
206         echo "(running from within /$tmp_top; skipping test)" 1>&2
207         exit 0
208     fi
209     D=bupdata.tmp
210     WVPASS force-delete $D
211     WVPASS mkdir -p $D/x
212     WVPASS date > $D/x/1
213     tmpdir2="$(WVPASS mktemp -d $real_tmp/bup-test-XXXXXXX)" || exit $?
214     cleanup() { WVPASS rm -r "$tmpdir2"; }
215     WVPASS trap cleanup EXIT
216     WVPASS date > "$tmpdir2/2"
217
218     export BUP_DIR="$tmpdir/bup"
219     WVPASS test -d "$BUP_DIR" && WVPASS rm -r "$BUP_DIR"
220
221     WVPASS bup init
222     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir2"
223     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir2"
224
225     # For now, assume that "ls -a" and "sort" use the same order.
226     actual="$(WVPASS bup ls -AF src/latest)" || exit $?
227     expected="$(echo -e "$pwd_top/\n$tmp_top/" | WVPASS sort)" || exit $?
228     WVPASSEQ "$actual" "$expected"
229 ) || exit $?
230
231 WVPASS rm -rf "$tmpdir"