improved unit test

This commit is contained in:
Louwrentius 2010-06-08 23:10:35 +00:00
parent 4b9df537a0
commit b133b76ddf
2 changed files with 99 additions and 15 deletions

31
ppss
View File

@ -714,6 +714,14 @@ process_arguments () {
exit 1
fi
if [ ! -e "$SRC_DIR" ]
then
showusage_short
echo
log ERROR "Source directory $SRC_DIR does not exist."
exit 1
fi
if [ "$DAEMON" == "1" ] && [ -z "$SRC_DIR" ]
then
showusage_short
@ -1414,6 +1422,11 @@ escape_item () {
download_item () {
if [ ! "$DOWNLOAD_TO_NODE" == "1" ] || [ "$VIRTUAL" == "1" ]
then
return 1
fi
ITEM="$1"
VIRTUAL="0"
ERR_STATE="0"
@ -1556,6 +1569,11 @@ get_all_items () {
then
get_input_lock
fi
if [ -e "$LOCAL_INPUT_FILE" ] && are_we_sourced
then
rm "$LOCAL_INPUT_FILE"
fi
count=0
@ -1565,12 +1583,10 @@ get_all_items () {
then
if [ "$RECURSION" == "1" ]
then
#ITEMS=`exec_cmd "find $SRC_DIR/ ! -type d"`
`exec_cmd "find $SRC_DIR/ ! -type d" > "$LOCAL_INPUT_FILE"`
check_status "$?" "$FUNCNAME" "Could not list files within remote source directory."
else
log DEBUG "Recursion is disabled."
#ITEMS=`exec_cmd "ls -1 $SRC_DIR"`
`exec_cmd "find $SRC_DIR/ -d 1 ! -type d" > "$LOCAL_INPUT_FILE"`
check_status "$?" "$FUNCNAME" "Could not list files within remote source directory."
fi
@ -1580,13 +1596,11 @@ get_all_items () {
if [ "$RECURSION" == "1" ]
then
log DEBUG "Recursion is enabled."
#ITEMS=`find "$SRC_DIR/" ! -type d`
`find "$SRC_DIR/" ! -type d >> "$LOCAL_INPUT_FILE"`
`find "$SRC_DIR"/ ! -type d >> "$LOCAL_INPUT_FILE"`
check_status "$?" "$FUNCNAME" "Could not list files within local source directory."
else
log DEBUG "Recursion is disabled."
#ITEMS=`ls -1 "$SRC_DIR"`
`find "$SRC_DIR/" -d 1 ! -type d >> "$LOCAL_INPUT_FILE"`
`find "$SRC_DIR"/ -d 1 ! -type d >> "$LOCAL_INPUT_FILE"`
check_status "$?" "$FUNCNAME" "Could not list files within local source directory."
fi
if [ ! -e "$LOCAL_INPUT_FILE" ]
@ -1997,7 +2011,10 @@ commando () {
fi
fi
start_single_worker
if ! are_we_sourced
then
start_single_worker
fi
return $?
}

View File

@ -7,6 +7,7 @@ PPSS=./ppss
PPSS_DIR=ppss_dir
export PPSS_DEBUG=1
HOST_ARCH=`uname`
SPECIAL_DIR=$TMP_DIR/root/special
. "$PPSS"
cleanup () {
@ -43,7 +44,7 @@ oneTimeSetUp () {
JOBLOG=./$PPSS_DIR/job_log
INPUTFILENORMAL=test-normal.input
INPUTFILESPECIAL=test-special.input
INPUTFILESPECIAL_DIR=test-special.input
LOCALOUTPUT=ppss_dir/PPSS_LOCAL_OUTPUT
REMOVEFILES="$PPSS_DIR test-ppss-*"
@ -76,12 +77,10 @@ oneTimeTearDown () {
then
cleanup
fi
}
createDirectoryWithSomeFiles () {
ROOT_DIR=$TMP_DIR/root
CHILD_1=$ROOT_DIR/child_1
CHILD_2=$ROOT_DIR/child_2
@ -92,7 +91,7 @@ createDirectoryWithSomeFiles () {
for x in {1..10}
do
touch "$ROOT_DIR/file-$x"
touch "$ROOT_DIR/file-$x"
touch "$CHILD_1/file-$x"
touch "$CHILD_2/file-$x"
done
@ -101,6 +100,21 @@ createDirectoryWithSomeFiles () {
ln -s /etc/hosts "$ROOT_DIR" 2> /dev/null
}
createSpecialFilenames () {
ERROR=0
mkdir -p "$SPECIAL_DIR"
touch "$SPECIAL_DIR/a file with spaces"
touch "$SPECIAL_DIR/a\\'file\\'with\\'quotes"
touch "$SPECIAL_DIR/a{file}with{curly}brackets}"
touch "$SPECIAL_DIR/a(file)with(parenthesis)"
touch "$SPECIAL_DIR/a\\file\\with\\backslashes"
touch "$SPECIAL_DIR/a!file!with!exclamationmarks"
touch "$SPECIAL_DIR/a filé with special characters"
touch "$SPECIAL_DIR/a\"file\"with\"double\"quotes"
}
testMD5 () {
ARCH=Darwin
@ -114,18 +128,19 @@ testMD5 () {
init_get_all_items () {
RECURSION="$1"
RECURSION="$2"
DIR="$1"
createDirectoryWithSomeFiles
create_working_directory
init_vars > /dev/null 2>&1
export SRC_DIR=$TMP_DIR/root
export SRC_DIR=$DIR
get_all_items
RES=`get_contents_of_input_file`
}
testRecursion () {
init_get_all_items 1
init_get_all_items $TMP_DIR/root 1
EXPECTED=32
assertEquals "Recursion not correct." "$EXPECTED" "$RES"
@ -135,7 +150,7 @@ testRecursion () {
testNoRecursion () {
init_get_all_items 0
init_get_all_items $TMP_DIR/root 0
EXPECTED=12
assertEquals "Recursion not correct." "$EXPECTED" "$RES"
@ -143,4 +158,56 @@ testNoRecursion () {
rename-ppss-dir $FUNCNAME
}
testGetItem () {
createSpecialFilenames
init_get_all_items $TMP_DIR/root 1
get_item
if [ -z "$ITEM" ]
then
ERROR=1
else
ERROR=0
fi
EXPECTED=0
assertEquals "Get item failed." "$EXPECTED" "$ERROR"
i=1
ERROR=0
while get_item
do
((i++))
done
EXPECTED=40
assertEquals "Got wrong number of items." "$EXPECTED" "$i"
}
testEscaping () {
createSpecialFilenames
init_get_all_items $TMP_DIR/root 1
RES1=`find $TMP_DIR/root/ ! -type d`
while get_item
do
RES2="$RES2$ITEM"$'\n'
done
RES1="$RES1"$'\n' # NASTY HACK YUCK
assertEquals "Input file and actual files not the same!" "$RES1" "$RES2"
}
inotestNumberOfLogfiles () {
createSpecialFilenames
init_get_all_items $TMP_DIR/root 1
COMMAND='echo '
while get_item
do
commando "$ITEM"
done
RES=`ls -1 $PPSS_DIR/job_log/ | wc -l | awk '{ print $1}'`
assertEquals "Got wrong number of log files." 40 "$RES"
}
. ./shunit2