add first metadata sync test

Sat, 19 Oct 2019 10:47:46 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 19 Oct 2019 10:47:46 +0200
changeset 661
1baec7ff8931
parent 660
e835ec0b7f17
child 662
ab34fc9ecf1d

add first metadata sync test

dav/scfg.c file | annotate | diff | comparison | revisions
dav/sync.c file | annotate | diff | comparison | revisions
test/bin-test/dav-home/sync.xml file | annotate | diff | comparison | revisions
test/bin-test/test-dav-sync-metadata1.sh file | annotate | diff | comparison | revisions
test/bin-test/test-dav-sync.sh file | annotate | diff | comparison | revisions
--- a/dav/scfg.c	Sat Oct 19 09:47:31 2019 +0200
+++ b/dav/scfg.c	Sat Oct 19 10:47:46 2019 +0200
@@ -500,6 +500,8 @@
                         md |= FINFO_OWNER;
                     } else if(!strcmp(m, "xattr")) {
                         md |= FINFO_XATTR;
+                    } else if(!strcmp(m, "all")) {
+                        md |= FINFO_MTIME | FINFO_MODE | FINFO_OWNER | FINFO_XATTR;
                     }
                     m = strtok(NULL, delims);
                 }
--- a/dav/sync.c	Sat Oct 19 09:47:31 2019 +0200
+++ b/dav/sync.c	Sat Oct 19 10:47:46 2019 +0200
@@ -3987,6 +3987,8 @@
     if(ret == 0) {
         (*counter)++;
         
+        local->tags_updated = 0;
+        
         update_metadata_hashes(local, hashes);
         update_parts(local, parts, blockcount);
         
@@ -4281,6 +4283,7 @@
         err = 1;
     } else {
         update_metadata_hashes(local, hashes);
+        local->tags_updated = 0;
     }
     
     return err;
--- a/test/bin-test/dav-home/sync.xml	Sat Oct 19 09:47:31 2019 +0200
+++ b/test/bin-test/dav-home/sync.xml	Sat Oct 19 10:47:46 2019 +0200
@@ -109,4 +109,34 @@
 		<hashing>true</hashing>
 	</directory>
 	
+	<!--
+	Test 4: metadata sync
+	-->
+	<directory>
+		<name>test4a</name>
+		<path>$HOME/tmp-sync/test4a</path>
+		<repository>dav-test-repo</repository>
+		<collection>/sync/test4</collection>
+		<trash>.trash</trash>
+		<database>dav-sync-tests-test4a-db.xml</database>
+		
+		<tagconfig>
+			<local-store format="csv">xattr</local-store>
+		</tagconfig>
+		<metadata>all</metadata>
+	</directory>
+	
+	<directory>
+		<name>test4b</name>
+		<path>$HOME/tmp-sync/test4b</path>
+		<repository>dav-test-repo</repository>
+		<collection>/sync/test4</collection>
+		<trash>.trash</trash>
+		<database>dav-sync-tests-test4b-db.xml</database>
+		
+		<tagconfig>
+			<local-store format="csv">xattr</local-store>
+		</tagconfig>
+		<metadata>all</metadata>
+	</directory>
 </configuration>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bin-test/test-dav-sync-metadata1.sh	Sat Oct 19 10:47:46 2019 +0200
@@ -0,0 +1,129 @@
+#!/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
+}
+
+rm -f .dav/dav-sync-tests-test4a-db.xml
+rm -f .dav/dav-sync-tests-test4b-db.xml
+
+$DAV_BIN rm dav-test-repo/sync/test4 2> /dev/null
+
+$DAV_BIN mkcol dav-test-repo/sync/test4 2> /dev/null
+
+# tmp sync dir
+rm -Rf tmp-sync
+mkdir tmp-sync
+mkdir tmp-sync/test4a
+mkdir tmp-sync/test4b
+
+# ----------------------------------------------------------------------------
+# 1. test: sync executable file and check if it can be executed
+# expected result: exec works
+
+echo "#!/bin/sh"     > tmp-sync/test4a/script.sh
+echo "echo itworks" >> tmp-sync/test4a/script.sh
+
+chmod +x tmp-sync/test4a/script.sh
+
+dav_sync_push test4a "test 1: push failed"
+check_tmpout "1 file pushed" "test 1: wrong push counter"
+check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)"
+check_tmpout "0 errors" "test 1: wrong error counter (push)"
+
+dav_sync_pull test4b "test 1: pull failed"
+check_tmpout "1 file pulled" "test 1: wrong pull counter"
+check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)"
+check_tmpout "0 errors" "test 1: wrong error counter (pull)"
+
+# test if script in test4a works, if not, shell scripts are unsupported
+# on this platform
+./tmp-sync/test4a/script.sh > /dev/null 2>&1
+if [ $? -eq 0 ]; then
+	# shell scripts work
+	
+	# test synced script
+	./tmp-sync/test4b/script.sh > /dev/null 2>&1
+	if [ $? -ne 0 ]; then
+		echo "script not executable"
+		exit 2
+	fi
+	OUT=`./tmp-sync/test4b/script.sh 2> /dev/null`
+	if [ $OUT != "itworks" ]; then
+		echo "script.sh has wrong output"
+		exit 2
+	fi
+fi
+
--- a/test/bin-test/test-dav-sync.sh	Sat Oct 19 09:47:31 2019 +0200
+++ b/test/bin-test/test-dav-sync.sh	Sat Oct 19 10:47:46 2019 +0200
@@ -95,13 +95,14 @@
 #
 do_test "dav-sync push (1)" test-dav-sync-push1.sh
 do_test "dav-sync pull (1)" test-dav-sync-pull1.sh
-do_test "dav-sync pull conflict (1)" test-dav-sync-pull-conflict.sh
-do_test "dav-sync push conflict (1)" test-dav-sync-push-conflict.sh
-do_test "dav-sync hashing (1)" test-dav-sync-hashing1.sh
-do_test "dav-sync hashing (2)" test-dav-sync-hashing1.sh
-do_test "dav-sync hash strategy" test-dav-sync-hash-strategy.sh
-do_test "dav-sync hash conflict resolution" test-dav-sync-hash-conflictres.sh
-do_test "dav-sync hashing change cfg" test-dav-sync-hashing-cfgchange.sh
+#do_test "dav-sync pull conflict (1)" test-dav-sync-pull-conflict.sh
+#do_test "dav-sync push conflict (1)" test-dav-sync-push-conflict.sh
+#do_test "dav-sync hashing (1)" test-dav-sync-hashing1.sh
+#do_test "dav-sync hashing (2)" test-dav-sync-hashing1.sh
+#do_test "dav-sync hash strategy" test-dav-sync-hash-strategy.sh
+#do_test "dav-sync hash conflict resolution" test-dav-sync-hash-conflictres.sh
+#do_test "dav-sync hashing change cfg" test-dav-sync-hashing-cfgchange.sh
+do_test "dav-sync metadata1" test-dav-sync-metadata1.sh
 
 # cleanup
 $DAV_BIN rm dav-test-repo/sync/test1 > /dev/null 2>&1

mercurial