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

changeset 661
1baec7ff8931
child 662
ab34fc9ecf1d
equal deleted inserted replaced
660:e835ec0b7f17 661:1baec7ff8931
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 rm -f .dav/dav-sync-tests-test4a-db.xml
80 rm -f .dav/dav-sync-tests-test4b-db.xml
81
82 $DAV_BIN rm dav-test-repo/sync/test4 2> /dev/null
83
84 $DAV_BIN mkcol dav-test-repo/sync/test4 2> /dev/null
85
86 # tmp sync dir
87 rm -Rf tmp-sync
88 mkdir tmp-sync
89 mkdir tmp-sync/test4a
90 mkdir tmp-sync/test4b
91
92 # ----------------------------------------------------------------------------
93 # 1. test: sync executable file and check if it can be executed
94 # expected result: exec works
95
96 echo "#!/bin/sh" > tmp-sync/test4a/script.sh
97 echo "echo itworks" >> tmp-sync/test4a/script.sh
98
99 chmod +x tmp-sync/test4a/script.sh
100
101 dav_sync_push test4a "test 1: push failed"
102 check_tmpout "1 file pushed" "test 1: wrong push counter"
103 check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)"
104 check_tmpout "0 errors" "test 1: wrong error counter (push)"
105
106 dav_sync_pull test4b "test 1: pull failed"
107 check_tmpout "1 file pulled" "test 1: wrong pull counter"
108 check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)"
109 check_tmpout "0 errors" "test 1: wrong error counter (pull)"
110
111 # test if script in test4a works, if not, shell scripts are unsupported
112 # on this platform
113 ./tmp-sync/test4a/script.sh > /dev/null 2>&1
114 if [ $? -eq 0 ]; then
115 # shell scripts work
116
117 # test synced script
118 ./tmp-sync/test4b/script.sh > /dev/null 2>&1
119 if [ $? -ne 0 ]; then
120 echo "script not executable"
121 exit 2
122 fi
123 OUT=`./tmp-sync/test4b/script.sh 2> /dev/null`
124 if [ $OUT != "itworks" ]; then
125 echo "script.sh has wrong output"
126 exit 2
127 fi
128 fi
129

mercurial