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

changeset 632
2e1b59290829
parent 631
93bbeb00385c
child 633
b7de5ecc30fa
equal deleted inserted replaced
631:93bbeb00385c 632:2e1b59290829
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 #
31 # Test dav-sync pull conflict detection
32 # and related commands
33 #
34
35 if [ -z "$DAV_BIN" ];
36 then
37 echo "DAV_BIN variable not set"
38 exit 1
39 fi
40 if [ -z "$DAV_SYNC_BIN" ];
41 then
42 echo "DAV_BIN variable not set"
43 exit 1
44 fi
45
46 # checks if tmp-sync/out.txt contains a specific text
47 # arg1: pattern
48 # arg2: errormsg
49 check_tmpout()
50 {
51 TEST=`cat tmp-sync/out.txt | grep "$1"`
52 if [ $? -ne 0 ];
53 then
54 echo "$2"
55 exit 2
56 fi
57 }
58
59 # do dav-sync push and check return value
60 # arg1: dir
61 # arg2: errormsg
62 dav_sync_push()
63 {
64 $DAV_SYNC_BIN push $1 > tmp-sync/out.txt
65 if [ $? -ne 0 ];
66 then
67 echo "$2"
68 exit 2
69 fi
70 }
71 # do dav-sync pull and check return value
72 # arg1: dir
73 # arg2: errormsg
74 dav_sync_pull()
75 {
76 $DAV_SYNC_BIN pull $1 > tmp-sync/out.txt
77 if [ $? -ne 0 ];
78 then
79 echo "$2"
80 exit 2
81 fi
82 }
83
84 rm -f .dav/dav-sync-tests-test1a-db.xml
85 rm -f .dav/dav-sync-tests-test1b-db.xml
86
87 $DAV_BIN rm dav-test-repo/sync/test1 2> /dev/null
88 $DAV_BIN rm dav-test-repo/sync/test2 2> /dev/null
89
90 $DAV_BIN mkcol dav-test-repo/sync/test1 2> /dev/null
91 $DAV_BIN mkcol dav-test-repo/sync/test2 2> /dev/null
92
93 # prepare
94 cp synctest/file1 tmp-sync/test1a
95 cp synctest/file2 tmp-sync/test1a
96 dav_sync_push test1a "prepare: push failed"
97 dav_sync_pull test1b "prepare: pull failed"
98 sleep 3
99
100 # ----------------------------------------------------------------------------
101 # 1. test: pull, local file also modified
102 # expected result: 1 conflict
103
104 echo "conflict1-test1" >> tmp-sync/test1a/file1
105 dav_sync_push test1a "prepare: push failed"
106 check_tmpout "1 file pushed" "test 1: wrong push counter"
107
108 TEST1B_COUNT1=`ls tmp-sync/test1b/ | wc -l`
109
110 echo "conflict1-test1-conflict" >> tmp-sync/test1b/file1
111 dav_sync_pull test1b "prepare: pull failed"
112 check_tmpout "1 file pulled" "test 1: wrong pull counter"
113 check_tmpout "1 conflict" "test 1: wrong conflict counter"
114 check_tmpout "0 errors" "test 1: wrong error counter"
115
116 TEST1B_COUNT2=`ls tmp-sync/test1b/ | wc -l`
117 # check if the conflict file was moved
118 if [ $TEST1B_COUNT1 = $TEST1B_COUNT2 ]; then
119 echo "test 1: conflict file not renamed"
120 exit 2
121 fi
122
123 # warning: never check if the moved conflict file has a specific
124 # name like "orig.0.file1"
125
126 # ----------------------------------------------------------------------------
127 # 2. test: check list-conflicts command
128 # expected result: "/file1" output
129
130 $DAV_SYNC_BIN list-conflicts test1b > tmp-sync/out.txt
131 if [ $? -ne 0 ]; then
132 echo "test 2: list-conflicts failed"
133 exit 2
134 fi
135 TEST=`cat tmp-sync/out.txt | grep "/file1"`
136 if [ $? -ne 0 ];
137 then
138 echo "test 2: wrong list-conflicts output"
139 exit 2
140 fi
141
142 # ----------------------------------------------------------------------------
143 # 3. test: check delete-conflicts command
144 # expected result: conflict file ("/orig.0.file1") deleted
145
146 # don't check if the conflict file has this specific name
147
148 $DAV_SYNC_BIN delete-conflicts test1b > tmp-sync/out.txt
149 if [ $? -ne 0 ]; then
150 echo "test 3: delete-conflicts failed"
151 exit 2
152 fi
153 TEST=`cat tmp-sync/out.txt | grep "1 conflict file deleted"`
154 if [ $? -ne 0 ];
155 then
156 echo "test 3: wrong delete-conflicts output"
157 exit 2
158 fi
159
160 TEST1B_COUNT3=`ls tmp-sync/test1b/ | wc -l`
161
162 if [ $TEST1B_COUNT1 != $TEST1B_COUNT3 ]; then
163 echo "test 3: file not removed"
164 exit 2
165 fi
166
167 # ----------------------------------------------------------------------------
168 # 4. test: pull after deleted conflicts
169 # expected result: 0 files pulled, 0 conflicts
170
171 dav_sync_pull test1b "test 4: pull failed"
172 check_tmpout "0 files pulled" "test 4: wrong pull counter"
173 check_tmpout "0 conflicts" "test 4: wrong conflict counter"
174 check_tmpout "0 errors" "test 4: wrong error counter"
175
176 # ----------------------------------------------------------------------------
177 # 5. test: pull, local file also modified, delete-conflicts
178 # this test prepares test 6, to test 'push' after 'delete-conflicts'
179 # expected result: 0 files pulled, 0 conflicts
180
181 sleep 3 # make sure mtime changes
182
183 echo "conflict1-test5" >> tmp-sync/test1a/file1
184 dav_sync_push test1a "prepare: push failed"
185 check_tmpout "1 file pushed" "test 1: wrong push counter"
186
187 echo "conflict1-test5-conflict" >> tmp-sync/test1b/file1
188 dav_sync_pull test1b "prepare: pull failed"
189 check_tmpout "1 file pulled" "test 1: wrong pull counter"
190 check_tmpout "1 conflict" "test 1: wrong conflict counter"
191 check_tmpout "0 errors" "test 1: wrong error counter"
192
193 $DAV_SYNC_BIN delete-conflicts test1b > tmp-sync/out.txt
194 if [ $? -ne 0 ]; then
195 echo "test 3: delete-conflicts failed"
196 exit 2
197 fi
198 TEST=`cat tmp-sync/out.txt | grep "1 conflict file deleted"`
199 if [ $? -ne 0 ];
200 then
201 echo "test 3: wrong delete-conflicts output"
202 exit 2
203 fi
204
205
206 # ----------------------------------------------------------------------------
207 # 6. test: push after deleted conflicts
208 # expected result: 0 files pushed, 0 conflicts
209
210 dav_sync_push test1b "test 6: push failed"
211 check_tmpout "0 files pushed" "test 6: wrong push counter"
212 check_tmpout "0 conflicts" "test 6: wrong conflict counter"
213 check_tmpout "0 errors" "test 6: wrong error counter"
214
215
216 # ----------------------------------------------------------------------------
217 # 7. test: resolve-conflicts after pull, followed by push
218 # expected result: pull with 1 conflict, resolve-conflicts removes conflicts
219 # from db (list-conflicts doesn't show conflicts after that)
220
221 sleep 3 # make sure mtime changes
222
223 echo "conflict1-test7" >> tmp-sync/test1a/file1
224 dav_sync_push test1a "prepare: push failed"
225 check_tmpout "1 file pushed" "test 7: wrong push counter"
226
227 echo "conflict1-test7-conflict" >> tmp-sync/test1b/file1
228 dav_sync_pull test1b "prepare: pull failed"
229 check_tmpout "1 file pulled" "test 7: wrong pull counter"
230 check_tmpout "1 conflict" "test 7: wrong conflict counter"
231 check_tmpout "0 errors" "test 7: wrong error counter"
232
233 TEST1B_COUNT_T7_1=`ls tmp-sync/test1b/ | wc -l`
234
235 $DAV_SYNC_BIN resolve-conflicts test1b > tmp-sync/out.txt
236 if [ $? -ne 0 ]; then
237 echo "test 7: resolve-conflicts failed"
238 exit 2
239 fi
240 TEST=`cat tmp-sync/out.txt | grep "1 conflict resolved"`
241 if [ $? -ne 0 ];
242 then
243 echo "test 7: wrong resolve-conflicts output"
244 exit 2
245 fi
246
247 TEST1B_COUNT_T7_2=`ls tmp-sync/test1b/ | wc -l`
248
249 if [ $TEST1B_COUNT_T7_1 != $TEST1B_COUNT_T7_2 ]; then
250 echo "test 7: number of files has changed"
251 exit 2
252 fi
253
254 TEST7=`dav-sync list-conflicts test1b | wc -l`
255 if [ $TEST7 != "0" ]; then
256 echo "test 7: list-conflicts must not show conflicts"
257 return 2
258 fi
259
260 # pull again, should do nothing
261
262 dav_sync_pull test1b "test 7: pull(2) failed"
263 check_tmpout "0 files pulled" "test 7: wrong pull counter (2)"
264 check_tmpout "0 conflicts" "test 7: wrong conflict counter (2)"
265 check_tmpout "0 errors" "test 7: wrong error counter (2)"
266
267 # ----------------------------------------------------------------------------
268 # 8. test: resolve-conflicts after pull, followed by push
269 # expected result: pull with 1 conflict, resolve-conflicts removes conflicts
270 # from db (list-conflicts doesn't show conflicts after that)
271
272 # test mostly the same as test 7
273
274 sleep 3 # make sure mtime changes
275
276 echo "conflict1-test8" >> tmp-sync/test1a/file1
277 dav_sync_push test1a "prepare: push failed"
278 check_tmpout "1 file pushed" "test 8: wrong push counter"
279
280 echo "conflict1-test8-conflict" >> tmp-sync/test1b/file1
281 dav_sync_pull test1b "prepare: pull failed"
282 check_tmpout "1 file pulled" "test 8: wrong pull counter"
283 check_tmpout "1 conflict" "test 8: wrong conflict counter"
284 check_tmpout "0 errors" "test 8: wrong error counter"
285
286 TEST1B_COUNT_T7_1=`ls tmp-sync/test1b/ | wc -l`
287
288 $DAV_SYNC_BIN resolve-conflicts test1b > tmp-sync/out.txt
289 if [ $? -ne 0 ]; then
290 echo "test 8: resolve-conflicts failed"
291 exit 2
292 fi
293 TEST=`cat tmp-sync/out.txt | grep "1 conflict resolved"`
294 if [ $? -ne 0 ];
295 then
296 echo "test 8: wrong resolve-conflicts output"
297 exit 2
298 fi
299
300 TEST1B_COUNT_T7_2=`ls tmp-sync/test1b/ | wc -l`
301
302 if [ $TEST1B_COUNT_T7_1 != $TEST1B_COUNT_T7_2 ]; then
303 echo "test 8: number of files has changed"
304 exit 2
305 fi
306
307 TEST7=`dav-sync list-conflicts test1b | wc -l`
308 if [ $TEST7 != "0" ]; then
309 echo "test 8: list-conflicts must not show conflicts"
310 return 2
311 fi
312
313 # push, 2 resolved conflict files (test 7 and test 8 'orig' file)
314
315 dav_sync_push test1b "test 8: push failed"
316 check_tmpout "2 files pushed" "test 8: wrong push counter"
317 check_tmpout "0 conflicts" "test 8: wrong conflicts counter"
318 check_tmpout "0 errors" "test 8: wrong error counter"
319
320 # push again, shoud do nothing
321 dav_sync_push test1b "test 8: push(2) failed"
322 check_tmpout "0 files pushed" "test 8: wrong push counter (2)"
323 check_tmpout "0 conflicts" "test 8: wrong conflicts counter (2)"
324 check_tmpout "0 errors" "test 8: wrong error counter (2)"
325
326
327 # ----------------------------------------------------------------------------
328 # 9. test: test1a deleted file, test1b modified file
329 # expected result: conflict
330
331 sleep 3 # make sure mtime changes
332
333 rm -f tmp-sync/test1a/file1
334
335 dav_sync_push test1a "test 9: push failed"
336 check_tmpout "1 file deleted" "test 9: wrong delete counter"
337 check_tmpout "0 conflicts" "test 9: wrong conflict counter"
338
339 echo "conflict1-test9-conflict" >> tmp-sync/test1b/file1
340
341 dav_sync_pull test1b "test 9: pull failed"
342 # don't check conflict counter
343 TEST=`cat tmp-sync/out.txt | grep "1 file deleted"`
344 if [ $? -eq 0 ];
345 then
346 echo "test 9: file1 deleted"
347 exit 2
348 fi
349
350 cat tmp-sync/test1b/file1 > /dev/null 2>&1
351 if [ $? -ne 0 ]; then
352 echo "test 9: file1 deleted (2)"
353 exit 2
354 fi
355

mercurial