Skip to content

Commit

Permalink
Clean up test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Feb 14, 2011
1 parent 759d78d commit 2f8ad3f
Show file tree
Hide file tree
Showing 24 changed files with 81 additions and 763 deletions.
13 changes: 11 additions & 2 deletions test/api/api-expect-success.sh → test/api/api-test-success.sh
@@ -1,8 +1,8 @@
#!/bin/bash

# usage:
# api-expect-success.sh <file.xml>
# expects success response for the file.xml
# api-test-success.sh <file.xml> [message]
# expects success response for the file.xml, optionally expects a certain message

errorMsg() {
echo "$*" 1>&2
Expand All @@ -13,6 +13,8 @@ DIR=$(cd `dirname $0` && pwd)
file="$1"
shift

message="$*"

XMLSTARLET=xml

#test ${file} for valid xml
Expand Down Expand Up @@ -42,5 +44,12 @@ if [ "true" != "$wassucc" ] ; then
$XMLSTARLET sel -T -t -m "/result/error/message" -v "." -n ${file}
exit 2
fi
if [ "" != "${message}" ] ; then
sucmsg=$($XMLSTARLET sel -T -t -v "/result/success/message" ${file})
if [ "${sucmsg}" != "${message}" ] ; then
errorMsg "FAIL: wrong success message: \"${sucmsg}\", expected \"${message}\""
exit 2
fi
fi

exit 0
23 changes: 1 addition & 22 deletions test/api/test-execution.sh
Expand Up @@ -42,28 +42,7 @@ if [ 0 != $? ] ; then
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi

# job list query doesn't wrap result in common result wrapper
#If <result error="true"> then an error occured.
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
if [ "true" == "$waserror" ] ; then
errorMsg "Server reported an error: "
$XMLSTARLET sel -T -t -v "/result/error/message" -n $DIR/curl.out
exit 2
fi
sh $DIR/api-test-success.sh $DIR/curl.out || exit 2

#Check projects list
itemcount=$($XMLSTARLET sel -T -t -v "/result/executions/@count" $DIR/curl.out)
Expand Down
23 changes: 1 addition & 22 deletions test/api/test-executions-running.sh
Expand Up @@ -41,28 +41,7 @@ if [ 0 != $? ] ; then
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi

# job list query doesn't wrap result in common result wrapper
#If <result error="true"> then an error occured.
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
if [ "true" == "$waserror" ] ; then
errorMsg "Server reported an error: "
$XMLSTARLET sel -T -t -v "/result/error/message" -n $DIR/curl.out
exit 2
fi
sh $DIR/api-test-success.sh $DIR/curl.out || exit 2

#Check projects list
itemcount=$($XMLSTARLET sel -T -t -v "/result/executions/@count" $DIR/curl.out)
Expand Down
20 changes: 4 additions & 16 deletions test/api/test-invalid.sh
Expand Up @@ -37,28 +37,16 @@ if [ 0 != $? ] ; then
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi
sh $DIR/api-test-error.sh $DIR/curl.out || exit 2

#test result error message
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)

errmsg=$($XMLSTARLET sel -T -t -v "/result/error/message" $DIR/curl.out)
substr=${errmsg#Invalid API Request:}
if [ "true" == "$waserror" -a "$substr" != "$errmsg" ] ; then
if [ "Invalid API Request:$substr" == "$errmsg" ] ; then
echo "OK"
else
errorMsg "TEST FAILED: nonexistent project message expected: $errmsg"
errorMsg "TEST FAILED: Invalid API Request message expected: $errmsg"
exit 2
fi

Expand Down
93 changes: 6 additions & 87 deletions test/api/test-job-delete.sh
Expand Up @@ -80,28 +80,7 @@ if [ 0 != $? ] ; then
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi

# job list query doesn't wrap result in common result wrapper
#If <result error="true"> then an error occured.
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
if [ "true" == "$waserror" ] ; then
errorMsg "Server reported an error: "
$XMLSTARLET sel -T -t -v "/result/error/message" -n $DIR/curl.out
exit 2
fi
sh $DIR/api-test-success.sh $DIR/curl.out || exit 2

#result will contain list of failed and succeeded jobs, in this
#case there should only be 1 failed or 1 succeeded since we submit only 1
Expand Down Expand Up @@ -133,82 +112,22 @@ if [ 0 != $? ] ; then
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /result element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi

#expect success
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
wassucc=$($XMLSTARLET sel -T -t -v "/result/@success" $DIR/curl.out)
sucmsg=$($XMLSTARLET sel -T -t -v "/result/success/message" $DIR/curl.out)
if [ "true" == "$waserror" ] ; then
errorMsg "FAIL: error result"
$XMLSTARLET sel -T -t -v "/result/error/message" -n $DIR/curl.out
exit 2
fi
if [ "true" != "$wassucc" ] ; then
errorMsg "FAIL: expected success"
exit 2
fi
if [ "Job was successfully deleted: [${jobid}] api-test/job-delete/cli job" == "$sucmsg" ] ; then
echo "OK"
else
errorMsg "FAIL: expected delete success message"
exit 2
fi
#test success result
sh $DIR/api-test-success.sh $DIR/curl.out "Job was successfully deleted: [${jobid}] api-test/job-delete/cli job" || exit 2
echo "OK"

###
# Get the chosen id, expect DNE message
###

echo "TEST: Get deleted job should fail"


# now submit req
runurl="${apiurl}/job/${jobid}"
params=""
sh $DIR/api-expect-error.sh "${runurl}" "${params}" "Job ID does not exist: ${jobid}" || exit 2

# get listing
$CURL --header "$VERSHEADER" ${runurl}?${params} > $DIR/curl.out
if [ 0 != $? ] ; then
errorMsg "ERROR: failed query request"
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi

# job list query doesn't wrap result in common result wrapper
#If <result error="true"> then an error occured.
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
errmsg=$($XMLSTARLET sel -T -t -v "/result/error/message" $DIR/curl.out)
if [ "true" == "$waserror" -a "Job ID does not exist: ${jobid}" == "$errmsg" ] ; then
echo "OK"
else
errorMsg "FAIL: nonexistent Job ID message expected: $errmsg"
exit 2
fi
echo "OK"

rm $DIR/curl.out

40 changes: 3 additions & 37 deletions test/api/test-job-export-missing.sh
Expand Up @@ -35,44 +35,10 @@ echo "TEST: export job with wrong ID"
runurl="${apiurl}/job/9000"
params=""

# get listing
$CURL --header "$VERSHEADER" ${runurl}?${params} > $DIR/curl.out
if [ 0 != $? ] ; then
errorMsg "ERROR: failed query request"
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi
# expect error message
sh $DIR/api-expect-error.sh "${runurl}" "${params}" "Job ID does not exist: 9000" || exit 2
echo "OK"

# job list query doesn't wrap result in common result wrapper
#If <result error="true"> then an error occured.
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
errmsg=$($XMLSTARLET sel -T -t -v "/result/error/message" $DIR/curl.out)
if [ "true" == "$waserror" -a "Job ID does not exist: 9000" == "$errmsg" ] ; then
echo "OK"
else
errorMsg "TEST FAILED: nonexistent Job ID message expected: $errmsg"
exit 2
fi

rm $DIR/curl.out

23 changes: 2 additions & 21 deletions test/api/test-job-export.sh
Expand Up @@ -80,28 +80,9 @@ if [ 0 != $? ] ; then
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi
# expect success result
sh $DIR/api-test-success.sh $DIR/curl.out || exit 2

# job list query doesn't wrap result in common result wrapper
#If <result error="true"> then an error occured.
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
if [ "true" == "$waserror" ] ; then
errorMsg "Server reported an error: "
$XMLSTARLET sel -T -t -v "/result/error/message" -n $DIR/curl.out
exit 2
fi

#result will contain list of failed and succeeded jobs, in this
#case there should only be 1 failed or 1 succeeded since we submit only 1
Expand Down
52 changes: 3 additions & 49 deletions test/api/test-job-run.sh
Expand Up @@ -80,28 +80,7 @@ if [ 0 != $? ] ; then
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi

# job list query doesn't wrap result in common result wrapper
#If <result error="true"> then an error occured.
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
if [ "true" == "$waserror" ] ; then
errorMsg "Server reported an error: "
$XMLSTARLET sel -T -t -v "/result/error/message" -n $DIR/curl.out
exit 2
fi
sh $DIR/api-test-success.sh $DIR/curl.out || exit 2

#result will contain list of failed and succeeded jobs, in this
#case there should only be 1 failed or 1 succeeded since we submit only 1
Expand Down Expand Up @@ -133,37 +112,12 @@ if [ 0 != $? ] ; then
exit 2
fi

#test curl.out for valid xml
$XMLSTARLET val -w $DIR/curl.out > /dev/null 2>&1
if [ 0 != $? ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /result element
$XMLSTARLET el $DIR/curl.out | grep -e '^result' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi

#expect success
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" $DIR/curl.out)
wassucc=$($XMLSTARLET sel -T -t -v "/result/@success" $DIR/curl.out)
sucmsg=$($XMLSTARLET sel -T -t -v "/result/success/message" $DIR/curl.out)
if [ "true" == "$waserror" ] ; then
errorMsg "FAIL: error result"
$XMLSTARLET sel -T -t -v "/result/error/message" -n $DIR/curl.out
exit 2
fi
if [ "true" != "$wassucc" ] ; then
errorMsg "FAIL: expected success"
exit 2
fi
sh $DIR/api-test-success.sh $DIR/curl.out || exit 2

#get execid

execid=$($XMLSTARLET sel -T -t -v "/result/succeeded/execution/id" $DIR/curl.out)
sucmsg=$($XMLSTARLET sel -T -t -v "/result/success/message" $DIR/curl.out)

if [ "" != "${execid}" -a "Execution started: ${execid}" == "$sucmsg" ] ; then
echo "OK"
Expand Down

0 comments on commit 2f8ad3f

Please sign in to comment.