2015-03-09 17:33:47 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -o xtrace
|
|
|
|
set -o errexit
|
|
|
|
|
2015-01-12 22:46:24 +00:00
|
|
|
COMMON=integration-test-common.sh
|
|
|
|
source $COMMON
|
|
|
|
|
|
|
|
# Configuration
|
|
|
|
TEST_TEXT="HELLO WORLD"
|
|
|
|
TEST_TEXT_FILE=test-s3fs.txt
|
|
|
|
TEST_DIR=testdir
|
|
|
|
ALT_TEST_TEXT_FILE=test-s3fs-ALT.txt
|
|
|
|
TEST_TEXT_FILE_LENGTH=15
|
2015-03-03 00:58:11 +00:00
|
|
|
BIG_FILE=big-file-s3fs.txt
|
|
|
|
BIG_FILE_LENGTH=$((25 * 1024 * 1024))
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-02-23 19:59:11 +00:00
|
|
|
function mk_test_file {
|
|
|
|
if [ $# == 0 ]; then
|
|
|
|
TEXT=$TEST_TEXT
|
|
|
|
else
|
|
|
|
TEXT=$1
|
|
|
|
fi
|
|
|
|
echo $TEXT > $TEST_TEXT_FILE
|
|
|
|
if [ ! -e $TEST_TEXT_FILE ]
|
|
|
|
then
|
|
|
|
echo "Could not create file ${TEST_TEXT_FILE}, it does not exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function rm_test_file {
|
|
|
|
if [ $# == 0 ]; then
|
|
|
|
FILE=$TEST_TEXT_FILE
|
|
|
|
else
|
|
|
|
FILE=$1
|
|
|
|
fi
|
|
|
|
rm -f $FILE
|
|
|
|
|
|
|
|
if [ -e $FILE ]
|
|
|
|
then
|
|
|
|
echo "Could not cleanup file ${TEST_TEXT_FILE}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-02-24 01:58:38 +00:00
|
|
|
function mk_test_dir {
|
|
|
|
mkdir ${TEST_DIR}
|
|
|
|
|
|
|
|
if [ ! -d ${TEST_DIR} ]; then
|
|
|
|
echo "Directory ${TEST_DIR} was not created"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function rm_test_dir {
|
|
|
|
rmdir ${TEST_DIR}
|
|
|
|
if [ -e $TEST_DIR ]; then
|
|
|
|
echo "Could not remove the test directory, it still exists: ${TEST_DIR}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_append_file {
|
|
|
|
echo "Testing append to file ..."
|
|
|
|
|
|
|
|
# Write a small test file
|
|
|
|
for x in `seq 1 $TEST_TEXT_FILE_LENGTH`
|
|
|
|
do
|
|
|
|
echo "echo ${TEST_TEXT} to ${TEST_TEXT_FILE}"
|
|
|
|
echo $TEST_TEXT >> $TEST_TEXT_FILE
|
|
|
|
done
|
|
|
|
|
|
|
|
# Verify contents of file
|
|
|
|
echo "Verifying length of test file"
|
|
|
|
FILE_LENGTH=`wc -l $TEST_TEXT_FILE | awk '{print $1}'`
|
|
|
|
if [ "$FILE_LENGTH" -ne "$TEST_TEXT_FILE_LENGTH" ]
|
|
|
|
then
|
|
|
|
echo "error: expected $TEST_TEXT_FILE_LENGTH , got $FILE_LENGTH"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
rm_test_file
|
|
|
|
}
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_mv_file {
|
|
|
|
echo "Testing mv file function ..."
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# if the rename file exists, delete it
|
|
|
|
if [ -e $ALT_TEST_TEXT_FILE ]
|
|
|
|
then
|
|
|
|
rm $ALT_TEST_TEXT_FILE
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
if [ -e $ALT_TEST_TEXT_FILE ]
|
|
|
|
then
|
|
|
|
echo "Could not delete file ${ALT_TEST_TEXT_FILE}, it still exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# create the test file again
|
|
|
|
mk_test_file
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
#rename the test file
|
|
|
|
mv $TEST_TEXT_FILE $ALT_TEST_TEXT_FILE
|
|
|
|
if [ ! -e $ALT_TEST_TEXT_FILE ]
|
|
|
|
then
|
|
|
|
echo "Could not move file"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# Check the contents of the alt file
|
|
|
|
ALT_TEXT_LENGTH=`echo $TEST_TEXT | wc -c | awk '{print $1}'`
|
|
|
|
ALT_FILE_LENGTH=`wc -c $ALT_TEST_TEXT_FILE | awk '{print $1}'`
|
|
|
|
if [ "$ALT_FILE_LENGTH" -ne "$ALT_TEXT_LENGTH" ]
|
|
|
|
then
|
|
|
|
echo "moved file length is not as expected expected: $ALT_TEXT_LENGTH got: $ALT_FILE_LENGTH"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# clean up
|
|
|
|
rm_test_file $ALT_TEST_TEXT_FILE
|
|
|
|
}
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_mv_directory {
|
|
|
|
echo "Testing mv directory function ..."
|
|
|
|
if [ -e $TEST_DIR ]; then
|
|
|
|
echo "Unexpected, this file/directory exists: ${TEST_DIR}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
mk_test_dir
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
mv ${TEST_DIR} ${TEST_DIR}_rename
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
if [ ! -d "${TEST_DIR}_rename" ]; then
|
|
|
|
echo "Directory ${TEST_DIR} was not renamed"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
rmdir ${TEST_DIR}_rename
|
|
|
|
if [ -e "${TEST_DIR}_rename" ]; then
|
|
|
|
echo "Could not remove the test directory, it still exists: ${TEST_DIR}_rename"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_redirects {
|
|
|
|
echo "Testing redirects ..."
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
mk_test_file ABCDEF
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
CONTENT=`cat $TEST_TEXT_FILE`
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
if [ ${CONTENT} != "ABCDEF" ]; then
|
|
|
|
echo "CONTENT read is unexpected, got ${CONTENT}, expected ABCDEF"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
echo XYZ > $TEST_TEXT_FILE
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
CONTENT=`cat $TEST_TEXT_FILE`
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
if [ ${CONTENT} != "XYZ" ]; then
|
|
|
|
echo "CONTENT read is unexpected, got ${CONTENT}, expected XYZ"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
echo 123456 >> $TEST_TEXT_FILE
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
LINE1=`sed -n '1,1p' $TEST_TEXT_FILE`
|
|
|
|
LINE2=`sed -n '2,2p' $TEST_TEXT_FILE`
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
if [ ${LINE1} != "XYZ" ]; then
|
|
|
|
echo "LINE1 was not as expected, got ${LINE1}, expected XYZ"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
if [ ${LINE2} != "123456" ]; then
|
|
|
|
echo "LINE2 was not as expected, got ${LINE2}, expected 123456"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# clean up
|
|
|
|
rm_test_file
|
|
|
|
}
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_mkdir_rmdir {
|
|
|
|
echo "Testing creation/removal of a directory"
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
if [ -e $TEST_DIR ]; then
|
|
|
|
echo "Unexpected, this file/directory exists: ${TEST_DIR}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
mk_test_dir
|
|
|
|
rm_test_dir
|
|
|
|
}
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_chmod {
|
|
|
|
echo "Testing chmod file function ..."
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# create the test file again
|
|
|
|
mk_test_file
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
ORIGINAL_PERMISSIONS=$(stat --format=%a $TEST_TEXT_FILE)
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
chmod 777 $TEST_TEXT_FILE;
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# if they're the same, we have a problem.
|
|
|
|
if [ $(stat --format=%a $TEST_TEXT_FILE) == $ORIGINAL_PERMISSIONS ]
|
|
|
|
then
|
|
|
|
echo "Could not modify $TEST_TEXT_FILE permissions"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# clean up
|
|
|
|
rm_test_file
|
|
|
|
}
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_chown {
|
|
|
|
echo "Testing chown file function ..."
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# create the test file again
|
|
|
|
mk_test_file
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
ORIGINAL_PERMISSIONS=$(stat --format=%u:%g $TEST_TEXT_FILE)
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
chown 1000:1000 $TEST_TEXT_FILE;
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# if they're the same, we have a problem.
|
|
|
|
if [ $(stat --format=%a $TEST_TEXT_FILE) == $ORIGINAL_PERMISSIONS ]
|
|
|
|
then
|
|
|
|
echo "Could not modify $TEST_TEXT_FILE ownership"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# clean up
|
|
|
|
rm_test_file
|
|
|
|
}
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_list {
|
|
|
|
echo "Testing list"
|
|
|
|
mk_test_file
|
|
|
|
mk_test_dir
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
file_cnt=$(ls -1 | wc -l)
|
|
|
|
if [ $file_cnt != 2 ]; then
|
|
|
|
echo "Expected 2 file but got $file_cnt"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
rm_test_file
|
|
|
|
rm_test_dir
|
|
|
|
}
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_remove_nonempty_directory {
|
|
|
|
echo "Testing removing a non-empty directory"
|
|
|
|
mk_test_dir
|
|
|
|
touch "${TEST_DIR}/file"
|
|
|
|
rmdir "${TEST_DIR}" 2>&1 | grep -q "Directory not empty"
|
|
|
|
rm "${TEST_DIR}/file"
|
|
|
|
rm_test_dir
|
|
|
|
}
|
2015-02-24 01:58:38 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_rename_before_close {
|
|
|
|
echo "Testing rename before close ..."
|
|
|
|
(
|
|
|
|
echo foo
|
|
|
|
mv $TEST_TEXT_FILE ${TEST_TEXT_FILE}.new
|
|
|
|
) > $TEST_TEXT_FILE
|
2015-02-24 01:58:38 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
if ! cmp <(echo foo) ${TEST_TEXT_FILE}.new; then
|
|
|
|
echo "rename before close failed"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
rm_test_file ${TEST_TEXT_FILE}.new
|
|
|
|
rm -f ${TEST_TEXT_FILE}
|
|
|
|
}
|
2015-01-12 22:46:24 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_multipart_upload {
|
|
|
|
echo "Testing multi-part upload ..."
|
|
|
|
dd if=/dev/urandom of="/tmp/${BIG_FILE}" bs=$BIG_FILE_LENGTH count=1
|
|
|
|
dd if="/tmp/${BIG_FILE}" of="${BIG_FILE}" bs=$BIG_FILE_LENGTH count=1
|
2015-03-03 00:58:11 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# Verify contents of file
|
|
|
|
echo "Comparing test file"
|
|
|
|
if ! cmp "/tmp/${BIG_FILE}" "${BIG_FILE}"
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f "/tmp/${BIG_FILE}"
|
|
|
|
rm_test_file "${BIG_FILE}"
|
|
|
|
}
|
2015-03-03 00:58:11 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_multipart_copy {
|
|
|
|
echo "Testing multi-part copy ..."
|
|
|
|
dd if=/dev/urandom of="/tmp/${BIG_FILE}" bs=$BIG_FILE_LENGTH count=1
|
|
|
|
dd if="/tmp/${BIG_FILE}" of="${BIG_FILE}" bs=$BIG_FILE_LENGTH count=1
|
|
|
|
mv "${BIG_FILE}" "${BIG_FILE}-copy"
|
2015-07-27 22:47:08 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
# Verify contents of file
|
|
|
|
echo "Comparing test file"
|
|
|
|
if ! cmp "/tmp/${BIG_FILE}" "${BIG_FILE}-copy"
|
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-07-27 22:47:08 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
rm -f "/tmp/${BIG_FILE}"
|
|
|
|
rm_test_file "${BIG_FILE}-copy"
|
|
|
|
}
|
2015-07-27 22:47:08 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function test_special_characters {
|
|
|
|
echo "Testing special characters ..."
|
2015-07-27 22:47:08 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
ls 'special' 2>&1 | grep -q 'No such file or directory'
|
|
|
|
ls 'special?' 2>&1 | grep -q 'No such file or directory'
|
|
|
|
ls 'special*' 2>&1 | grep -q 'No such file or directory'
|
|
|
|
ls 'special~' 2>&1 | grep -q 'No such file or directory'
|
|
|
|
ls 'specialµ' 2>&1 | grep -q 'No such file or directory'
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_extended_attributes {
|
|
|
|
echo "Testing extended attributes ..."
|
|
|
|
|
|
|
|
rm -f $TEST_TEXT_FILE
|
|
|
|
touch $TEST_TEXT_FILE
|
|
|
|
|
|
|
|
# set value
|
|
|
|
setfattr -n key1 -v value1 $TEST_TEXT_FILE
|
|
|
|
getfattr -n key1 --only-values $TEST_TEXT_FILE | grep -q '^value1$'
|
|
|
|
|
|
|
|
# append value
|
|
|
|
setfattr -n key2 -v value2 $TEST_TEXT_FILE
|
|
|
|
getfattr -n key1 --only-values $TEST_TEXT_FILE | grep -q '^value1$'
|
|
|
|
getfattr -n key2 --only-values $TEST_TEXT_FILE | grep -q '^value2$'
|
|
|
|
|
|
|
|
# remove value
|
|
|
|
setfattr -x key1 $TEST_TEXT_FILE
|
|
|
|
! getfattr -n key1 --only-values $TEST_TEXT_FILE
|
|
|
|
getfattr -n key2 --only-values $TEST_TEXT_FILE | grep -q '^value2$'
|
|
|
|
}
|
2015-07-27 22:47:08 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
function run_all_tests {
|
|
|
|
test_append_file
|
|
|
|
test_mv_file
|
|
|
|
test_mv_directory
|
|
|
|
test_redirects
|
|
|
|
test_mkdir_rmdir
|
|
|
|
test_chmod
|
|
|
|
test_chown
|
|
|
|
test_list
|
|
|
|
test_remove_nonempty_directory
|
|
|
|
# TODO: broken: https://github.com/s3fs-fuse/s3fs-fuse/issues/145
|
|
|
|
#test_rename_before_close
|
|
|
|
test_multipart_upload
|
|
|
|
# TODO: test disabled until S3Proxy 1.5.0 is released
|
|
|
|
#test_multipart_copy
|
|
|
|
test_special_characters
|
|
|
|
test_extended_attributes
|
|
|
|
}
|
|
|
|
|
|
|
|
# Mount the bucket
|
|
|
|
CUR_DIR=`pwd`
|
|
|
|
TEST_BUCKET_MOUNT_POINT_1=$1
|
|
|
|
if [ "$TEST_BUCKET_MOUNT_POINT_1" == "" ]; then
|
|
|
|
echo "Mountpoint missing"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cd $TEST_BUCKET_MOUNT_POINT_1
|
|
|
|
|
|
|
|
if [ -e $TEST_TEXT_FILE ]
|
|
|
|
then
|
|
|
|
rm -f $TEST_TEXT_FILE
|
2015-07-27 22:47:08 +00:00
|
|
|
fi
|
2015-03-03 00:58:11 +00:00
|
|
|
|
2015-08-16 22:48:05 +00:00
|
|
|
run_all_tests
|
2015-01-12 22:46:24 +00:00
|
|
|
|
|
|
|
# Unmount the bucket
|
|
|
|
cd $CUR_DIR
|
|
|
|
echo "All tests complete."
|