|
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 # don't create test2b |
|
91 |
|
92 # ---------------------------------------------------------------------------- |
|
93 # test 1: first pull with exiting files |
|
94 # expected result: no conflicts |
|
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 cp -R tmp-sync/test2a tmp-sync/test2b |
|
105 |
|
106 dav_sync_push test2a "test 1: push failed" |
|
107 check_tmpout "4 files pushed" "test 1: wrong push counter" |
|
108 check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)" |
|
109 check_tmpout "0 errors" "test 1: wrong error counter (push)" |
|
110 |
|
111 dav_sync_pull test2b "test 1: pull failed" |
|
112 check_tmpout "0 files pulled" "test 1: wrong pull counter" |
|
113 check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)" |
|
114 check_tmpout "0 errors" "test 1: wrong error counter (pull)" |
|
115 |
|
116 |
|
117 # ---------------------------------------------------------------------------- |
|
118 # test 2: first push with existing resources on the server |
|
119 # expected result: no conflicts |
|
120 |
|
121 rm -f .dav/dav-sync-tests-test2a-db.xml |
|
122 |
|
123 sleep 2 |
|
124 |
|
125 dav_sync_push test2a "test 2: push failed" |
|
126 check_tmpout "0 files pushed" "test 2: wrong push counter" |
|
127 check_tmpout "0 conflicts" "test 2: wrong conflict counter (push)" |
|
128 check_tmpout "0 errors" "test 2: wrong error counter (push)" |
|
129 |
|
130 dav_sync_pull test2b "test 2: pull failed" |
|
131 check_tmpout "0 files pulled" "test 2: wrong pull counter" |
|
132 check_tmpout "0 conflicts" "test 2: wrong conflict counter (pull)" |
|
133 check_tmpout "0 errors" "test 2: wrong error counter (pull)" |
|
134 |
|
135 |
|
136 # ---------------------------------------------------------------------------- |
|
137 # test 3: modify file1 on both sides (with same content) |
|
138 # expected result: (pull): no conflicts |
|
139 |
|
140 sleep 2 |
|
141 |
|
142 echo "test3-mod" >> tmp-sync/test2a/file1 |
|
143 echo "test3-mod" >> tmp-sync/test2b/file1 |
|
144 |
|
145 dav_sync_push test2a "test 3: push failed" |
|
146 check_tmpout "1 file pushed" "test 3: wrong push counter" |
|
147 check_tmpout "0 conflicts" "test 3: wrong conflict counter (push)" |
|
148 check_tmpout "0 errors" "test 3: wrong error counter (push)" |
|
149 |
|
150 dav_sync_pull test2b "test 3: pull failed" |
|
151 check_tmpout "0 files pulled" "test 3: wrong pull counter" |
|
152 check_tmpout "0 conflicts" "test 3: wrong conflict counter (pull)" |
|
153 check_tmpout "0 errors" "test 3: wrong error counter (pull)" |
|
154 |
|
155 |
|
156 # ---------------------------------------------------------------------------- |
|
157 # test 4: modify file2 on both sides (with same content) and push test2b |
|
158 # expected result: (push): no conflicts |
|
159 |
|
160 sleep 2 |
|
161 |
|
162 echo "test4-mod" >> tmp-sync/test2a/dir1/file2 |
|
163 echo "test4-mod" >> tmp-sync/test2b/dir1/file2 |
|
164 |
|
165 dav_sync_push test2a "test 4: push test2a failed" |
|
166 check_tmpout "1 file pushed" "test 4: wrong push counter (test2a)" |
|
167 check_tmpout "0 conflicts" "test 4: wrong conflict counter (test2a)" |
|
168 check_tmpout "0 errors" "test 4: wrong error counter (test2a)" |
|
169 |
|
170 dav_sync_push test2b "test 4: push test2b failed" |
|
171 check_tmpout "0 files pushed" "test 4: wrong push counter (test2b)" |
|
172 check_tmpout "0 conflicts" "test 4: wrong conflict counter (test2b)" |
|
173 check_tmpout "0 errors" "test 4: wrong error counter (test2b)" |
|
174 |
|
175 dav_sync_pull test2b "test 4: pull failed" |
|
176 check_tmpout "0 files pulled" "test 4: wrong pull counter" |
|
177 check_tmpout "0 conflicts" "test 4: wrong conflict counter (pull)" |
|
178 check_tmpout "0 errors" "test 4: wrong error counter (pull)" |
|
179 |
|
180 |
|
181 # ---------------------------------------------------------------------------- |
|
182 # test 5: add same new file on both sides |
|
183 # expected result: (pull): no conflicts |
|
184 |
|
185 echo "test5-newfilex1" >> tmp-sync/test2a/filex1 |
|
186 echo "test5-newfilex1" >> tmp-sync/test2b/filex1 |
|
187 |
|
188 echo "test5-newfilex2" >> tmp-sync/test2a/filex2 |
|
189 echo "test5-newfilex2" >> tmp-sync/test2b/filex2 |
|
190 |
|
191 dav_sync_push test2a "test 5: push failed" |
|
192 check_tmpout "2 files pushed" "test 5: wrong push counter (push)" |
|
193 check_tmpout "0 conflicts" "test 5: wrong conflict counter (push)" |
|
194 check_tmpout "0 errors" "test 5: wrong error counter (push)" |
|
195 |
|
196 dav_sync_pull test2b "test 5: pull failed" |
|
197 check_tmpout "0 files pulled" "test 5: wrong pull counter" |
|
198 check_tmpout "0 conflicts" "test 5: wrong conflict counter (pull)" |
|
199 check_tmpout "0 errors" "test 5: wrong error counter (pull)" |
|
200 |
|
201 |
|
202 # ---------------------------------------------------------------------------- |
|
203 # test 6: add same new file on both sides and try to push both |
|
204 # expected result: no conflicts |
|
205 |
|
206 echo "test5-newfilez1" >> tmp-sync/test2a/filez1 |
|
207 echo "test5-newfilez1" >> tmp-sync/test2b/filez1 |
|
208 |
|
209 echo "test5-newfilez2" >> tmp-sync/test2a/filez2 |
|
210 echo "test5-newfilez2" >> tmp-sync/test2b/filez2 |
|
211 |
|
212 dav_sync_push test2a "test 6: push test2a failed" |
|
213 check_tmpout "2 files pushed" "test 6: wrong push counter (test2a)" |
|
214 check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2a)" |
|
215 check_tmpout "0 errors" "test 6: wrong error counter (test2a)" |
|
216 |
|
217 dav_sync_push test2b "test 6: push test2b failed" |
|
218 check_tmpout "0 files pushed" "test 6: wrong push counter (test2b)" |
|
219 check_tmpout "0 conflicts" "test 6: wrong conflict counter (test2b)" |
|
220 check_tmpout "0 errors" "test 6: wrong error counter (test2b)" |
|
221 |
|
222 |
|
223 # ---------------------------------------------------------------------------- |
|
224 # test 7: provoke real conflict, push test2a, pull test2b |
|
225 # expected result: (pull): conflict |
|
226 |
|
227 sleep 2 |
|
228 |
|
229 echo "test7-mod-a" >> tmp-sync/test2a/file1 |
|
230 echo "test7-mod-b" >> tmp-sync/test2b/file1 |
|
231 |
|
232 dav_sync_push test2a "test 7: push failed" |
|
233 check_tmpout "1 file pushed" "test 7: wrong push counter (push)" |
|
234 check_tmpout "0 conflicts" "test 7: wrong conflict counter (push)" |
|
235 check_tmpout "0 errors" "test 7: wrong error counter (push)" |
|
236 |
|
237 dav_sync_pull test2b "test 7: pull failed" |
|
238 check_tmpout "1 file pulled" "test 7: wrong pull counter" |
|
239 check_tmpout "1 conflict" "test 7: wrong conflict counter (pull)" |
|
240 check_tmpout "0 errors" "test 7: wrong error counter (pull)" |
|
241 |
|
242 $DAV_SYNC_BIN delete-conflicts test2b > /dev/null 2>&1 |
|
243 if [ $? -ne 0 ]; then |
|
244 echo "test 7: delete-conflicts failed" |
|
245 exit 2 |
|
246 fi |
|
247 |
|
248 dav_sync_push test2b "test 7: push test2b failed" |
|
249 check_tmpout "0 files pushed" "test 7: wrong push counter (test2b)" |
|
250 check_tmpout "0 conflicts" "test 7: wrong conflict counter (test2b)" |
|
251 check_tmpout "0 errors" "test 7: wrong error counter (test2b)" |
|
252 |
|
253 |
|
254 # ---------------------------------------------------------------------------- |
|
255 # test 8: provoke real conflict, push both |
|
256 # expected result: (push): conflict |
|
257 |
|
258 sleep 2 |
|
259 |
|
260 echo "test8-mod-a" >> tmp-sync/test2a/dir1/file2 |
|
261 echo "test8-mod-b" >> tmp-sync/test2b/dir1/file2 |
|
262 |
|
263 dav_sync_push test2a "test 8: push test2a failed" |
|
264 check_tmpout "1 file pushed" "test 8: wrong push counter (test2a)" |
|
265 check_tmpout "0 conflicts" "test 8: wrong conflict counter (test2a)" |
|
266 check_tmpout "0 errors" "test 8: wrong error counter (test2a)" |
|
267 |
|
268 dav_sync_push test2b "test 8: push test2b failed" |
|
269 check_tmpout "0 files pushed" "test 8: wrong push counter (test2b)" |
|
270 check_tmpout "1 conflict" "test 8: wrong conflict counter (test2b)" |
|
271 check_tmpout "0 errors" "test 8: wrong error counter (test2b)" |
|
272 |
|
273 |
|
274 # ---------------------------------------------------------------------------- |
|
275 # test 9: resolve push conflict by manually syncing file2 |
|
276 # expected result: (push): no conflict |
|
277 |
|
278 cp -f tmp-sync/test2a/dir1/file2 tmp-sync/test2b/dir1/file2 |
|
279 |
|
280 dav_sync_push test2b "test 9: push test2b failed" |
|
281 check_tmpout "0 files pushed" "test 9: wrong push counter (test2b)" |
|
282 check_tmpout "0 conflicts" "test 9: wrong conflict counter (test2b)" |
|
283 check_tmpout "0 errors" "test 9: wrong error counter (test2b)" |
|
284 |
|
285 |
|
286 # ---------------------------------------------------------------------------- |
|
287 # test 10: provoke real conflict, push test2a, pull test2b |
|
288 # expected result: (pull): conflict |
|
289 |
|
290 sleep 2 |
|
291 |
|
292 echo "test10-mod-a" >> tmp-sync/test2a/dir1/file2 |
|
293 echo "test10-mod-b" >> tmp-sync/test2b/dir1/file2 |
|
294 |
|
295 dav_sync_push test2a "test 10: push test2a failed" |
|
296 check_tmpout "1 file pushed" "test 10: wrong push counter (test2a)" |
|
297 check_tmpout "0 conflicts" "test 10: wrong conflict counter (test2a)" |
|
298 check_tmpout "0 errors" "test 10: wrong error counter (test2a)" |
|
299 |
|
300 dav_sync_pull test2b "test 10: pull failed" |
|
301 check_tmpout "1 file pulled" "test 10: wrong pull counter (pull)" |
|
302 check_tmpout "1 conflict" "test 10: wrong conflict counter (pull)" |
|
303 check_tmpout "0 errors" "test 10: wrong error counter (pull)" |
|
304 |
|
305 $DAV_SYNC_BIN delete-conflicts test2b > /dev/null 2>&1 |
|
306 if [ $? -ne 0 ]; then |
|
307 echo "test 10: delete-conflicts failed" |
|
308 exit 2 |
|
309 fi |
|
310 |
|
311 dav_sync_push test2b "test 10: push test2b failed" |
|
312 check_tmpout "0 files pushed" "test 10: wrong push counter (test2b)" |
|
313 check_tmpout "0 conflicts" "test 10: wrong conflict counter (test2b)" |
|
314 check_tmpout "0 errors" "test 10: wrong error counter (test2b)" |
|
315 |
|
316 |
|
317 # ---------------------------------------------------------------------------- |
|
318 # test 11: If hashes are equal and 0 files are pulled, check if |
|
319 # the db was updated. Modify a file after pull and push the new file |
|
320 # expected result: (push): no conflict, 1 file pushed |
|
321 |
|
322 sleep 2 |
|
323 |
|
324 echo "test11-mod" >> tmp-sync/test2a/file1 |
|
325 echo "test11-mod" >> tmp-sync/test2b/file1 |
|
326 |
|
327 dav_sync_push test2a "test 11: push test2a failed" |
|
328 check_tmpout "1 file pushed" "test 11: wrong push counter (test2a)" |
|
329 check_tmpout "0 conflicts" "test 11: wrong conflict counter (test2a)" |
|
330 check_tmpout "0 errors" "test 11: wrong error counter (test2a)" |
|
331 |
|
332 dav_sync_pull test2b "test 11: pull failed" |
|
333 check_tmpout "0 files pulled" "test 11: wrong pull counter" |
|
334 check_tmpout "0 conflicts" "test 11: wrong conflict counter (pull)" |
|
335 check_tmpout "0 errors" "test 11: wrong error counter (pull)" |
|
336 |
|
337 sleep 2 |
|
338 echo "test11-mod2-b" >> tmp-sync/test2b/file1 |
|
339 |
|
340 dav_sync_push test2b "test 11: push test2b failed" |
|
341 check_tmpout "1 file pushed" "test 11: wrong push counter (test2b)" |
|
342 check_tmpout "0 conflicts" "test 11: wrong conflict counter (test2b)" |
|
343 check_tmpout "0 errors" "test 11: wrong error counter (test2b)" |
|
344 |
|
345 |
|
346 # ---------------------------------------------------------------------------- |
|
347 # test 12: same as test 11 but with a new file and not an existing file |
|
348 # expected result: (push): no conflict, 1 file pushed |
|
349 |
|
350 echo "test12-new" >> tmp-sync/test2a/new-t12 |
|
351 echo "test12-new" >> tmp-sync/test2b/new-t12 |
|
352 |
|
353 dav_sync_push test2a "test 12: push test2a failed" |
|
354 check_tmpout "1 file pushed" "test 12: wrong push counter (test2a)" |
|
355 check_tmpout "0 conflicts" "test 12: wrong conflict counter (test2a)" |
|
356 check_tmpout "0 errors" "test 12: wrong error counter (test2a)" |
|
357 |
|
358 dav_sync_pull test2b "test 12: pull failed" |
|
359 check_tmpout "0 files pulled" "test 12: wrong pull counter" |
|
360 check_tmpout "0 conflicts" "test 12: wrong conflict counter (pull)" |
|
361 check_tmpout "0 errors" "test 12: wrong error counter (pull)" |
|
362 |
|
363 sleep 2 |
|
364 echo "test12-mod2-b" >> tmp-sync/test2b/new-t12 |
|
365 |
|
366 dav_sync_push test2b "test 12: push test2b failed" |
|
367 check_tmpout "1 file pushed" "test 12: wrong push counter (test2b)" |
|
368 check_tmpout "0 conflicts" "test 12: wrong conflict counter (test2b)" |
|
369 check_tmpout "0 errors" "test 12: wrong error counter (test2b)" |
|
370 |
|
371 # ---------------------------------------------------------------------------- |
|
372 # test 13: Check if push updates the db, if a modified file is already |
|
373 # updated (hashes equal). Modify file the same way on both sides, |
|
374 # push both, modify file in test2b and push again |
|
375 # expected result: (push): no conflict, 1 file pushed |
|
376 |
|
377 echo "test13-mod" >> tmp-sync/test2a/dir1/file2 |
|
378 echo "test13-mod" >> tmp-sync/test2b/dir1/file2 |
|
379 |
|
380 dav_sync_push test2a "test 13: push test2a failed" |
|
381 check_tmpout "1 file pushed" "test 13: wrong push counter (test2a)" |
|
382 check_tmpout "0 conflicts" "test 13: wrong conflict counter (test2a)" |
|
383 check_tmpout "0 errors" "test 13: wrong error counter (test2a)" |
|
384 |
|
385 dav_sync_push test2b "test 13: push test2b failed" |
|
386 check_tmpout "0 files pushed" "test 13: wrong push counter (test2b)" |
|
387 check_tmpout "0 conflicts" "test 13: wrong conflict counter (test2b)" |
|
388 check_tmpout "0 errors" "test 13: wrong error counter (test2b)" |
|
389 |
|
390 sleep 2 |
|
391 echo "test13-mod2-b" >> tmp-sync/test2b/dir1/file2 |
|
392 |
|
393 dav_sync_push test2b "test 13: push test2b (2) failed" |
|
394 check_tmpout "1 file pushed" "test 13: wrong push counter (test2b 2)" |
|
395 check_tmpout "0 conflicts" "test 13: wrong conflict counter (test2b 2)" |
|
396 check_tmpout "0 errors" "test 13: wrong error counter (test2b 2)" |
|
397 |
|
398 |
|
399 # ---------------------------------------------------------------------------- |
|
400 # test 14: same as test 13 but with a new file and not an existing file |
|
401 # expected result: (push): no conflict, 1 file pushed |
|
402 |
|
403 echo "test14-mod" >> tmp-sync/test2a/dir1/new-t14 |
|
404 echo "test14-mod" >> tmp-sync/test2b/dir1/new-t14 |
|
405 |
|
406 dav_sync_push test2a "test 14: push test2a failed" |
|
407 check_tmpout "1 file pushed" "test 14: wrong push counter (test2a)" |
|
408 check_tmpout "0 conflicts" "test 14: wrong conflict counter (test2a)" |
|
409 check_tmpout "0 errors" "test 14: wrong error counter (test2a)" |
|
410 |
|
411 dav_sync_push test2b "test 14: push test2b failed" |
|
412 check_tmpout "0 files pushed" "test 14: wrong push counter (test2b)" |
|
413 check_tmpout "0 conflicts" "test 14: wrong conflict counter (test2b)" |
|
414 check_tmpout "0 errors" "test 14: wrong error counter (test2b)" |
|
415 |
|
416 sleep 2 |
|
417 echo "test13-mod2-b" >> tmp-sync/test2b/dir1/new-t14 |
|
418 |
|
419 dav_sync_push test2b "test 14: push test2b (2) failed" |
|
420 check_tmpout "1 file pushed" "test 14: wrong push counter (test2b 2)" |
|
421 check_tmpout "0 conflicts" "test 14: wrong conflict counter (test2b 2)" |
|
422 check_tmpout "0 errors" "test 14: wrong error counter (test2b 2)" |