|
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 XATTR=../../build/xattrtool |
|
42 |
|
43 # checks if tmp-sync/out.txt contains a specific text |
|
44 # arg1: pattern |
|
45 # arg2: errormsg |
|
46 check_tmpout() |
|
47 { |
|
48 TEST=`cat tmp-sync/out.txt | grep "$1"` |
|
49 if [ $? -ne 0 ]; |
|
50 then |
|
51 echo "$2" |
|
52 exit 2 |
|
53 fi |
|
54 } |
|
55 |
|
56 # checks if tmp-sync/out.txt does not contain a specific text |
|
57 # arg1: pattern |
|
58 # arg2: errormsg |
|
59 ncheck_tmpout() |
|
60 { |
|
61 TEST=`cat tmp-sync/out.txt | grep "$1"` |
|
62 if [ $? -eq 0 ]; |
|
63 then |
|
64 echo "$2" |
|
65 exit 2 |
|
66 fi |
|
67 } |
|
68 |
|
69 # do dav-sync push and check return value |
|
70 # arg1: dir |
|
71 # arg2: errormsg |
|
72 dav_sync_push() |
|
73 { |
|
74 $DAV_SYNC_BIN push $1 > tmp-sync/out.txt |
|
75 if [ $? -ne 0 ]; |
|
76 then |
|
77 echo "$2" |
|
78 exit 2 |
|
79 fi |
|
80 } |
|
81 # do dav-sync pull and check return value |
|
82 # arg1: dir |
|
83 # arg2: errormsg |
|
84 dav_sync_pull() |
|
85 { |
|
86 $DAV_SYNC_BIN pull $1 > tmp-sync/out.txt |
|
87 if [ $? -ne 0 ]; |
|
88 then |
|
89 echo "$2" |
|
90 exit 2 |
|
91 fi |
|
92 } |
|
93 |
|
94 rm -f .dav/dav-sync-tests-test5a-db.xml |
|
95 rm -f .dav/dav-sync-tests-test5b-db.xml |
|
96 |
|
97 $DAV_BIN rm dav-test-repo/sync/test5 2> /dev/null |
|
98 |
|
99 $DAV_BIN mkcol dav-test-repo/sync/test5 2> /dev/null |
|
100 |
|
101 # tmp sync dir |
|
102 rm -Rf tmp-sync |
|
103 mkdir tmp-sync |
|
104 mkdir tmp-sync/test5a |
|
105 mkdir tmp-sync/test5b |
|
106 |
|
107 # ---------------------------------------------------------------------------- |
|
108 # test 1: add some files (preparation, make sure everything works) |
|
109 # expected result: everything synced |
|
110 |
|
111 mkdir tmp-sync/test5a/dir1 |
|
112 mkdir tmp-sync/test5a/dir1/sub1 |
|
113 |
|
114 cp synctest/file1 tmp-sync/test5a |
|
115 cp synctest/file2 tmp-sync/test5a/dir1 |
|
116 cp synctest/file3 tmp-sync/test5a/dir1/sub1 |
|
117 |
|
118 dav_sync_push test5a "test 1: push failed" |
|
119 check_tmpout "3 files pushed" "test 1: wrong push counter" |
|
120 check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)" |
|
121 check_tmpout "0 errors" "test 1: wrong error counter (push)" |
|
122 |
|
123 dav_sync_pull test5b "test 1: pull failed" |
|
124 check_tmpout "3 files pulled" "test 1: wrong pull counter" |
|
125 check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)" |
|
126 check_tmpout "0 errors" "test 1: wrong error counter (pull)" |
|
127 |
|
128 |
|
129 # ---------------------------------------------------------------------------- |
|
130 # test 2: modify file, sync |
|
131 # expected result: old resource moved to history collection |
|
132 |
|
133 echo "test2-mod1" >> tmp-sync/test5a/file1 |
|
134 touch -t 01011200 tmp-sync/test5a/file1 |
|
135 |
|
136 dav_sync_push test5a "test 2: push failed" |
|
137 check_tmpout "1 file pushed" "test 2: wrong push counter" |
|
138 check_tmpout "0 conflicts" "test 2: wrong conflict counter (push)" |
|
139 check_tmpout "0 errors" "test 2: wrong error counter (push)" |
|
140 |
|
141 dav_sync_pull test5b "test 2: pull failed" |
|
142 check_tmpout "1 file pulled" "test 2: wrong pull counter" |
|
143 check_tmpout "0 conflicts" "test 2: wrong conflict counter (pull)" |
|
144 check_tmpout "0 errors" "test 2: wrong error counter (pull)" |
|
145 |
|
146 dav list -R dav-test-repo/sync/test5/.dav-version-history/ > tmp-sync/out.txt 2> /dev/null |
|
147 if [ $? -ne 0 ]; then |
|
148 echo "test 2: dav list failed" |
|
149 exit 2 |
|
150 fi |
|
151 |
|
152 TEST=`cat tmp-sync/out.txt | wc -l 2> /dev/null` |
|
153 if [ -z "$TEST" ]; then |
|
154 echo "test 2: wc failed" |
|
155 exit 2 |
|
156 fi |
|
157 |
|
158 # line count is 1 (sub-history-collection) + 1 file version = 2 |
|
159 if [ $TEST -ne 2 ]; then |
|
160 echo "test 2: wrong line count" |
|
161 exit 2 |
|
162 fi |
|
163 |
|
164 |
|
165 # ---------------------------------------------------------------------------- |
|
166 # test 3: modify file again, sync |
|
167 # expected result: old resource moved to history collection, 2 old versions |
|
168 |
|
169 echo "test3-mod1" >> tmp-sync/test5a/file1 |
|
170 touch -t 02011200 tmp-sync/test5a/file1 |
|
171 |
|
172 dav_sync_push test5a "test 3: push failed" |
|
173 check_tmpout "1 file pushed" "test 3: wrong push counter" |
|
174 check_tmpout "0 conflicts" "test 3: wrong conflict counter (push)" |
|
175 check_tmpout "0 errors" "test 3: wrong error counter (push)" |
|
176 |
|
177 dav_sync_pull test5b "test 3: pull failed" |
|
178 check_tmpout "1 file pulled" "test 3: wrong pull counter" |
|
179 check_tmpout "0 conflicts" "test 3: wrong conflict counter (pull)" |
|
180 check_tmpout "0 errors" "test 3: wrong error counter (pull)" |
|
181 |
|
182 dav list -R dav-test-repo/sync/test5/.dav-version-history/ > tmp-sync/out.txt 2> /dev/null |
|
183 TEST=`cat tmp-sync/out.txt | wc -l 2> /dev/null` |
|
184 if [ $TEST -ne 3 ]; then |
|
185 echo "test 3: wrong line count" |
|
186 exit 2 |
|
187 fi |
|
188 |
|
189 |
|
190 # ---------------------------------------------------------------------------- |
|
191 # test 4: modify file2, add new file, sync |
|
192 # expected result: file2 versionized, new file just uploaded |
|
193 |
|
194 echo "test4-new1" > tmp-sync/test5a/new1 |
|
195 echo "test4-mod1" >> tmp-sync/test5a/dir1/file2 |
|
196 |
|
197 dav_sync_push test5a "test 4: push failed" |
|
198 check_tmpout "2 files pushed" "test 4: wrong push counter" |
|
199 check_tmpout "0 conflicts" "test 4: wrong conflict counter (push)" |
|
200 check_tmpout "0 errors" "test 4: wrong error counter (push)" |
|
201 |
|
202 dav_sync_pull test5b "test 4: pull failed" |
|
203 check_tmpout "2 files pulled" "test 4: wrong pull counter" |
|
204 check_tmpout "0 conflicts" "test 4: wrong conflict counter (pull)" |
|
205 check_tmpout "0 errors" "test 4: wrong error counter (pull)" |
|
206 |
|
207 dav list -R dav-test-repo/sync/test5/.dav-version-history/ > tmp-sync/out.txt 2> /dev/null |
|
208 TEST=`cat tmp-sync/out.txt | wc -l 2> /dev/null` |
|
209 |
|
210 # line count is 3 (prev) + 1 new sub-history-collection + 1 file version = 5 |
|
211 if [ $TEST -ne 5 ]; then |
|
212 echo "test 4: wrong line count" |
|
213 exit 2 |
|
214 fi |
|
215 |
|
216 |
|
217 # ---------------------------------------------------------------------------- |
|
218 # test 5: restore previous file2 version |
|
219 # expected result: file restored |
|
220 |
|
221 VERSION=`$DAV_SYNC_BIN list-versions tmp-sync/test5a/dir1/file2 | grep "name: " 2> /dev/null` |
|
222 if [ $? -ne 0 ]; then |
|
223 echo "test 5: list-versions failed" |
|
224 exit 2 |
|
225 fi |
|
226 |
|
227 # extract version name |
|
228 VERSION=${VERSION:5} |
|
229 |
|
230 $DAV_SYNC_BIN restore -V $VERSION tmp-sync/test5a/dir1/file2 > tmp-sync/out.txt 2> /dev/null |
|
231 if [ $? -ne 0 ]; then |
|
232 echo "test 5: restore failed" |
|
233 exit 2 |
|
234 fi |
|
235 check_tmpout "1 file pulled" "test 5: wrong pull counter" |
|
236 |
|
237 # compare restored file with base file |
|
238 diff synctest/file2 tmp-sync/test5a/dir1/file2 > /dev/null 2>&1 |
|
239 |
|
240 if [ $? -ne 0 ]; then |
|
241 echo "test 5: wrong file2 content" |
|
242 exit 2 |
|
243 fi |
|
244 |
|
245 |
|
246 # ---------------------------------------------------------------------------- |
|
247 # test 6: push test5a |
|
248 # expected result: file2 pushed |
|
249 |
|
250 dav_sync_push test5a "test 6: push failed" |
|
251 check_tmpout "1 file pushed" "test 6: wrong push counter" |
|
252 check_tmpout "file2" "test 6: file2 not pushed" |
|
253 check_tmpout "0 conflicts" "test 6: wrong conflict counter (push)" |
|
254 check_tmpout "0 errors" "test 6: wrong error counter (push)" |
|
255 |
|
256 dav_sync_pull test5b "test 6: pull failed" |
|
257 check_tmpout "1 file pulled" "test 6: wrong pull counter" |
|
258 check_tmpout "0 conflicts" "test 6: wrong conflict counter (pull)" |
|
259 check_tmpout "0 errors" "test 6: wrong error counter (pull)" |
|
260 |
|
261 |
|
262 # ---------------------------------------------------------------------------- |
|
263 # test 7: modify file2 again and push (this is just a prep for test8) |
|
264 # expected result: file2 pushed |
|
265 |
|
266 sleep 2 |
|
267 |
|
268 echo "test7-mod1" >> tmp-sync/test5a/dir1/file2 |
|
269 |
|
270 dav_sync_push test5a "test 7: push failed" |
|
271 check_tmpout "1 file pushed" "test 7: wrong push counter" |
|
272 check_tmpout "0 conflicts" "test 7: wrong conflict counter (push)" |
|
273 check_tmpout "0 errors" "test 7: wrong error counter (push)" |
|
274 |
|
275 dav_sync_pull test5b "test 7: pull failed" |
|
276 check_tmpout "1 file pulled" "test 7: wrong pull counter" |
|
277 check_tmpout "0 conflicts" "test 7: wrong conflict counter (pull)" |
|
278 check_tmpout "0 errors" "test 7: wrong error counter (pull)" |
|
279 |
|
280 |
|
281 # ---------------------------------------------------------------------------- |
|
282 # test 8: restore previous file2 version and pull |
|
283 # expected result: file restored, no files pulled |
|
284 |
|
285 $DAV_SYNC_BIN restore -V $VERSION tmp-sync/test5a/dir1/file2 > tmp-sync/out.txt 2> /dev/null |
|
286 if [ $? -ne 0 ]; then |
|
287 echo "test 8: restore failed" |
|
288 exit 2 |
|
289 fi |
|
290 check_tmpout "1 file pulled" "test 8: wrong pull counter (restore)" |
|
291 |
|
292 # compare restored file with base file |
|
293 diff synctest/file2 tmp-sync/test5a/dir1/file2 > /dev/null 2>&1 |
|
294 |
|
295 if [ $? -ne 0 ]; then |
|
296 echo "test 8: wrong file2 content" |
|
297 exit 2 |
|
298 fi |
|
299 |
|
300 dav_sync_pull test5a "test 8: pull failed" |
|
301 check_tmpout "0 files pulled" "test 8: wrong pull counter" |
|
302 check_tmpout "0 conflicts" "test 8: wrong conflict counter (pull)" |
|
303 check_tmpout "0 errors" "test 8: wrong error counter (pull)" |
|
304 |