-
Notifications
You must be signed in to change notification settings - Fork 899
/
test-executions-running.sh
executable file
·80 lines (60 loc) · 1.75 KB
/
test-executions-running.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#test output from /api/executions/running
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"
XMLSTARLET=xml
# now submit req
runurl="${apiurl}/executions/running"
proj=$2
if [ "" == "$2" ] ; then
proj="test"
fi
echo "TEST: /api/executions/running for project ${proj}..."
params="project=${proj}"
# 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)
if [ "true" == "$waserror" ] ; then
errorMsg "Server reported an error: "
$XMLSTARLET sel -T -t -v "/result/error/message" -n $DIR/curl.out
exit 2
fi
#Check projects list
itemcount=$($XMLSTARLET sel -T -t -v "/result/executions/@count" $DIR/curl.out)
echo "$itemcount executions"
if [ "" == "$itemcount" ] ; then
errorMsg "FAIL: executions count was not valid"
exit 2
fi
echo "OK"
#rm $DIR/curl.out