Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for /api/execution/[id]/abort
- Loading branch information
Showing
1 changed file
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#!/bin/bash | ||
|
||
#test aborting execution from /api/execution/{id}/abort | ||
|
||
errorMsg() { | ||
echo "$*" 1>&2 | ||
} | ||
assert(){ | ||
# assert expected, actual | ||
if [ "$1" != "$2" ] ; then | ||
errorMsg "FAIL: Expected value \"$1\" but saw: \"$2\" ${3}" | ||
exit 2 | ||
fi | ||
} | ||
|
||
DIR=$(cd `dirname $0` && pwd) | ||
|
||
# accept url argument on commandline, if '-' use default | ||
url="$1" | ||
if [ "-" == "$1" ] ; then | ||
url='http://localhost:4440' | ||
fi | ||
apiurl="${url}/api" | ||
VERSHEADER="X-RUNDECK-API-VERSION: 1.2" | ||
|
||
# curl opts to use a cookie jar, and follow redirects, showing only errors | ||
CURLOPTS="-s -S -L -c $DIR/cookies -b $DIR/cookies" | ||
CURL="curl $CURLOPTS" | ||
|
||
|
||
XMLSTARLET=xml | ||
|
||
#### | ||
# Setup: create simple adhoc command execution to provide execution ID. | ||
#### | ||
|
||
runurl="${apiurl}/run/command" | ||
proj="test" | ||
params="project=${proj}&exec=echo+testing+execution+api%3Bsleep+120" | ||
|
||
# get listing | ||
$CURL --header "$VERSHEADER" ${runurl}?${params} > $DIR/curl.out | ||
if [ 0 != $? ] ; then | ||
errorMsg "ERROR: failed query request" | ||
exit 2 | ||
fi | ||
|
||
sh $DIR/api-test-success.sh $DIR/curl.out || exit 2 | ||
|
||
#select id | ||
|
||
execid=$($XMLSTARLET sel -T -t -v "/result/execution/@id" $DIR/curl.out) | ||
|
||
if [ -z "$execid" ] ; then | ||
errorMsg "FAIL: expected execution id" | ||
exit 2 | ||
fi | ||
|
||
|
||
#### | ||
# Test: | ||
#### | ||
|
||
# now submit req | ||
runurl="${apiurl}/execution/${execid}" | ||
|
||
echo "TEST: /api/execution/${execid} ..." | ||
|
||
params="" | ||
|
||
# get listing | ||
$CURL --header "$VERSHEADER" ${runurl}?${params} > $DIR/curl.out | ||
if [ 0 != $? ] ; then | ||
errorMsg "ERROR: failed query request" | ||
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) | ||
assert "1" "$itemcount" "execution count should be 1" | ||
|
||
assert "running" $($XMLSTARLET sel -T -t -v "/result/executions/execution/@status" $DIR/curl.out) "execution was not running" | ||
|
||
echo "OK" | ||
|
||
|
||
#### | ||
# test /abort | ||
#### | ||
|
||
runurl="${apiurl}/execution/${execid}/abort" | ||
|
||
echo "TEST: /api/execution/${execid}/abort ..." | ||
|
||
params="" | ||
|
||
# pause | ||
sleep 4 | ||
|
||
# get listing | ||
$CURL --header "$VERSHEADER" ${runurl}?${params} > $DIR/curl.out | ||
if [ 0 != $? ] ; then | ||
errorMsg "ERROR: failed query request" | ||
exit 2 | ||
fi | ||
|
||
sh $DIR/api-test-success.sh $DIR/curl.out || exit 2 | ||
|
||
#Check projects list | ||
astatus=$($XMLSTARLET sel -T -t -v "/result/abort/@status" $DIR/curl.out) | ||
aexecid=$($XMLSTARLET sel -T -t -v "/result/abort/execution/@id" $DIR/curl.out) | ||
aexecstatus=$($XMLSTARLET sel -T -t -v "/result/abort/execution/@status" $DIR/curl.out) | ||
|
||
assert "pending" "$astatus" "Abort status should be pending" | ||
assert "$execid" "$aexecid" "Wrong execution id in abort status" | ||
assert "running" "$aexecstatus" "Wrong execution status in abort status" | ||
|
||
echo "OK" | ||
|
||
|
||
rm $DIR/curl.out | ||
|