|
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 # checks if tmp-sync/out.txt contains a specific text |
|
42 # arg1: pattern |
|
43 # arg2: errormsg |
|
44 check_tmpout() |
|
45 { |
|
46 TEST=`cat tmp-sync/out.txt | grep "$1"` |
|
47 if [ $? -ne 0 ]; |
|
48 then |
|
49 echo "$2" |
|
50 exit 2 |
|
51 fi |
|
52 } |
|
53 |
|
54 # do dav-sync push and check return value |
|
55 # arg1: dir |
|
56 # arg2: errormsg |
|
57 dav_sync_push() |
|
58 { |
|
59 $DAV_SYNC_BIN push $1 > tmp-sync/out.txt |
|
60 if [ $? -ne 0 ]; |
|
61 then |
|
62 echo "$2" |
|
63 exit 2 |
|
64 fi |
|
65 } |
|
66 # do dav-sync pull and check return value |
|
67 # arg1: dir |
|
68 # arg2: errormsg |
|
69 dav_sync_pull() |
|
70 { |
|
71 $DAV_SYNC_BIN pull $1 > tmp-sync/out.txt |
|
72 if [ $? -ne 0 ]; |
|
73 then |
|
74 echo "$2" |
|
75 exit 2 |
|
76 fi |
|
77 } |
|
78 |
|
79 $DAV_BIN mkcol dav-test-repo/sync/test1 2> /dev/null |
|
80 $DAV_BIN mkcol dav-test-repo/sync/test2 2> /dev/null |
|
81 |
|
82 # ---------------------------------------------------------------------------- |
|
83 # 1. test: pull empty collection |
|
84 # expected result: 0 files pulled, 0 errors |
|
85 dav_sync_pull test1b "test1: pull failed" |
|
86 |
|
87 check_tmpout "0 files pulled" "pull1: wrong pull counter" |
|
88 check_tmpout "0 errors" "pull1: wrong error counter" |
|
89 check_tmpout "0 conflicts" "pull1: wrong conflicts counter" |
|
90 |
|
91 # ---------------------------------------------------------------------------- |
|
92 # 2. test: add 2 files to test1a and push it and pull test1b |
|
93 # expected result: 2 files pushed, 2 files pulled |
|
94 |
|
95 rm -f .dav/dav-sync-tests-test1a-db.xml |
|
96 |
|
97 cp synctest/file1 tmp-sync/test1a |
|
98 cp synctest/file2 tmp-sync/test1a |
|
99 |
|
100 dav_sync_push test1a "test2: push failed" |
|
101 check_tmpout "2 files pushed" "test2: wrong push counter" |
|
102 |
|
103 dav_sync_pull test1b "test2: pull failed" |
|
104 check_tmpout "2 files pulled" "test2: wrong pull counter" |
|
105 check_tmpout "0 errors" "test2: wrong error counter" |
|
106 check_tmpout "0 conflicts" "test2: wrong conflicts counter" |
|
107 |
|
108 # ---------------------------------------------------------------------------- |
|
109 # 3. test: pull empty directory |
|
110 # expected result: empty directory created |
|
111 |
|
112 mkdir tmp-sync/test1a/emptydir |
|
113 dav_sync_push test1a "test3: push failed" |
|
114 check_tmpout "mkcol" "test3: mkcol missing" |
|
115 |
|
116 |
|
117 |
|
118 dav_sync_pull test1b "test3: pull failed" |
|
119 ls tmp-sync/test1b/emptydir > /dev/null 2>&1 |
|
120 if [ $? -ne 0 ]; then |
|
121 echo "emptydir not created" |
|
122 exit 2 |
|
123 fi |
|
124 |
|
125 # check if file1 or file2 are pulled |
|
126 TEST=`cat tmp-sync/out.txt | grep "get: /file1"` |
|
127 if [ $? -eq 0 ]; then |
|
128 echo "test3: file1 must not be pulled" |
|
129 exit 2 |
|
130 fi |
|
131 TEST=`cat tmp-sync/out.txt | grep "get: /file2"` |
|
132 if [ $? -eq 0 ]; then |
|
133 echo "test3: file2 must not be pulled" |
|
134 exit 2 |
|
135 fi |
|
136 |
|
137 # ---------------------------------------------------------------------------- |
|
138 # 4. test: do nothing, test if double mkdir happens |
|
139 # expected result: no files pulled, no mkdir |
|
140 |
|
141 dav_sync_pull test1b "test4: pull failed" |
|
142 |
|
143 check_tmpout "0 files pulled" "test4: wrong pull counter" |
|
144 check_tmpout "0 errors" "test4: wrong error counter" |
|
145 check_tmpout "0 conflicts" "test4: wrong conflicts counter" |
|
146 |
|
147 OUT=`cat tmp-sync/out.txt | wc -l` |
|
148 if [ "$OUT" != "1" ]; then |
|
149 echo "test4: wrong line count" |
|
150 exit 2 |
|
151 fi |
|
152 |
|
153 # ---------------------------------------------------------------------------- |
|
154 # 5. test: pull changed files |
|
155 # expected result: 1 file pulled |
|
156 |
|
157 echo testx2 > tmp-sync/test1a/file1 |
|
158 dav_sync_push test1a "test5: push failed" |
|
159 check_tmpout "1 file pushed" "test5: wrong push counter" |
|
160 |
|
161 dav_sync_pull test1b "test5: pull failed" |
|
162 check_tmpout "0 errors" "test5: wrong error counter" |
|
163 check_tmpout "0 conflicts" "test5: wrong conflicts counter" |
|
164 |
|
165 # ---------------------------------------------------------------------------- |
|
166 # 6. test: pull new dir and files |
|
167 # expected result: mkdir and some files pulled |
|
168 |
|
169 mkdir tmp-sync/test1a/subdir |
|
170 cp testdir/subdir/sub1 tmp-sync/test1a/subdir/ |
|
171 cp testdir/subdir/sub2 tmp-sync/test1a/subdir/ |
|
172 dav_sync_push test1a "test6: push failed" |
|
173 |
|
174 dav_sync_pull test1b "test6: pull failed" |
|
175 check_tmpout "get: /subdir/sub1" "test6: sub1 not pulled" |
|
176 check_tmpout "get: /subdir/sub2" "test6: sub2 not pulled" |