Sun, 17 Sep 2023 13:40:48 +0200
use _mkgmtime instead of mktime in parse_iso8601() on windows
#!/bin/sh # # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # # Copyright 2019 Olaf Wintermann. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # if [ -z "$DAV_BIN" ]; then echo "DAV_BIN variable not set" exit 1 fi if [ -z "$DAV_SYNC_BIN" ]; then echo "DAV_BIN variable not set" exit 1 fi # checks if tmp-sync/out.txt contains a specific text # arg1: pattern # arg2: errormsg check_tmpout() { TEST=`cat tmp-sync/out.txt | grep "$1"` if [ $? -ne 0 ]; then echo "$2" exit 2 fi } # do dav-sync push and check return value # arg1: dir # arg2: errormsg dav_sync_push() { $DAV_SYNC_BIN push $1 > tmp-sync/out.txt if [ $? -ne 0 ]; then echo "$2" exit 2 fi } # do dav-sync pull and check return value # arg1: dir # arg2: errormsg dav_sync_pull() { $DAV_SYNC_BIN pull $1 > tmp-sync/out.txt if [ $? -ne 0 ]; then echo "$2" exit 2 fi } $DAV_BIN mkcol dav-test-repo/sync/test1 2> /dev/null $DAV_BIN mkcol dav-test-repo/sync/test2 2> /dev/null # ---------------------------------------------------------------------------- # 1. test: pull empty collection # expected result: 0 files pulled, 0 errors dav_sync_pull test1b "test1: pull failed" check_tmpout "0 files pulled" "pull1: wrong pull counter" check_tmpout "0 errors" "pull1: wrong error counter" check_tmpout "0 conflicts" "pull1: wrong conflicts counter" # ---------------------------------------------------------------------------- # 2. test: add 2 files to test1a and push it and pull test1b # expected result: 2 files pushed, 2 files pulled rm -f .dav/dav-sync-tests-test1a-db.xml cp synctest/file1 tmp-sync/test1a cp synctest/file2 tmp-sync/test1a dav_sync_push test1a "test2: push failed" check_tmpout "2 files pushed" "test2: wrong push counter" dav_sync_pull test1b "test2: pull failed" check_tmpout "2 files pulled" "test2: wrong pull counter" check_tmpout "0 errors" "test2: wrong error counter" check_tmpout "0 conflicts" "test2: wrong conflicts counter" cat tmp-sync/test1b/file1 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test2: missing file1" fi cat tmp-sync/test1b/file2 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test2: missing file2" fi # ---------------------------------------------------------------------------- # 3. test: pull empty directory # expected result: empty directory created mkdir tmp-sync/test1a/emptydir dav_sync_push test1a "test3: push failed" check_tmpout "mkcol" "test3: mkcol missing" dav_sync_pull test1b "test3: pull failed" ls tmp-sync/test1b/emptydir > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "emptydir not created" exit 2 fi # check if file1 or file2 are pulled TEST=`cat tmp-sync/out.txt | grep "get: /file1"` if [ $? -eq 0 ]; then echo "test3: file1 must not be pulled" exit 2 fi TEST=`cat tmp-sync/out.txt | grep "get: /file2"` if [ $? -eq 0 ]; then echo "test3: file2 must not be pulled" exit 2 fi # ---------------------------------------------------------------------------- # 4. test: do nothing, test if double mkdir happens # expected result: no files pulled, no mkdir dav_sync_pull test1b "test4: pull failed" check_tmpout "0 files pulled" "test4: wrong pull counter" check_tmpout "0 errors" "test4: wrong error counter" check_tmpout "0 conflicts" "test4: wrong conflicts counter" OUT=`cat tmp-sync/out.txt | wc -l` if [ $OUT -ne 1 ]; then echo "test4: wrong line count" exit 2 fi # ---------------------------------------------------------------------------- # 5. test: pull changed files # expected result: 1 file pulled echo testx5 > tmp-sync/test1a/file1 dav_sync_push test1a "test5: push failed" check_tmpout "1 file pushed" "test5: wrong push counter" dav_sync_pull test1b "test5: pull failed" check_tmpout "0 errors" "test5: wrong error counter" check_tmpout "0 conflicts" "test5: wrong conflicts counter" TEST=`cat tmp-sync/test1b/file1` if [ $TEST != "testx5" ]; then echo "test5: wrong content" exit 2 fi # ---------------------------------------------------------------------------- # 6. test: pull new dir and files # expected result: mkdir and some files pulled mkdir tmp-sync/test1a/subdir cp testdir/subdir/sub1 tmp-sync/test1a/subdir/ cp testdir/subdir/sub2 tmp-sync/test1a/subdir/ dav_sync_push test1a "test6: push failed" dav_sync_pull test1b "test6: pull failed" check_tmpout "get: /subdir/sub1" "test6: sub1 not pulled" check_tmpout "get: /subdir/sub2" "test6: sub2 not pulled" # ---------------------------------------------------------------------------- # 7. test: pull deep dir hierarchy with some files # expected result: mkdir in correct order (see push1 test 6) mkdir -p tmp-sync/test1a/dir_a/1/2/3/4/5/6/7/8 mkdir -p tmp-sync/test1a/dir_a/1/2/3/a/b/c/d mkdir -p tmp-sync/test1a/dir_a/i/j/k mkdir -p tmp-sync/test1a/dir_b/1/2/3/4/5/6/7/8 mkdir -p tmp-sync/test1a/dir_b/1/2/3/a/b/c/d mkdir -p tmp-sync/test1a/dir_b/i/j/k mkdir -p tmp-sync/test1a/dir_c/sub1/sub2/sub3/sub4 mkdir -p tmp-sync/test1a/dir_c/sub1/sub2/1 mkdir -p tmp-sync/test1a/dir_c/sub1/sub2/2 mkdir -p tmp-sync/test1a/dir_c/sub1/sub2/3 mkdir -p tmp-sync/test1a/dir_c/sub1/sub2/4 mkdir -p tmp-sync/test1a/dir_c/sub1/sub2/5 mkdir -p tmp-sync/test1a/dir_c/sub_a/x mkdir -p tmp-sync/test1a/dir_c/sub_a/y/d1/d2/d3 touch tmp-sync/test1a/dir_a/1/2/3/4/5/6/7/8/file1 touch tmp-sync/test1a/dir_a/1/2/3/4/5/6/7/file1 touch tmp-sync/test1a/dir_a/1/2/3/4/5/6/file1 touch tmp-sync/test1a/dir_a/1/2/3/a/b/c/d/d_file1 touch tmp-sync/test1a/dir_a/1/2/3/a/b/b_file1 touch tmp-sync/test1a/dir_a/a_file echo "test6-file-1" > tmp-sync/test1a/dir_b/1/2/3/4/5/6/7/8/t6f1-8 echo "test6-file-2" > tmp-sync/test1a/dir_b/i/t6f2-i echo "test6-file-3" > tmp-sync/test1a/dir_c/sub1/sub2/sub3/sub4/t6f3-s4 echo "test6-file-4" > tmp-sync/test1a/dir_c/sub1/sub2/3/t6f4-3 dav_sync_push test1a "test7: push failed" check_tmpout "10 files pushed" "test7: wrong push counter" dav_sync_pull test1b "test7: pull failed" check_tmpout "0 errors" "test7: wrong error counter" check_tmpout "0 conflicts" "test7: wrong conflicts counter" # check if all files are pulled cat tmp-sync/test1b/dir_a/1/2/3/4/5/6/7/8/file1 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 1" exit 2 fi cat tmp-sync/test1b/dir_a/1/2/3/4/5/6/7/file1 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 2" exit 2 fi cat tmp-sync/test1b/dir_a/1/2/3/4/5/6/file1 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 3" exit 2 fi cat tmp-sync/test1b/dir_a/1/2/3/a/b/c/d/d_file1 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 4" exit 1 fi cat tmp-sync/test1b/dir_a/1/2/3/a/b/b_file1 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 5" exit 2 fi cat tmp-sync/test1b/dir_a/a_file > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 6" exit 2 fi cat tmp-sync/test1b/dir_b/1/2/3/4/5/6/7/8/t6f1-8 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 7" exit 2 fi cat tmp-sync/test1b/dir_b/i/t6f2-i > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 8" exit 2 fi cat tmp-sync/test1b/dir_c/sub1/sub2/sub3/sub4/t6f3-s4 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 9" exit 2 fi cat tmp-sync/test1b/dir_c/sub1/sub2/3/t6f4-3 > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "test 7: missing file: 10" exit 2 fi # ---------------------------------------------------------------------------- # 8. test: delete file # expected result: 1 file deleted rm tmp-sync/test1a/file1 dav_sync_push test1a check_tmpout "1 file deleted" "test8: wrong delete counter" dav_sync_pull test1b check_tmpout "1 file deleted" "test8: wrong delete counter" TEST=`cat tmp-sync/out.txt | grep "delete: /file1"` if [ $? -ne 0 ]; then echo "test8: file1 not deleted (log)" exit 2 fi cat tmp-sync/test1b/file1 > /dev/null 2>&1 # should fail if [ $? -eq 0 ]; then echo "test8: file1 not deleted" exit 2 fi # ---------------------------------------------------------------------------- # 9. test: delete multiple files # expected result: multiple files deleted rm tmp-sync/test1a/file2 rm tmp-sync/test1a/subdir/sub1 rm tmp-sync/test1a/subdir/sub2 dav_sync_push test1a check_tmpout "3 files deleted" "test9: wrong delete counter" dav_sync_pull test1b check_tmpout "3 files deleted" "test9: wrong delete counter" check_tmpout "0 errors" "test9: wrong error counter" check_tmpout "0 conflicts" "test9: wrong conflicts counter" TEST=`cat tmp-sync/out.txt | grep "delete: /subdir/sub1"` if [ $? -ne 0 ]; then echo "test9: sub1 not deleted (log)" exit 2 fi TEST=`cat tmp-sync/out.txt | grep "delete: /subdir/sub2"` if [ $? -ne 0 ]; then echo "test9: sub2 not deleted (log)" exit 2 fi cat tmp-sync/test1b/file2 > /dev/null 2>&1 # should fail if [ $? -eq 0 ]; then echo "test9: file2 not deleted" exit 2 fi cat tmp-sync/test1b/subdir/sub1 > /dev/null 2>&1 # should fail if [ $? -eq 0 ]; then echo "test9: sub1 not deleted" exit 2 fi cat tmp-sync/test1b/subdir/sub2 > /dev/null 2>&1 # should fail if [ $? -eq 0 ]; then echo "test9: sub2 not deleted" exit 2 fi OUT=`ls tmp-sync/test1b/subdir/ | wc -l` if [ $OUT -ne 0 ]; then echo "test9: test1b/subdir not empty" exit 2 fi # ---------------------------------------------------------------------------- # 10. test: delete empty dir # expected result: pull deletes local empty dir rm -Rf tmp-sync/test1a/subdir/ dav_sync_push test1a dav_sync_pull test1b check_tmpout "0 errors" "test10: wrong error counter" check_tmpout "0 conflicts" "test10: wrong conflicts counter" TEST=`ls tmp-sync/test1b/ | grep subdir` if [ $? -eq 0 ]; then echo "test10: subdir not deleted" fi # ---------------------------------------------------------------------------- # 11. test: delete deep dir hierarchy # expected result: 0 errors, everything deleted rm -Rf tmp-sync/test1a/dir_a dav_sync_push test1a dav_sync_pull test1b check_tmpout "0 errors" "test10: wrong error counter" check_tmpout "0 conflicts" "test10: wrong conflicts counter" TEST=`ls tmp-sync/test1b/ | grep dir_a` if [ $? -eq 0 ]; then echo "test10: dir_a not deleted" fi # ---------------------------------------------------------------------------- # 11. test: delete all # expected result: empty dir (except .trash) rm -Rf tmp-sync/test1a/* dav_sync_push test1a dav_sync_pull test1b check_tmpout "0 errors" "test10: wrong error counter" check_tmpout "0 conflicts" "test10: wrong conflicts counter" OUT=`ls tmp-sync/test1b/ | wc -l` if [ $OUT -ne 0 ]; then echo "test1b not empty" exit 2 fi