Skip to content

Commit

Permalink
Update api test include script, update util scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Feb 16, 2011
1 parent cceca82 commit 1d74fc8
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 373 deletions.
11 changes: 8 additions & 3 deletions test/api/include.sh
Expand Up @@ -7,11 +7,14 @@ DIR=$(cd `dirname $0` && pwd)
errorMsg() {
echo "$*" 1>&2
}
fail(){
errorMsg "FAIL: $@"
exit 2
}
assert(){
# assert expected, actual
if [ "$1" != "$2" ] ; then
errorMsg "FAIL: Expected value \"$1\" but saw: \"$2\" ${3}"
exit 2
fail "Expected value \"$1\" but saw: \"$2\" ${3}"
fi
}

Expand All @@ -21,7 +24,9 @@ XMLSTARLET=xml
# xmlstarlet select xpath
# usage: xmlsel XPATH file
xmlsel(){
$XMLSTARLET sel -T -t -v "$1" $2
xpath=$1
shift
$XMLSTARLET sel -T -t -v "$xpath" $*
}

API_VERSION="1"
Expand Down
56 changes: 7 additions & 49 deletions test/api/util-executions-running.sh
@@ -1,79 +1,37 @@
#!/bin/bash

#Usage:
# util-executions-running.sh <project> [URL]

errorMsg() {
echo "$*" 1>&2
}
# util-executions-running.sh <URL> <project>

DIR=$(cd `dirname $0` && pwd)

source $DIR/include.sh

proj=$1
if [ "" == "$1" ] ; then
proj="test"
fi
shift
# accept url argument on commandline, if '-' use default
url="$1"
if [ "-" == "$1" ] ; then
url='http://localhost:4440'
fi
shift
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"

if [ ! -f $DIR/cookies ] ; then
# call rundecklogin.sh
sh $DIR/rundecklogin.sh $url
fi

XMLSTARLET=xml

# now submit req
runurl="${apiurl}/executions/running"
runurl="${APIURL}/executions/running"

echo "# Listing Running Executions for project ${proj}..."

params="project=${proj}"


# get listing
$CURL --header "$VERSHEADER" ${runurl}?${params} > $DIR/curl.out
$CURL ${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)
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)
itemcount=$(xmlsel "/result/executions/@count" $DIR/curl.out)
#echo "$itemcount Jobs"
if [ "0" != "$itemcount" ] ; then
#echo all on one line
Expand Down
62 changes: 8 additions & 54 deletions test/api/util-history.sh
@@ -1,41 +1,20 @@
#!/bin/bash

#Usage:
# util-history.sh <project> [URL] [param=value [param=value] .. ]

errorMsg() {
echo "$*" 1>&2
}
# util-history.sh <URL> <project> [param=value [param=value] .. ]

DIR=$(cd `dirname $0` && pwd)

source $DIR/include.sh

proj=$1
if [ "" == "$1" ] ; then
proj="test"
fi
shift
# accept url argument on commandline, if '-' use default
url="$1"
if [ "-" == "$1" ] ; then
url='http://localhost:4440'
fi
shift
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"

if [ ! -f $DIR/cookies ] ; then
# call rundecklogin.sh
sh $DIR/rundecklogin.sh $url
fi

XMLSTARLET=xml

# now submit req
runurl="${apiurl}/history"
runurl="${APIURL}/history"

echo "# Listing RunDeck Jobs for project ${proj}..."

Expand All @@ -44,37 +23,12 @@ params="project=${proj}&${args}"


# 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
$CURL ${runurl}?${params} > $DIR/curl.out || fail "failed request: ${runurl}"

#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/events/@count" $DIR/curl.out)
itemcount=$(xmlsel "/result/events/@count" $DIR/curl.out)

if [ "0" != "$itemcount" ] ; then
#echo all on one line
Expand All @@ -90,4 +44,4 @@ if [ "0" != "$itemcount" ] ; then
-n $DIR/curl.out
fi

rm $DIR/curl.out
#rm $DIR/curl.out
68 changes: 8 additions & 60 deletions test/api/util-job-delete.sh
Expand Up @@ -2,85 +2,33 @@


#Usage:
# util-job-delete.sh [URL] [id]
# util-job-delete.sh <URL> <id>
# Deletes specified job ID.
#

errorMsg() {
echo "$*" 1>&2
}

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"

if [ ! -f $DIR/cookies ] ; then
# call rundecklogin.sh
sh $DIR/rundecklogin.sh $url
fi

XMLSTARLET=xml
source $DIR/include.sh

###
# DELETE the chosen id, expect success message
###

jobid=$2
shift

echo "Deleting job ID ${jobid}..."


# now submit req
runurl="${apiurl}/job/${jobid}"
runurl="${APIURL}/job/${jobid}"
params=""

# get listing
$CURL --header "$VERSHEADER" -X DELETE ${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 /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
# delete
$CURL -X DELETE ${runurl}?${params} > $DIR/curl.out || fail "failed request: ${runurl}"

#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

$XMLSTARLET sel -T -t -v "/result/success/message" -n $DIR/curl.out
xmlsel "/result/success/message" -n $DIR/curl.out

rm $DIR/curl.out

35 changes: 6 additions & 29 deletions test/api/util-jobs-import.sh
Expand Up @@ -2,35 +2,16 @@

# Usage: util-jobs-import.sh <url> <file> [format]

errorMsg() {
echo "$*" 1>&2
}

DIR=$(cd `dirname $0` && pwd)

# accept url argument on commandline, if '-' use default
url="$1"
if [ "-" == "$1" ] ; then
url='http://localhost:4440/api'
fi
shift
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
source $DIR/include.sh

infile=$1
shift
informat=${1:-xml}


# now submit req
runurl="${apiurl}/jobs/import"
runurl="${APIURL}/jobs/import"

echo "Import jobs in ${informat} format"

Expand All @@ -40,20 +21,16 @@ params="dupeOption=update"
ulopts="-F xmlBatch=@$infile"

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

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

failedcount=$($XMLSTARLET sel -T -t -v "/result/failed/@count" $DIR/curl.out)
succount=$($XMLSTARLET sel -T -t -v "/result/succeeded/@count" $DIR/curl.out)
skipcount=$($XMLSTARLET sel -T -t -v "/result/skipped/@count" $DIR/curl.out)
failedcount=$(xmlsel "/result/failed/@count" $DIR/curl.out)
succount=$(xmlsel "/result/succeeded/@count" $DIR/curl.out)
skipcount=$(xmlsel "/result/skipped/@count" $DIR/curl.out)

if [ "0" != "$failedcount" ] ; then
echo "$failedcount Failed:"
Expand Down

0 comments on commit 1d74fc8

Please sign in to comment.