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

Sun, 17 Dec 2023 14:25:34 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 17 Dec 2023 14:25:34 +0100
changeset 797
edbb20b1438d
parent 650
14e7101d7604
permissions
-rwxr-xr-x

[Makefile] fix missing rules preventing dry-runs

We have to support dry-runs, because many IDEs are using
dry-runs to collect build information.

Some rules have dependencies that expect certain files or
directories to be just present. We added respective build
rules which invoke the test program. This way, the behavior
when running make normally is exactly the same, but dry-runs
are also not failing now.

#!/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-test2a-db.xml
rm -f .dav/dav-sync-tests-test2b-db.xml

$DAV_BIN rm dav-test-repo/sync/test2 2> /dev/null

$DAV_BIN mkcol dav-test-repo/sync/test2 2> /dev/null

# tmp sync dir
rm -Rf tmp-sync
mkdir tmp-sync
mkdir tmp-sync/test2a
mkdir tmp-sync/test2b

# ----------------------------------------------------------------------------
# test 1: add 2 equal files
# expected result: 2 files pushed

mkdir tmp-sync/test2a/dir1/
mkdir tmp-sync/test2a/dir1/subdir1/

echo "equal-file" > tmp-sync/test2a/file1
echo "equal-file" > tmp-sync/test2a/file2

dav_sync_push test2a "test 1: push failed"
check_tmpout "2 files 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 test2b "test 1: pull failed"
check_tmpout "2 files 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 2: add file3 with same content, but change file1 and file2
# expected result: pull: no copy/move for file3

echo "equal-file" > tmp-sync/test2a/file3

echo "change-test2" >> tmp-sync/test2a/file1
echo "change-test2" >> tmp-sync/test2a/file2

sleep 2 # make sure the etag changes

dav_sync_push test2a "test 2: push failed"
check_tmpout "3 files pushed" "test 2: wrong push counter"
check_tmpout "0 conflicts" "test 2: wrong conflict counter (push)"
check_tmpout "0 errors" "test 2: wrong error counter (push)"

dav_sync_pull test2b "test 3: pull failed"
check_tmpout "3 files pulled" "test 2: wrong pull counter"
check_tmpout "0 conflicts" "test 2: wrong conflict counter (pull)"
check_tmpout "0 errors" "test 2: wrong error counter (pull)"

diff tmp-sync/test2a/file1 tmp-sync/test2b/file1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
	echo "test 2: file1 missing or wrong content"
	exit 2
fi
diff tmp-sync/test2a/file2 tmp-sync/test2b/file2 > /dev/null 2>&1
if [ $? -ne 0 ]; then
	echo "test 2: file1 missing or wrong content"
	exit 2
fi
diff tmp-sync/test2a/file3 tmp-sync/test2b/file3 > /dev/null 2>&1
if [ $? -ne 0 ]; then
	echo "test 2: file1 missing or wrong content"
	exit 2
fi

mercurial