test/bin-test/test-dav-sync-push1.sh

changeset 571
f6de48471c9c
child 586
b45719a52ea6
equal deleted inserted replaced
570:00b7b8e86c48 571:f6de48471c9c
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 "$errormsg"
63 exit 2
64 fi
65 }
66
67 $DAV_BIN mkcol dav-test-repo/sync/test1
68
69 # 1. test
70 # copy to files to the test1a dir and run push
71 # expected result: 2 uploads, no errors or conflicts
72
73 cp synctest/file1 tmp-sync/test1a
74 cp synctest/file2 tmp-sync/test1a
75
76 OUT=`$DAV_SYNC_BIN push test1a | tail -n 1`
77
78 TEST=`echo $OUT | grep Result`
79 if [ $? -ne 0 ];
80 then
81 echo "push 1 failed"
82 exit 2
83 fi
84
85 TEST=`echo $OUT | grep "2 files pushed"`
86 if [ $? -ne 0 ];
87 then
88 echo "wrong push counter"
89 exit 2
90 fi
91
92 TEST=`echo $OUT | grep "0 conflicts"`
93 if [ $? -ne 0 ];
94 then
95 echo "wrong conflict counter"
96 exit 2
97 fi
98
99 TEST=`echo $OUT | grep "0 files deleted"`
100 if [ $? -ne 0 ];
101 then
102 echo "wrong delete counter"
103 exit 2
104 fi
105
106 # 2. test
107 # do nothing
108 # expected result: no uploads or updates, only status line with zeros
109
110 dav_sync_push test1a "push 2 failed"
111
112 OUT=`wc -l < tmp-sync/out.txt`
113 if [ "$OUT" != "1" ];
114 then
115 echo "push 2: number of output lines not 1"
116 exit 2
117 fi
118
119 check_tmpout "0 files pushed" "push 2: wrong push counter"
120 check_tmpout "0 errors" "push 2: wrong error counter"
121
122 # 3. test
123 # add empty dir
124 # expected result: 1 mkcol
125 mkdir tmp-sync/test1a/emptydir
126
127 dav_sync_push test1a "push 3 failed"
128 check_tmpout "mkcol: /emptydir" "push 3: no mkcol"
129
130 # 4. test
131 # do nothing again, test if double mkcol happens
132 # expected result: no mkcol
133 dav_sync_push test1a "push 4 failed"
134
135 OUT=`wc -l < tmp-sync/out.txt`
136 if [ "$OUT" != "1" ];
137 then
138 echo "push 4: number of output lines not 1"
139 exit 2
140 fi
141
142 check_tmpout "0 files pushed" "push 4: wrong push counter"
143 check_tmpout "0 errors" "push 4: wrong error counter"
144
145
146 # 5. test
147 # touch file
148 # expected result: upload touched file
149 sleep 2
150 touch tmp-sync/test1a/file1
151
152 dav_sync_push test1a "push 5 failed"
153 check_tmpout "put: /file1" "push 5: no put"
154 check_tmpout "1 file pushed" "push 5: wrong push counter"
155 check_tmpout "0 conflicts" "push 5: wrong conflict counter"
156 check_tmpout "0 files deleted" "push 5: wrong delete counter"
157 check_tmpout "0 errors" "push 5: wrong error counter"
158

mercurial