test/bin-test/test-dav-put.sh

Sat, 24 Aug 2019 23:34:16 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 24 Aug 2019 23:34:16 +0200
changeset 631
93bbeb00385c
parent 422
1429fb385513
permissions
-rwxr-xr-x

add pull conflict detection tests

#!/bin/sh
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
# Copyright 2018 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

BASE_URL=`dav repo-url dav-test-repo`

#
# test simple file upload
#
echo "hello world" > hello
dav put dav-test-repo/tests/ hello
DAV_RES=$?
rm -f hello

if [ $DAV_RES -ne 0 ]; then
	echo "dav put returned" $DAV_RES
	exit 2
fi

OUT=`dav info dav-test-repo/tests/hello`
if [ $? -ne 0 ]; then
	echo "dav info failed"
	exit 2
fi

echo $OUT | grep "type: resource" > /dev/null
if [ $? -ne 0 ];
then
	echo "wrong resource type"
	exit 2
fi

echo "hello world" > hello
curl --silent -o cmphello $BASE_URL/tests/hello
diff hello cmphello > /dev/null
RES=$?
rm -f hello
rm -f cmphello
if [ $RES -ne 0 ]; then
	echo "wrong content"
	exit 2
fi

#
# test dir upload
#
dav put -R dav-test-repo/tests/ testdir > /dev/null
if [ $? -ne 0 ]; then
	echo "dir upload failed"
	exit 2
fi

# check file1
curl --silent -o tmp_file1 $BASE_URL/tests/file1
if [ $? -ne 0 ]; then
	echo "cannot download file1"
	rm -f tmp_file1
	exit 2
fi

diff testdir/file1 tmp_file1 > /dev/null
if [ $? -ne 0 ]; then
	echo "file1 has wrong content"
	rm -f tmp_file1
	exit 2
fi
rm tmp_file1

# check subdir file
curl --silent -o tmp_sub1 $BASE_URL/tests/subdir/sub1
if [ $? -ne 0 ]; then
	echo "cannot download subdir/sub1"
	rm tmp_sub1
	exit 2
fi

diff testdir/subdir/sub1 tmp_sub1 > /dev/null
if [ $? -ne 0 ]; then
	echo "subdir/sub1 has wrong content"
	rm -f tmp_sub1
	exit 2
fi
rm -f tmp_sub1

# check subdir
OUT=`dav info dav-test-repo/tests/subdir`
if [ $? -ne 0 ]; then
	echo "cannot get subdir infos"
	exit 2
fi

echo $OUT | grep "type: collection" > /dev/null
if [ $? -ne 0 ];
then
	echo "subdir has wrong type"
	exit 2
fi

#
# test upload to specific url
#
dav put dav-test-repo/tests/uploaded_file testdir/file1
if [ $? -ne 0 ]; then
	echo "upload to /tests/uploaded_file failed"
	exit 2
fi
curl --silent -o /dev/null $BASE_URL/tests/uploaded_file
if [ $? -ne 0 ]; then
	echo "uploaded_file has wrong content"
	exit 2
fi

#
# test upload with automatic collection creation
#
dav put dav-test-repo/tests/newdir/newsubdir/newfile testdir/file2
if [ $? -ne 0 ]; then
	echo "upload to /tests/newdir/newsubdir/newfile failed"
	exit 2
fi
curl --silent -o /dev/null $BASE_URL/tests/newdir/newsubdir/newfile
if [ $? -ne 0 ]; then
	echo "newfile has wrong content"
	exit 2
fi

#
# test dir upload to specific url
#
dav put -R dav-test-repo/tests/testdir testdir > /dev/null
if [ $? -ne 0 ]; then
	echo "dir upload to /tests/testdir failed"
	exit 2
fi

OUT=`dav info dav-test-repo/tests/testdir`
if [ $? -ne 0 ]; then
	echo "cannot get /tests/testdir infos"
	exit 2
fi

echo $OUT | grep "type: collection" > /dev/null
if [ $? -ne 0 ];
then
	echo "/tests/testdir has wrong type"
	exit 2
fi

curl --silent -o tmp_file3 $BASE_URL/tests/testdir/file3
CURL_RES=$?
diff tmp_file3 testdir/file3 > /dev/null
DIFF_RES=$?
rm -f tmp_file3

if [ $CURL_RES -ne 0 ]; then
	echo "cannot download /tests/testdir/file3"
	exit 2
fi
if [ $DIFF_RES -ne 0 ]; then
	echo "/tests/testdir/file3 has wrong content"
	exit 2
fi

mercurial