|
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-test4akl-db.xml |
|
95 rm -f .dav/dav-sync-tests-test4bkr-db.xml |
|
96 |
|
97 $DAV_BIN rm dav-test-repo/sync/test4 2> /dev/null |
|
98 |
|
99 $DAV_BIN mkcol dav-test-repo/sync/test4 2> /dev/null |
|
100 |
|
101 # tmp sync dir |
|
102 rm -Rf tmp-sync |
|
103 mkdir tmp-sync |
|
104 mkdir tmp-sync/test4akl |
|
105 mkdir tmp-sync/test4bkr |
|
106 |
|
107 # ---------------------------------------------------------------------------- |
|
108 # test 1: add some files with tags and sync |
|
109 # expected result: everything synced |
|
110 |
|
111 cp synctest/file1 tmp-sync/test4akl/ |
|
112 cp synctest/file2 tmp-sync/test4akl/ |
|
113 cp synctest/file3 tmp-sync/test4akl/ |
|
114 |
|
115 $DAV_SYNC_BIN add-tag -s test4akl tmp-sync/test4akl/file1 mytag1 |
|
116 $DAV_SYNC_BIN add-tag -s test4akl tmp-sync/test4akl/file2 mytag1 |
|
117 $DAV_SYNC_BIN add-tag -s test4akl tmp-sync/test4akl/file3 mytag1 |
|
118 |
|
119 $DAV_SYNC_BIN add-tag -s test4akl tmp-sync/test4akl/file1 tt1 |
|
120 $DAV_SYNC_BIN add-tag -s test4akl tmp-sync/test4akl/file2 tt1 |
|
121 $DAV_SYNC_BIN add-tag -s test4akl tmp-sync/test4akl/file3 tt1 |
|
122 |
|
123 dav_sync_push test4akl "test 1: push failed" |
|
124 check_tmpout "3 files pushed" "test 1: wrong push counter" |
|
125 check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)" |
|
126 check_tmpout "0 errors" "test 1: wrong error counter (push)" |
|
127 |
|
128 dav_sync_pull test4bkr "test 1: pull failed" |
|
129 check_tmpout "3 files pulled" "test 1: wrong pull counter" |
|
130 check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)" |
|
131 check_tmpout "0 errors" "test 1: wrong error counter (pull)" |
|
132 |
|
133 TAGS=`$DAV_SYNC_BIN list-tags -s test4bkr tmp-sync/test4bkr/file1 > tmp-sync/out.txt 2> /dev/null` |
|
134 if [ $? -ne 0 ]; then |
|
135 echo "test 1: list-tags failed (file1)" |
|
136 exit 2 |
|
137 fi |
|
138 check_tmpout "mytag1" "test 1: file1: missing tag mytag1" |
|
139 check_tmpout "tt1" "test 1: file1: missing tag tt1" |
|
140 |
|
141 TAGS=`$DAV_SYNC_BIN list-tags -s test4bkr tmp-sync/test4bkr/file2 > tmp-sync/out.txt 2> /dev/null` |
|
142 if [ $? -ne 0 ]; then |
|
143 echo "test 1: list-tags failed (file2)" |
|
144 exit 2 |
|
145 fi |
|
146 check_tmpout "mytag1" "test 1: file2: missing tag mytag1" |
|
147 check_tmpout "tt1" "test 1: file2: missing tag tt1" |
|
148 |
|
149 TAGS=`$DAV_SYNC_BIN list-tags -s test4bkr tmp-sync/test4bkr/file3 > tmp-sync/out.txt 2> /dev/null` |
|
150 if [ $? -ne 0 ]; then |
|
151 echo "test 1: list-tags failed (file3)" |
|
152 exit 2 |
|
153 fi |
|
154 check_tmpout "mytag1" "test 1: file3: missing tag mytag1" |
|
155 check_tmpout "tt1" "test 1: file3: missing tag tt1" |
|
156 |
|
157 |
|
158 # ---------------------------------------------------------------------------- |
|
159 # test 2: modify tags on both sides and push b, push a, pull b |
|
160 # expected result: tags from a used |
|
161 |
|
162 # changes in test4kl |
|
163 $DAV_SYNC_BIN remove-tag -s test4akl tmp-sync/test4akl/file1 mytag1 |
|
164 $DAV_SYNC_BIN set-tags -s test4akl tmp-sync/test4akl/file2 tt2a |
|
165 $DAV_SYNC_BIN add-tag -s test4akl tmp-sync/test4akl/file3 mytag2 |
|
166 |
|
167 # changes in test4bkr |
|
168 $DAV_SYNC_BIN add-tag -s test4bkr tmp-sync/test4bkr/file1 tt2b |
|
169 $DAV_SYNC_BIN set-tags -s test4bkr tmp-sync/test4bkr/file2 tt2b |
|
170 $DAV_SYNC_BIN remove-tag -s test4bkr tmp-sync/test4bkr/file3 mytag1 |
|
171 |
|
172 dav_sync_push test4bkr "test 2: push b failed" |
|
173 check_tmpout "0 conflicts" "test 2: wrong conflict counter (push b)" |
|
174 check_tmpout "0 errors" "test 2: wrong error counter (push b)" |
|
175 |
|
176 dav_sync_push test4akl "test 2: push failed" |
|
177 check_tmpout "0 conflicts" "test 2: wrong conflict counter (push)" |
|
178 check_tmpout "0 errors" "test 2: wrong error counter (push)" |
|
179 |
|
180 dav_sync_pull test4bkr "test 2: pull failed" |
|
181 check_tmpout "0 conflicts" "test 2: wrong conflict counter (pull)" |
|
182 check_tmpout "0 errors" "test 2: wrong error counter (pull)" |
|
183 |
|
184 TAGS=`$DAV_SYNC_BIN list-tags -s test4bkr tmp-sync/test4bkr/file1 > tmp-sync/out.txt 2> /dev/null` |
|
185 if [ $? -ne 0 ]; then |
|
186 echo "test 1: list-tags failed (file1)" |
|
187 exit 2 |
|
188 fi |
|
189 ncheck_tmpout "mytag1" "test 2: file1: tag mytag1" |
|
190 check_tmpout "tt1" "test 2: file1: tag tt1" |
|
191 ncheck_tmpout "tt2" "test 2: file1: tag tt2" |
|
192 |
|
193 TAGS=`$DAV_SYNC_BIN list-tags -s test4bkr tmp-sync/test4bkr/file2 > tmp-sync/out.txt 2> /dev/null` |
|
194 if [ $? -ne 0 ]; then |
|
195 echo "test 2: list-tags failed (file2)" |
|
196 exit 2 |
|
197 fi |
|
198 check_tmpout "tt2a" "test 2: file2: tt2a" |
|
199 ncheck_tmpout "tt2b" "test 2: file2: tt2b" |
|
200 |
|
201 TAGS=`$DAV_SYNC_BIN list-tags -s test4bkr tmp-sync/test4bkr/file3 > tmp-sync/out.txt 2> /dev/null` |
|
202 if [ $? -ne 0 ]; then |
|
203 echo "test 2: list-tags failed (file3)" |
|
204 exit 2 |
|
205 fi |
|
206 check_tmpout "mytag1" "test 3: file3: tag mytag1" |
|
207 check_tmpout "tt1" "test 3: file3: tag tt1" |
|
208 check_tmpout "mytag2" "test 3: file3: tag mytag2" |
|
209 |
|
210 |
|
211 # ---------------------------------------------------------------------------- |
|
212 # test 3: modify tags on both sides and push a, push b, pull a |
|
213 # expected result: tags from a used |
|
214 |
|
215 # changes in test4kl |
|
216 $DAV_SYNC_BIN add-tag -s test4akl tmp-sync/test4akl/file1 mytag3 |
|
217 $DAV_SYNC_BIN set-tags -s test4akl tmp-sync/test4akl/file2 tt3a |
|
218 $DAV_SYNC_BIN remove-tag -s test4akl tmp-sync/test4akl/file3 mytag2 |
|
219 |
|
220 # changes in test4bkr |
|
221 $DAV_SYNC_BIN remove-tag -s test4bkr tmp-sync/test4bkr/file1 tt1 |
|
222 $DAV_SYNC_BIN set-tags -s test4bkr tmp-sync/test4bkr/file2 tt3b |
|
223 $DAV_SYNC_BIN add-tag -s test4bkr tmp-sync/test4bkr/file3 mytag3 |
|
224 |
|
225 dav_sync_push test4akl "test 3: push a failed" |
|
226 check_tmpout "0 conflicts" "test 3: wrong conflict counter (push a)" |
|
227 check_tmpout "0 errors" "test 3: wrong error counter (push a)" |
|
228 |
|
229 dav_sync_push test4bkr "test 3: push failed" |
|
230 check_tmpout "0 conflicts" "test 3: wrong conflict counter (push)" |
|
231 check_tmpout "0 errors" "test 3: wrong error counter (push)" |
|
232 |
|
233 dav_sync_pull test4akl "test 3: pull failed" |
|
234 check_tmpout "0 conflicts" "test 3: wrong conflict counter (pull)" |
|
235 check_tmpout "0 errors" "test 3: wrong error counter (pull)" |
|
236 |
|
237 TAGS=`$DAV_SYNC_BIN list-tags -s test4akl tmp-sync/test4akl/file1 > tmp-sync/out.txt 2> /dev/null` |
|
238 if [ $? -ne 0 ]; then |
|
239 echo "test 3: list-tags failed (file1)" |
|
240 exit 2 |
|
241 fi |
|
242 check_tmpout "mytag3" "test 3: file1: tag mytag3" |
|
243 check_tmpout "tt1" "test 3: file1: tag tt1" |
|
244 |
|
245 TAGS=`$DAV_SYNC_BIN list-tags -s test4akl tmp-sync/test4akl/file2 > tmp-sync/out.txt 2> /dev/null` |
|
246 if [ $? -ne 0 ]; then |
|
247 echo "test 3: list-tags failed (file2)" |
|
248 exit 2 |
|
249 fi |
|
250 check_tmpout "tt3a" "test 2: file2: tt3a" |
|
251 ncheck_tmpout "tt3b" "test 2: file2: tt3b" |
|
252 |
|
253 TAGS=`$DAV_SYNC_BIN list-tags -s test4akl tmp-sync/test4akl/file3 > tmp-sync/out.txt 2> /dev/null` |
|
254 if [ $? -ne 0 ]; then |
|
255 echo "test 3: list-tags failed (file3)" |
|
256 exit 2 |
|
257 fi |
|
258 check_tmpout "mytag1" "test 3: file3: tag mytag1" |
|
259 check_tmpout "tt1" "test 3: file3: tag tt1" |
|
260 ncheck_tmpout "mytag2" "test 3: file3: tag mytag2" |
|
261 ncheck_tmpout "mytag2" "test 3: file3: tag mytag3" |
|
262 |