|
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 # tmp sync dir |
|
94 rm -Rf tmp-sync |
|
95 mkdir tmp-sync |
|
96 mkdir tmp-sync/test1a |
|
97 mkdir tmp-sync/test1b |
|
98 |
|
99 # prepare |
|
100 cp synctest/file1 tmp-sync/test1a |
|
101 cp synctest/file2 tmp-sync/test1a |
|
102 |
|
103 mkdir tmp-sync/test1a/dir1/ |
|
104 mkdir tmp-sync/test1a/dir1/subdir1/ |
|
105 |
|
106 cp synctest/file1 tmp-sync/test1a/dir1/ |
|
107 cp synctest/file2 tmp-sync/test1a/dir1/ |
|
108 cp synctest/file3 tmp-sync/test1a/dir1/ |
|
109 cp synctest/file4 tmp-sync/test1a/dir1/ |
|
110 |
|
111 cp synctest/file1 tmp-sync/test1a/dir1/subdir1/ |
|
112 cp synctest/file2 tmp-sync/test1a/dir1/subdir1/ |
|
113 cp synctest/file3 tmp-sync/test1a/dir1/subdir1/ |
|
114 cp synctest/file4 tmp-sync/test1a/dir1/subdir1/ |
|
115 cp synctest/empty1 tmp-sync/test1a/dir1/subdir1/ |
|
116 cp synctest/empty2 tmp-sync/test1a/dir1/subdir1/ |
|
117 |
|
118 dav_sync_push test1a "prepare: push failed" |
|
119 dav_sync_pull test1b "prepare: pull failed" |
|
120 sleep 3 |
|
121 |
|
122 # ---------------------------------------------------------------------------- |
|
123 # 1. test: try to push a file, that has changed on the server |
|
124 # expected result: 1 conflict |
|
125 |
|
126 echo "test1-mod" >> tmp-sync/test1a/file1 |
|
127 |
|
128 dav_sync_push test1a "test 1: push test1a failed" |
|
129 check_tmpout "1 file pushed" "test 1: wrong push counter (1)" |
|
130 check_tmpout "0 conflicts" "test 1: wrong conflict counter(1)" |
|
131 check_tmpout "0 errors" "test 1: wrong erro counter(1)" |
|
132 |
|
133 echo "test1-conflict" >> tmp-sync/test1b/file1 |
|
134 |
|
135 dav_sync_push test1b "test 1: push test1b failed" |
|
136 check_tmpout "0 files pushed" "test 1: wrong push counter (2)" |
|
137 check_tmpout "1 conflict" "test 1: wrong conflict counter(2)" |
|
138 check_tmpout "0 errors" "test 1: wrong erro counter(2)" |
|
139 |
|
140 |
|
141 # ---------------------------------------------------------------------------- |
|
142 # 2. test: try again |
|
143 # expected result: 1 conflict |
|
144 |
|
145 dav_sync_push test1b "test 2: push test1b failed" |
|
146 check_tmpout "0 files pushed" "test 2: wrong push counter" |
|
147 check_tmpout "1 conflict" "test 2: wrong conflict counter" |
|
148 check_tmpout "0 errors" "test 2: wrong erro counter" |
|
149 |
|
150 |
|
151 # ---------------------------------------------------------------------------- |
|
152 # 3. test: try again with -c |
|
153 # expected result: 1 file pushed, 0 conflicts |
|
154 |
|
155 $DAV_SYNC_BIN push -c test1b > tmp-sync/out.txt |
|
156 if [ $? -ne 0 ]; |
|
157 then |
|
158 echo "test 1: push test1b failed" |
|
159 exit 2 |
|
160 fi |
|
161 |
|
162 check_tmpout "1 file pushed" "test 3: wrong push counter" |
|
163 check_tmpout "0 conflicts" "test 3: wrong conflict counter" |
|
164 check_tmpout "0 errors" "test 3: wrong erro counter" |
|
165 |
|
166 |
|
167 # ---------------------------------------------------------------------------- |
|
168 # 4. test: get changes in test1a and retry test 1 |
|
169 # expected result: 1 conflict |
|
170 |
|
171 sleep 3 |
|
172 |
|
173 dav_sync_pull test1a "test 4: pull failed" |
|
174 check_tmpout "1 file pulled" "test 4: wrong pull counter" |
|
175 check_tmpout "0 conflicts" "test 4: wrong conflict counter (pull)" |
|
176 check_tmpout "0 errors" "test 4: wrong error counter (pull)" |
|
177 |
|
178 echo "test4-mod" >> tmp-sync/test1a/file1 |
|
179 |
|
180 dav_sync_push test1a "test 4: push test1a failed" |
|
181 check_tmpout "1 file pushed" "test 4: wrong push counter (1)" |
|
182 check_tmpout "0 conflicts" "test 4: wrong conflict counter(1)" |
|
183 check_tmpout "0 errors" "test 4: wrong erro counter(1)" |
|
184 |
|
185 echo "test4-conflict" >> tmp-sync/test1b/file1 |
|
186 |
|
187 dav_sync_push test1b "test 4: push test1b failed" |
|
188 check_tmpout "0 files pushed" "test 4: wrong push counter (2)" |
|
189 check_tmpout "1 conflict" "test 4: wrong conflict counter(2)" |
|
190 check_tmpout "0 errors" "test 4: wrong erro counter(2)" |
|
191 |
|
192 |
|
193 # ---------------------------------------------------------------------------- |
|
194 # 5. test: check if resolve-conflicts can fix push conflicts |
|
195 # expected result: resolve-conflicts only resolves pull conflicts |
|
196 |
|
197 $DAV_SYNC_BIN resolve-conflicts test1b > /dev/null 2>&1 |
|
198 |
|
199 dav_sync_push test1b "test 5: push test1b failed" |
|
200 check_tmpout "0 files pushed" "test 5: wrong push counter" |
|
201 check_tmpout "1 conflict" "test 5: wrong conflict counter" |
|
202 check_tmpout "0 errors" "test 5: wrong erro counter" |
|
203 |
|
204 |
|
205 # ---------------------------------------------------------------------------- |
|
206 # 6. test: pull (with conflict), push |
|
207 # expected result: local conflict file, 0 files pushed |
|
208 |
|
209 sleep 3 |
|
210 |
|
211 dav_sync_pull test1b "test 6: pull failed" |
|
212 check_tmpout "1 conflict" "test 6: wrong conflict counter (pull)" |
|
213 check_tmpout "0 errors" "test 6: wrong error counter (pull)" |
|
214 |
|
215 # check if file1 is a conflict |
|
216 $DAV_SYNC_BIN list-conflicts test1b > tmp-sync/out.txt |
|
217 check_tmpout "/file1" "test 6: list-conflicts doesn't list file1 (1)" |
|
218 |
|
219 dav_sync_push test1b "test 6: push failed" |
|
220 check_tmpout "0 files pushed" "test 6: wrong push counter" |
|
221 check_tmpout "0 conflicts" "test 6: wrong conflict counter (push)" |
|
222 check_tmpout "0 errors" "test 6: wrong error counter (push)" |
|
223 |
|
224 # check if file1 is a conflict (again) |
|
225 $DAV_SYNC_BIN list-conflicts test1b > tmp-sync/out.txt |
|
226 check_tmpout "/file1" "test 6: list-conflicts doesn't list file1 (2)" |
|
227 |
|
228 # ---------------------------------------------------------------------------- |
|
229 # 7. test: push after resolve-conflicts |
|
230 # expected result: removes conflict from orig-file -> 1 file pushed |
|
231 |
|
232 $DAV_SYNC_BIN resolve-conflicts test1b > /dev/null |
|
233 |
|
234 TEST=`$DAV_SYNC_BIN list-conflicts test1b | wc -l` |
|
235 if [ $TEST != "0" ]; then |
|
236 echo "test 7: list-conflicts not empty" |
|
237 exit 2 |
|
238 fi |
|
239 |
|
240 dav_sync_push test1b "test 7: push failed" |
|
241 check_tmpout "1 file pushed" "test 7: wrong push counter" |
|
242 check_tmpout "0 conflicts" "test 7: wrong conflict counter" |
|
243 check_tmpout "0 errors" "test 7: wrong error counter" |
|
244 |
|
245 |
|
246 # ---------------------------------------------------------------------------- |
|
247 # 8. test: pull test1a (actually not a push test, but we need to pull test1a) |
|
248 # expected result: no conflicts |
|
249 |
|
250 dav_sync_pull test1a "test 8: pull failed" |
|
251 check_tmpout "0 conflicts" "test 8: wrong conflict counter" |
|
252 check_tmpout "0 errors" "test 8: wrong error counter" |
|
253 TEST=`cat tmp-sync/out.txt | wc -l` |
|
254 if [ $TEST == "1" ]; then |
|
255 echo "test 8: no files pulled" |
|
256 exit 2 |
|
257 fi |
|
258 |
|
259 |
|
260 # ---------------------------------------------------------------------------- |
|
261 # 9. test: multiple files modified locally and on the server, push |
|
262 # expected result: multiple conflicts |
|
263 |
|
264 # modify 6 files in test1a |
|
265 echo "test9conflict_a" >> tmp-sync/test1a/file1 |
|
266 echo "test9conflict_a" >> tmp-sync/test1a/file2 |
|
267 |
|
268 echo "test9conflict_a" >> tmp-sync/test1a/dir1/file1 |
|
269 echo "test9conflict_a" >> tmp-sync/test1a/dir1/file2 |
|
270 |
|
271 echo "test9conflict_a" >> tmp-sync/test1a/dir1/subdir1/empty1 |
|
272 echo "test9conflict_a" >> tmp-sync/test1a/dir1/subdir1/empty2 |
|
273 |
|
274 dav_sync_push test1a "test 9: push test1a failed" |
|
275 check_tmpout "6 files pushed" "test 9: wrong test1a push counter" |
|
276 check_tmpout "0 conflicts" "test 9: wrong test1a conflict counter" |
|
277 check_tmpout "0 errors" "test 9: wrong test1a error counter" |
|
278 |
|
279 # modify 3 files in test1b, which are also modified in test1a |
|
280 echo "test9conflict_b" >> tmp-sync/test1b/file2 |
|
281 echo "test9conflict_b" >> tmp-sync/test1b/dir1/file2 |
|
282 echo "test9conflict_b" >> tmp-sync/test1b/dir1/subdir1/empty2 |
|
283 |
|
284 dav_sync_push test1b "test 9: push test1a failed" |
|
285 check_tmpout "3 files pushed" "test 9: wrong test1b push counter" |
|
286 check_tmpout "3 conflicts" "test 9: wrong test1b conflict counter" |
|
287 check_tmpout "0 errors" "test 9: wrong test1b error counter" |
|
288 |
|
289 |
|
290 |