|
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-test7a-db.xml |
|
95 rm -f .dav/dav-sync-tests-test7b-db.xml |
|
96 |
|
97 $DAV_BIN rm dav-test-repo/sync/test7 2> /dev/null |
|
98 |
|
99 $DAV_BIN mkcol dav-test-repo/sync/test7 2> /dev/null |
|
100 |
|
101 # tmp sync dir |
|
102 rm -Rf tmp-sync |
|
103 mkdir tmp-sync |
|
104 mkdir tmp-sync/test7a |
|
105 mkdir tmp-sync/test7b |
|
106 |
|
107 # ---------------------------------------------------------------------------- |
|
108 # test 1: try to sync symlinks with symlinks disabled (test7a1) |
|
109 # expected result: only normal files synced |
|
110 |
|
111 mkdir tmp-sync/files |
|
112 mkdir tmp-sync/test7a/dir1 |
|
113 mkdir tmp-sync/test7a/dir1/sub1 |
|
114 |
|
115 echo "extern-file1" > tmp-sync/extern1 |
|
116 echo "extern-file2" > tmp-sync/files/extern2 |
|
117 echo "extern-file3" > tmp-sync/files/extern3 |
|
118 |
|
119 which ln > /dev/null 2>&1 |
|
120 if [ $? -ne 0 ]; then |
|
121 exit 0 # symlinks unsupported on this platform |
|
122 fi |
|
123 |
|
124 ln -s -r tmp-sync/extern1 tmp-sync/test7a/extern1 > /dev/null 2>&1 |
|
125 if [ $? -ne 0 ]; then |
|
126 exit 0 # symlinks unsupported on this platform |
|
127 fi |
|
128 |
|
129 ln -s -r tmp-sync/files/extern2 tmp-sync/test7a/extern2 |
|
130 ln -s -r tmp-sync/files/extern3 tmp-sync/test7a/dir1/sub1/extern3 |
|
131 |
|
132 cp synctest/file1 tmp-sync/test7a |
|
133 cp synctest/file2 tmp-sync/test7a/dir1 |
|
134 cp synctest/file3 tmp-sync/test7a/dir1/sub1 |
|
135 |
|
136 ln -s -r tmp-sync/test7a/file1 tmp-sync/test7a/intern1 |
|
137 ln -s -r tmp-sync/test7a/dir1/file2 tmp-sync/test7a/intern2 |
|
138 ln -s -r tmp-sync/test7a/file1 tmp-sync/test7a/dir1/sub1/intern3 |
|
139 |
|
140 dav_sync_push test7a1 "test 1: push failed" |
|
141 check_tmpout "3 files pushed" "test 1: wrong push counter" |
|
142 check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)" |
|
143 check_tmpout "0 errors" "test 1: wrong error counter (push)" |
|
144 ncheck_tmpout "extern" "test 1: external symlinks pushed" |
|
145 ncheck_tmpout "intern" "test 1: internal symlinks pushed" |
|
146 |
|
147 dav_sync_pull test7b "test 1: pull failed" |
|
148 check_tmpout "3 files pulled" "test 1: wrong pull counter" |
|
149 check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)" |
|
150 check_tmpout "0 errors" "test 1: wrong error counter (pull)" |
|
151 |
|
152 |
|
153 # ---------------------------------------------------------------------------- |
|
154 # test 2: try to sync internal symlinks (test7a2) |
|
155 # expected result: internal symlinks synced, external symlinks ignored |
|
156 |
|
157 dav_sync_push test7a2 "test 2: push failed" |
|
158 check_tmpout "3 files pushed" "test 2: wrong push counter" |
|
159 check_tmpout "0 conflicts" "test 2: wrong conflict counter (push)" |
|
160 check_tmpout "0 errors" "test 2: wrong error counter (push)" |
|
161 check_tmpout "link: /intern1" "test 2: no links created (push)" |
|
162 ncheck_tmpout "extern" "test 2: external symlinks pushed" |
|
163 |
|
164 dav_sync_pull test7b "test 2: pull failed" |
|
165 check_tmpout "3 files pulled" "test 2: wrong pull counter" |
|
166 check_tmpout "0 conflicts" "test 2: wrong conflict counter (pull)" |
|
167 check_tmpout "0 errors" "test 2: wrong error counter (pull)" |
|
168 check_tmpout "link: /intern1" "test 2: no links created (pull)" |
|
169 |
|
170 # compare links |
|
171 HASH_A=`cat tmp-sync/test7a/intern1 | sha256sum` |
|
172 HASH_B=`cat tmp-sync/test7b/intern1 | sha256sum` |
|
173 if [ "$HASH_A" != "$HASH_B" ]; then |
|
174 echo "test 2: intern1 has wrong content" |
|
175 exit 2 |
|
176 fi |
|
177 HASH_A=`cat tmp-sync/test7a/intern2 | sha256sum` |
|
178 HASH_B=`cat tmp-sync/test7b/intern2 | sha256sum` |
|
179 if [ "$HASH_A" != "$HASH_B" ]; then |
|
180 echo "test 2: intern2 has wrong content" |
|
181 exit 2 |
|
182 fi |
|
183 HASH_A=`cat tmp-sync/test7a/dir1/sub1/intern3 | sha256sum` |
|
184 HASH_B=`cat tmp-sync/test7b/dir1/sub1/intern3 | sha256sum` |
|
185 if [ "$HASH_A" != "$HASH_B" ]; then |
|
186 echo "test 2: intern3 has wrong content" |
|
187 exit 2 |
|
188 fi |
|
189 |
|
190 |
|
191 # ---------------------------------------------------------------------------- |
|
192 # test 3: push with symlink-extern follow (test7a) |
|
193 # expected result: external links pushed as regular files |
|
194 |
|
195 dav_sync_push test7a "test 3: push failed" |
|
196 check_tmpout "3 files pushed" "test 3: wrong push counter" |
|
197 check_tmpout "0 conflicts" "test 3: wrong conflict counter (push)" |
|
198 check_tmpout "0 errors" "test 3: wrong error counter (push)" |
|
199 check_tmpout "extern" "test 3: no links created (push)" |
|
200 |
|
201 dav_sync_pull test7b "test 3: pull failed" |
|
202 check_tmpout "3 files pulled" "test 3: wrong pull counter" |
|
203 check_tmpout "0 conflicts" "test 3: wrong conflict counter (pull)" |
|
204 check_tmpout "0 errors" "test 3: wrong error counter (pull)" |
|
205 |
|
206 |
|
207 # ---------------------------------------------------------------------------- |
|
208 # test 4: push, add new file, push (test if double sync happens) |
|
209 # expected result: push1: 0 files pushed, push2: 1 file pushed |
|
210 |
|
211 dav_sync_push test7a "test 4: push failed" |
|
212 check_tmpout "0 files pushed" "test 4: wrong push counter" |
|
213 check_tmpout "0 conflicts" "test 4: wrong conflict counter (push)" |
|
214 check_tmpout "0 errors" "test 4: wrong error counter (push)" |
|
215 |
|
216 echo "test3-new1" > tmp-sync/test7a/new1 |
|
217 |
|
218 dav_sync_push test7a "test 4: push 2 failed" |
|
219 check_tmpout "1 file pushed" "test 4: wrong push counter (2)" |
|
220 check_tmpout "0 conflicts" "test 4: wrong conflict counter (2)" |
|
221 check_tmpout "0 errors" "test 4: wrong error counter (2)" |
|
222 |
|
223 dav_sync_pull test7b "test 4: pull failed" |
|
224 check_tmpout "1 file pulled" "test 4: wrong pull counter" |
|
225 check_tmpout "0 conflicts" "test 4: wrong conflict counter (pull)" |
|
226 check_tmpout "0 errors" "test 4: wrong error counter (pull)" |
|
227 |
|
228 |
|
229 # ---------------------------------------------------------------------------- |
|
230 # test 5: modify file1, sync |
|
231 # expected result: file1 synced, intern1 not synced |
|
232 |
|
233 sleep 2 |
|
234 |
|
235 echo "test5-mod1" >> tmp-sync/test7a/file1 |
|
236 |
|
237 dav_sync_push test7a "test 5: push failed" |
|
238 check_tmpout "1 file pushed" "test 5: wrong push counter" |
|
239 check_tmpout "0 conflicts" "test 5: wrong conflict counter (push)" |
|
240 check_tmpout "0 errors" "test 5: wrong error counter (push)" |
|
241 ncheck_tmpout "intern1" "test 5: intern1 updated (push)" |
|
242 |
|
243 dav_sync_pull test7b "test 5: pull failed" |
|
244 check_tmpout "1 file pulled" "test 5: wrong pull counter" |
|
245 check_tmpout "0 conflicts" "test 5: wrong conflict counter (pull)" |
|
246 check_tmpout "0 errors" "test 5: wrong error counter (pull)" |
|
247 |
|
248 |
|
249 # ---------------------------------------------------------------------------- |
|
250 # test 6: change intern1 target |
|
251 # expected result: intern1 updated |
|
252 |
|
253 rm -f tmp-sync/test7a/intern1 |
|
254 ln -s -r tmp-sync/test7a/new1 tmp-sync/test7a/intern1 |
|
255 |
|
256 dav_sync_push test7a "test 6: push failed" |
|
257 check_tmpout "1 file pushed" "test 6: wrong push counter" |
|
258 check_tmpout "0 conflicts" "test 6: wrong conflict counter (push)" |
|
259 check_tmpout "0 errors" "test 6: wrong error counter (push)" |
|
260 check_tmpout "intern1" "test 6: intern1 not updated (push)" |
|
261 |
|
262 dav_sync_pull test7b "test 6: pull failed" |
|
263 check_tmpout "1 file pulled" "test 6: wrong pull counter" |
|
264 check_tmpout "0 conflicts" "test 6: wrong conflict counter (pull)" |
|
265 check_tmpout "0 errors" "test 6: wrong error counter (pull)" |
|
266 check_tmpout "intern1" "test 6: intern1 not updated (pull)" |
|
267 |