improved unit test
This commit is contained in:
parent
4b9df537a0
commit
b133b76ddf
29
ppss
29
ppss
@ -714,6 +714,14 @@ process_arguments () {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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" ]
|
if [ "$DAEMON" == "1" ] && [ -z "$SRC_DIR" ]
|
||||||
then
|
then
|
||||||
showusage_short
|
showusage_short
|
||||||
@ -1414,6 +1422,11 @@ escape_item () {
|
|||||||
|
|
||||||
download_item () {
|
download_item () {
|
||||||
|
|
||||||
|
if [ ! "$DOWNLOAD_TO_NODE" == "1" ] || [ "$VIRTUAL" == "1" ]
|
||||||
|
then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
ITEM="$1"
|
ITEM="$1"
|
||||||
VIRTUAL="0"
|
VIRTUAL="0"
|
||||||
ERR_STATE="0"
|
ERR_STATE="0"
|
||||||
@ -1557,6 +1570,11 @@ get_all_items () {
|
|||||||
get_input_lock
|
get_input_lock
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -e "$LOCAL_INPUT_FILE" ] && are_we_sourced
|
||||||
|
then
|
||||||
|
rm "$LOCAL_INPUT_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
count=0
|
count=0
|
||||||
|
|
||||||
if [ -z "$INPUT_FILE" ]
|
if [ -z "$INPUT_FILE" ]
|
||||||
@ -1565,12 +1583,10 @@ get_all_items () {
|
|||||||
then
|
then
|
||||||
if [ "$RECURSION" == "1" ]
|
if [ "$RECURSION" == "1" ]
|
||||||
then
|
then
|
||||||
#ITEMS=`exec_cmd "find $SRC_DIR/ ! -type d"`
|
|
||||||
`exec_cmd "find $SRC_DIR/ ! -type d" > "$LOCAL_INPUT_FILE"`
|
`exec_cmd "find $SRC_DIR/ ! -type d" > "$LOCAL_INPUT_FILE"`
|
||||||
check_status "$?" "$FUNCNAME" "Could not list files within remote source directory."
|
check_status "$?" "$FUNCNAME" "Could not list files within remote source directory."
|
||||||
else
|
else
|
||||||
log DEBUG "Recursion is disabled."
|
log DEBUG "Recursion is disabled."
|
||||||
#ITEMS=`exec_cmd "ls -1 $SRC_DIR"`
|
|
||||||
`exec_cmd "find $SRC_DIR/ -d 1 ! -type d" > "$LOCAL_INPUT_FILE"`
|
`exec_cmd "find $SRC_DIR/ -d 1 ! -type d" > "$LOCAL_INPUT_FILE"`
|
||||||
check_status "$?" "$FUNCNAME" "Could not list files within remote source directory."
|
check_status "$?" "$FUNCNAME" "Could not list files within remote source directory."
|
||||||
fi
|
fi
|
||||||
@ -1580,13 +1596,11 @@ get_all_items () {
|
|||||||
if [ "$RECURSION" == "1" ]
|
if [ "$RECURSION" == "1" ]
|
||||||
then
|
then
|
||||||
log DEBUG "Recursion is enabled."
|
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."
|
check_status "$?" "$FUNCNAME" "Could not list files within local source directory."
|
||||||
else
|
else
|
||||||
log DEBUG "Recursion is disabled."
|
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."
|
check_status "$?" "$FUNCNAME" "Could not list files within local source directory."
|
||||||
fi
|
fi
|
||||||
if [ ! -e "$LOCAL_INPUT_FILE" ]
|
if [ ! -e "$LOCAL_INPUT_FILE" ]
|
||||||
@ -1997,7 +2011,10 @@ commando () {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! are_we_sourced
|
||||||
|
then
|
||||||
start_single_worker
|
start_single_worker
|
||||||
|
fi
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
81
ppss-test.sh
81
ppss-test.sh
@ -7,6 +7,7 @@ PPSS=./ppss
|
|||||||
PPSS_DIR=ppss_dir
|
PPSS_DIR=ppss_dir
|
||||||
export PPSS_DEBUG=1
|
export PPSS_DEBUG=1
|
||||||
HOST_ARCH=`uname`
|
HOST_ARCH=`uname`
|
||||||
|
SPECIAL_DIR=$TMP_DIR/root/special
|
||||||
. "$PPSS"
|
. "$PPSS"
|
||||||
|
|
||||||
cleanup () {
|
cleanup () {
|
||||||
@ -43,7 +44,7 @@ oneTimeSetUp () {
|
|||||||
|
|
||||||
JOBLOG=./$PPSS_DIR/job_log
|
JOBLOG=./$PPSS_DIR/job_log
|
||||||
INPUTFILENORMAL=test-normal.input
|
INPUTFILENORMAL=test-normal.input
|
||||||
INPUTFILESPECIAL=test-special.input
|
INPUTFILESPECIAL_DIR=test-special.input
|
||||||
LOCALOUTPUT=ppss_dir/PPSS_LOCAL_OUTPUT
|
LOCALOUTPUT=ppss_dir/PPSS_LOCAL_OUTPUT
|
||||||
REMOVEFILES="$PPSS_DIR test-ppss-*"
|
REMOVEFILES="$PPSS_DIR test-ppss-*"
|
||||||
|
|
||||||
@ -76,12 +77,10 @@ oneTimeTearDown () {
|
|||||||
then
|
then
|
||||||
cleanup
|
cleanup
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createDirectoryWithSomeFiles () {
|
createDirectoryWithSomeFiles () {
|
||||||
|
|
||||||
|
|
||||||
ROOT_DIR=$TMP_DIR/root
|
ROOT_DIR=$TMP_DIR/root
|
||||||
CHILD_1=$ROOT_DIR/child_1
|
CHILD_1=$ROOT_DIR/child_1
|
||||||
CHILD_2=$ROOT_DIR/child_2
|
CHILD_2=$ROOT_DIR/child_2
|
||||||
@ -101,6 +100,21 @@ createDirectoryWithSomeFiles () {
|
|||||||
ln -s /etc/hosts "$ROOT_DIR" 2> /dev/null
|
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 () {
|
testMD5 () {
|
||||||
|
|
||||||
ARCH=Darwin
|
ARCH=Darwin
|
||||||
@ -114,18 +128,19 @@ testMD5 () {
|
|||||||
|
|
||||||
init_get_all_items () {
|
init_get_all_items () {
|
||||||
|
|
||||||
RECURSION="$1"
|
RECURSION="$2"
|
||||||
|
DIR="$1"
|
||||||
createDirectoryWithSomeFiles
|
createDirectoryWithSomeFiles
|
||||||
create_working_directory
|
create_working_directory
|
||||||
init_vars > /dev/null 2>&1
|
init_vars > /dev/null 2>&1
|
||||||
export SRC_DIR=$TMP_DIR/root
|
export SRC_DIR=$DIR
|
||||||
get_all_items
|
get_all_items
|
||||||
RES=`get_contents_of_input_file`
|
RES=`get_contents_of_input_file`
|
||||||
}
|
}
|
||||||
|
|
||||||
testRecursion () {
|
testRecursion () {
|
||||||
|
|
||||||
init_get_all_items 1
|
init_get_all_items $TMP_DIR/root 1
|
||||||
|
|
||||||
EXPECTED=32
|
EXPECTED=32
|
||||||
assertEquals "Recursion not correct." "$EXPECTED" "$RES"
|
assertEquals "Recursion not correct." "$EXPECTED" "$RES"
|
||||||
@ -135,7 +150,7 @@ testRecursion () {
|
|||||||
|
|
||||||
testNoRecursion () {
|
testNoRecursion () {
|
||||||
|
|
||||||
init_get_all_items 0
|
init_get_all_items $TMP_DIR/root 0
|
||||||
EXPECTED=12
|
EXPECTED=12
|
||||||
|
|
||||||
assertEquals "Recursion not correct." "$EXPECTED" "$RES"
|
assertEquals "Recursion not correct." "$EXPECTED" "$RES"
|
||||||
@ -143,4 +158,56 @@ testNoRecursion () {
|
|||||||
rename-ppss-dir $FUNCNAME
|
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
|
. ./shunit2
|
||||||
|
Loading…
Reference in New Issue
Block a user