test/bin-test/test-dav-sync-hashing1.sh

changeset 650
14e7101d7604
equal deleted inserted replaced
649:0f4c59ac8c74 650:14e7101d7604
1 #!/bin/sh
2 #
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 #
5 # Copyright 2019 Olaf Wintermann. All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
9 #
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 #
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28 #
29
30 if [ -z "$DAV_BIN" ];
31 then
32 echo "DAV_BIN variable not set"
33 exit 1
34 fi
35 if [ -z "$DAV_SYNC_BIN" ];
36 then
37 echo "DAV_BIN variable not set"
38 exit 1
39 fi
40
41 # checks if tmp-sync/out.txt contains a specific text
42 # arg1: pattern
43 # arg2: errormsg
44 check_tmpout()
45 {
46 TEST=`cat tmp-sync/out.txt | grep "$1"`
47 if [ $? -ne 0 ];
48 then
49 echo "$2"
50 exit 2
51 fi
52 }
53
54 # do dav-sync push and check return value
55 # arg1: dir
56 # arg2: errormsg
57 dav_sync_push()
58 {
59 $DAV_SYNC_BIN push $1 > tmp-sync/out.txt
60 if [ $? -ne 0 ];
61 then
62 echo "$2"
63 exit 2
64 fi
65 }
66 # do dav-sync pull and check return value
67 # arg1: dir
68 # arg2: errormsg
69 dav_sync_pull()
70 {
71 $DAV_SYNC_BIN pull $1 > tmp-sync/out.txt
72 if [ $? -ne 0 ];
73 then
74 echo "$2"
75 exit 2
76 fi
77 }
78
79 rm -f .dav/dav-sync-tests-test2a-db.xml
80 rm -f .dav/dav-sync-tests-test2b-db.xml
81
82 $DAV_BIN rm dav-test-repo/sync/test2 2> /dev/null
83
84 $DAV_BIN mkcol dav-test-repo/sync/test2 2> /dev/null
85
86 # tmp sync dir
87 rm -Rf tmp-sync
88 mkdir tmp-sync
89 mkdir tmp-sync/test2a
90 mkdir tmp-sync/test2b
91
92 # ----------------------------------------------------------------------------
93 # 1. test: add 4 files, push, pull (not really an hashing test)
94 # expected result: 4 files pushed, 4 files pulled
95
96 mkdir tmp-sync/test2a/dir1/
97 mkdir tmp-sync/test2a/dir1/subdir1/
98
99 cp synctest/file1 tmp-sync/test2a/
100 cp synctest/file2 tmp-sync/test2a/dir1/
101 cp synctest/file3 tmp-sync/test2a/dir1/subdir1
102 cp synctest/file4 tmp-sync/test2a/dir1/subdir1
103
104 dav_sync_push test2a "test 1: push failed"
105 check_tmpout "4 files pushed" "test 1: wrong push counter"
106 check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)"
107 check_tmpout "0 errors" "test 1: wrong error counter (push)"
108
109 dav_sync_pull test2b "test 1: pull failed"
110 check_tmpout "4 files pulled" "test 1: wrong pull counter"
111 check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)"
112 check_tmpout "0 errors" "test 1: wrong error counter (pull)"
113
114
115 # ----------------------------------------------------------------------------
116 # 2. test: touch 2 files, push
117 # expected result: 0 files pushed
118
119 sleep 3
120
121 touch tmp-sync/test2a/file1
122 touch tmp-sync/test2a/dir1/file2
123
124 dav_sync_push test2a "test 2: push failed"
125 check_tmpout "0 files pushed" "test 2: wrong push counter"
126 check_tmpout "0 conflicts" "test 2: wrong conflict counter"
127 check_tmpout "0 errors" "test 2: wrong error counter"
128
129
130 # ----------------------------------------------------------------------------
131 # 3. test: copy file1 to test2a again
132 # expected result: 0 files pushed
133
134 sleep 3
135
136 cp synctest/file1 tmp-sync/test2a/
137
138 dav_sync_push test2a "test 3: push failed"
139 check_tmpout "0 files pushed" "test 3: wrong push counter"
140 check_tmpout "0 conflicts" "test 3: wrong conflict counter"
141 check_tmpout "0 errors" "test 3: wrong error counter"
142
143
144 # ----------------------------------------------------------------------------
145 # 4. test: change content but don't change mtime
146 # expected result: 1 file pushed
147
148 # modify file and mtime to update mtime in the database
149 echo "test4-change1-a" >> tmp-sync/test2a/file1
150 touch -t 01011200 tmp-sync/test2a/file1
151
152 dav_sync_push test2a "test 4: push failed (1)"
153 check_tmpout "1 file pushed" "test 4: wrong push counter (1)"
154 check_tmpout "0 conflicts" "test 4: wrong conflict counter (1)"
155 check_tmpout "0 errors" "test 4: wrong error counter (1)"
156
157 # modify file again and set mtime to same value
158 echo "test4-change2-a" >> tmp-sync/test2a/file1
159 touch -t 01011200 tmp-sync/test2a/file1
160
161 dav_sync_push test2a "test 4: push failed (2)"
162 check_tmpout "1 file pushed" "test 4: wrong push counter (2)"
163 check_tmpout "0 conflicts" "test 4: wrong conflict counter (2)"
164 check_tmpout "0 errors" "test 4: wrong error counter (2)"
165
166
167 # ----------------------------------------------------------------------------
168 # 5. test: set same content on both sides
169 # expected result: no conflict
170
171 # prepare test2b
172 dav_sync_pull test2b "test 5: pull failed"
173 check_tmpout "1 file pulled" "test 5: wrong pull counter"
174 check_tmpout "0 conflicts" "test 5: wrong conflict counter (prepare)"
175 check_tmpout "0 errors" "test 5: wrong error counter (prepare)"
176
177 # change content on both sides
178 echo "test5-change" >> tmp-sync/test2a/file1
179 echo "test5-change" >> tmp-sync/test2b/file1
180
181 # push both sides
182 dav_sync_push test2a "test 5: push failed (test2a)"
183 check_tmpout "1 file pushed" "test 5: wrong push counter (test2a)"
184 check_tmpout "0 conflicts" "test 5: wrong conflict counter (test2a)"
185 check_tmpout "0 errors" "test 5: wrong error counter (test2a)"
186
187 dav_sync_push test2b "test 5: push failed (test2b)"
188 # don't check push counter
189 check_tmpout "0 conflicts" "test 5: wrong conflict counter (test2b)"
190 check_tmpout "0 errors" "test 5: wrong error counter (test2b)"
191
192
193 # ----------------------------------------------------------------------------
194 # 6. test: upload same new file on both sides
195 # expected result: no conflict
196
197 echo "test6-newfile" >> tmp-sync/test2a/newfile1
198 echo "test6-newfile" >> tmp-sync/test2b/newfile1
199
200 # push both sides
201 dav_sync_push test2a "test 6: push failed (test2a)"
202 check_tmpout "1 file pushed" "test 6: wrong push counter (test2a)"
203 check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2a)"
204 check_tmpout "0 errors" "test 6: wrong error counter (test2a)"
205
206 dav_sync_push test2b "test 6: push failed (test2b)"
207 # don't check push counter
208 check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2b)"
209 check_tmpout "0 errors" "test 6: wrong error counter (test2b)"
210
211
212 # ----------------------------------------------------------------------------
213 # 7. test: rename file
214 # expected result: move
215
216 mv tmp-sync/test2a/newfile1 tmp-sync/test2a/move1
217
218 dav_sync_push test2a "test 7: push failed"
219 check_tmpout "move:" "test 7: no move"
220 check_tmpout "0 conflicts" "test 7: wrong conflict counter"
221 check_tmpout "0 errors" "test 7: wrong error counter"
222
223
224 # ----------------------------------------------------------------------------
225 # 8. test: copy file
226 # expected result: copy
227
228 cp tmp-sync/test2a/file1 tmp-sync/test2a/copy1
229
230 dav_sync_push test2a "test 8: push failed"
231 check_tmpout "copy:" "test 8: no move"
232 check_tmpout "0 conflicts" "test 8: wrong conflict counter"
233 check_tmpout "0 errors" "test 8: wrong error counter"
234
235
236 # ----------------------------------------------------------------------------
237 # 9. test: copy file1 multiple times and than delete it
238 # expected result: multiple copies, maybe one move, no errors
239
240 echo "test9-change" >> tmp-sync/test2a/file1
241 dav_sync_push test2a "test 9: push failed (prepare)"
242 check_tmpout "1 file pushed" "test 9: wrong push counter (prepare)"
243 check_tmpout "0 conflicts" "test 9: wrong conflict counter (prepare)"
244 check_tmpout "0 errors" "test 9: wrong error counter (prepare)"
245
246 cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx1
247 cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx2
248 cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx3
249 cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx4
250 cp tmp-sync/test2a/file1 tmp-sync/test2a/copyx5
251 rm -f tmp-sync/test2a/file1
252
253 dav_sync_push test2a "test 9: push failed"
254 check_tmpout "copy:" "test 9: no move"
255 check_tmpout "0 conflicts" "test 9: wrong conflict counter"
256 check_tmpout "0 errors" "test 9: wrong error counter"
257
258 # to check if everything worked, pull test2b and check the files
259
260 dav_sync_pull test2b
261 check_tmpout "0 conflicts" "test 9: wrong conflict counter (pull)"
262 check_tmpout "0 errors" "test 9: wrong error counter (pull)"
263
264 cat tmp-sync/test2b/file1 > /dev/null 2>&1
265 if [ $? -eq 0 ]; then
266 echo "test 9: file1 not deleted (pull)"
267 exit 2
268 fi
269
270 diff tmp-sync/test2a/copyx1 tmp-sync/test2b/copyx1 > /dev/null 2>&1
271 if [ $? -ne 0 ]; then
272 echo "test 9: copyx1 missing or wrong content"
273 exit 2
274 fi
275 diff tmp-sync/test2a/copyx2 tmp-sync/test2b/copyx2 > /dev/null 2>&1
276 if [ $? -ne 0 ]; then
277 echo "test 9: copyx2 missing or wrong content"
278 exit 2
279 fi
280 diff tmp-sync/test2a/copyx3 tmp-sync/test2b/copyx3 > /dev/null 2>&1
281 if [ $? -ne 0 ]; then
282 echo "test 9: copyx3 missing or wrong content"
283 exit 2
284 fi
285 diff tmp-sync/test2a/copyx4 tmp-sync/test2b/copyx4 > /dev/null 2>&1
286 if [ $? -ne 0 ]; then
287 echo "test 9: copyx4 missing or wrong content"
288 exit 2
289 fi
290 diff tmp-sync/test2a/copyx5 tmp-sync/test2b/copyx5 > /dev/null 2>&1
291 if [ $? -ne 0 ]; then
292 echo "test 9: copyx5 missing or wrong content"
293 exit 2
294 fi
295
296
297 # ----------------------------------------------------------------------------
298 # 10. test: rename all copyx files, which will have all the same content hash
299 # we don't test if everything is moved (instead of deleted), but to make sure
300 # no errors occur when working with files with the same content
301 # expected result: no errors
302
303 mv tmp-sync/test2a/copyx1 tmp-sync/test2a/movex1
304 mv tmp-sync/test2a/copyx2 tmp-sync/test2a/movex2
305 mv tmp-sync/test2a/copyx3 tmp-sync/test2a/movex3
306 mv tmp-sync/test2a/copyx4 tmp-sync/test2a/movex4
307 mv tmp-sync/test2a/copyx5 tmp-sync/test2a/movex5
308
309 dav_sync_push test2a "test 10: push failed"
310 check_tmpout "move:" "test 10: no move"
311 check_tmpout "0 conflicts" "test 10: wrong conflict counter"
312 check_tmpout "0 errors" "test 10: wrong error counter"
313
314 # to check if everything worked, pull test2b and check the files
315
316 dav_sync_pull test2b
317 check_tmpout "0 conflicts" "test 9: wrong conflict counter (pull)"
318 check_tmpout "0 errors" "test 9: wrong error counter (pull)"
319
320 diff tmp-sync/test2a/movex1 tmp-sync/test2b/movex1 > /dev/null 2>&1
321 if [ $? -ne 0 ]; then
322 echo "test 10: movex1 missing or wrong content"
323 exit 2
324 fi
325 diff tmp-sync/test2a/movex2 tmp-sync/test2b/movex2 > /dev/null 2>&1
326 if [ $? -ne 0 ]; then
327 echo "test 10: movex2 missing or wrong content"
328 exit 2
329 fi
330 diff tmp-sync/test2a/movex3 tmp-sync/test2b/movex3 > /dev/null 2>&1
331 if [ $? -ne 0 ]; then
332 echo "test 10: movex3 missing or wrong content"
333 exit 2
334 fi
335 diff tmp-sync/test2a/movex4 tmp-sync/test2b/movex4 > /dev/null 2>&1
336 if [ $? -ne 0 ]; then
337 echo "test 10: movex4 missing or wrong content"
338 exit 2
339 fi
340 diff tmp-sync/test2a/movex5 tmp-sync/test2b/movex5 > /dev/null 2>&1
341 if [ $? -ne 0 ]; then
342 echo "test 10: movex5 missing or wrong content"
343 exit 2
344 fi
345
346
347 # ----------------------------------------------------------------------------
348 # 11. test: copy file, push test2a, pull test2b
349 # expected result: pull copies file
350
351 cp tmp-sync/test2a/movex5 tmp-sync/test2a/newcopyt11
352 dav_sync_push test2a "test 11: push failed"
353 check_tmpout "copy:" "test 11: no copy (push)"
354 check_tmpout "0 conflicts" "test 11: wrong conflict counter (push)"
355 check_tmpout "0 errors" "test 11: wrong error counter (push)"
356
357 dav_sync_pull test2b "test 11: pull failed"
358 check_tmpout "copy:" "test 11: no copy (pull)"
359 check_tmpout "0 conflicts" "test 11: wrong conflict counter (pull)"
360 check_tmpout "0 errors" "test 11: wrong error counter (pull)"
361
362
363 # ----------------------------------------------------------------------------
364 # 12. test: move file, push test2a, pull test2b
365 # expected result: pull moves file
366
367 # we need a fresh file with new content hash for this test
368 echo "test12-newfile" >> tmp-sync/test2a/t12file1
369 dav_sync_push test2a "test 12: push failed (prepare)"
370 check_tmpout "1 file pushed" "test 12: wrong push counter (prepare)"
371 check_tmpout "0 conflicts" "test 12: wrong conflict counter (push, prepare)"
372 check_tmpout "0 errors" "test 12: wrong error counter (push, prepare)"
373
374 dav_sync_pull test2b "test 12: pull failed (prepare)"
375 check_tmpout "1 file pulled" "test 12: wrong pull counter (prepare)"
376 check_tmpout "0 conflicts" "test 12: wrong conflict counter (pull, prepare)"
377 check_tmpout "0 errors" "test 12: wrong error counter (pull, prepare)"
378
379 # actual test
380 mv tmp-sync/test2a/t12file1 tmp-sync/test2a/t12move1
381 dav_sync_push test2a "test 12: push failed"
382 check_tmpout "move:" "test 12: no copy (push)"
383 check_tmpout "0 conflicts" "test 12: wrong conflict counter (push)"
384 check_tmpout "0 errors" "test 12: wrong error counter (push)"
385
386 dav_sync_pull test2b "test 12: pull failed"
387 check_tmpout "move:" "test 12: no move (pull)"
388 check_tmpout "0 conflicts" "test 12: wrong conflict counter (pull)"
389 check_tmpout "0 errors" "test 12: wrong error counter (pull)"
390
391
392 # ----------------------------------------------------------------------------
393 # 13. test: delete file, change name of other file to deleted file's name
394 # expected result: first file has content of second file, second file deleted
395
396 # prepare
397 echo "test13-file1" > tmp-sync/test2a/t13file1
398 sleep 3 # make sure t13file2 doesn't has the same mtime as t13file1
399 echo "test13-file2" > tmp-sync/test2a/t13file2
400
401 dav_sync_push test2a "test 13: push failed (prepare)"
402 check_tmpout "2 files pushed" "test 13: wrong push counter (prepare, push)"
403 check_tmpout "0 conflicts" "test 13: wrong conflict counter (prepare, push)"
404 check_tmpout "0 errors" "test 13: wrong error counter (prepare, push)"
405
406 dav_sync_pull test2b "test 13: pull failed (prepare)"
407 check_tmpout "2 files pulled" "test 13: wrong pull counter (prepare, pull)"
408 check_tmpout "0 conflicts" "test 13: wrong conflict counter (prepare, pull)"
409 check_tmpout "0 errors" "test 13: wrong error counter (prepare, pull)"
410
411 # do test
412 rm -f tmp-sync/test2a/t13file1
413 mv tmp-sync/test2a/t13file2 tmp-sync/test2a/t13file1
414
415 sleep 2
416
417 dav_sync_push test2a "test 13: push failed"
418 # we can't check the exact output, because there are multiple valid ways
419 # to sync the changes
420 check_tmpout "0 conflicts" "test 13: wrong conflict counter (push)"
421 check_tmpout "0 errors" "test 13: wrong error counter (push)"
422
423 dav_sync_pull test2b "test 13: pull failed"
424 check_tmpout "0 conflicts" "test 13: wrong conflict counter (pull)"
425 check_tmpout "0 errors" "test 13: wrong error counter (pull)"
426
427 TEST=`cat tmp-sync/test2b/t13file1`
428 if [ $TEST != "test13-file2" ]; then
429 echo "test 13: t13file1 has wrong content"
430 exit 2
431 fi
432
433 cat tmp-sync/test2b/t13file2 > /dev/null 2>&1
434 if [ $? -eq 0 ]; then
435 echo "test 13: t13file2 not deleted"
436 exit 2
437 fi
438
439
440

mercurial