Skip to content

Commit

Permalink
Tests for execution output API #145
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Jul 5, 2012
1 parent 5d965aa commit 51052a9
Show file tree
Hide file tree
Showing 3 changed files with 381 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/api/include.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ xmlsel(){
$XMLSTARLET sel -T -t -v "$xpath" $*
}

API_CURRENT_VERSION=4
API_CURRENT_VERSION=5

API_VERSION=${API_VERSION:-$API_CURRENT_VERSION}

Expand Down
119 changes: 119 additions & 0 deletions test/api/test-execution-output-plain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/bash

#test output from /api/execution/{id}/output

DIR=$(cd `dirname $0` && pwd)
source $DIR/include.sh

####
# Setup: create simple adhoc command execution to provide execution ID.
####

runurl="${APIURL}/run/command"
proj="test"
params="project=${proj}&exec=echo+testing+execution+output+api+line+1;sleep+2;echo+line+2;sleep+2;echo+line+3;sleep+2;echo+line+4+final"

expectfile=$DIR/expect-exec-output-plain.txt

cat > $expectfile <<END
testing execution output api line 1
line 2
line 3
line 4 final
END

# get listing
docurl ${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: receive output in plain text
####

# now submit req
runurl="${APIURL}/execution/${execid}/output.text"

echo "TEST: /api/execution/${execid}/output.text using lastmod ..."

outfile=$DIR/test-exec-output-plain.txt
doff=0
ddone="false"
dlast=0
dmax=20
dc=0
while [[ $ddone == "false" && $dc -lt $dmax ]]; do
#statements
params="offset=$doff&lastmod=$dlast"

# get listing
docurl -D $DIR/headers.out ${runurl}?${params} > $DIR/curl.out
if [ 0 != $? ] ; then
errorMsg "ERROR: failed query request"
exit 2
fi
grep "HTTP/1.1 200" -q $DIR/headers.out
if [ 0 != $? ] ; then
errorMsg "ERROR: failed query request"
exit 2
fi

ocount=$(wc -l $DIR/curl.out)

#output text

if [[ -r $DIR/curl.out ]]; then
cat $DIR/curl.out >> $outfile
cat $DIR/curl.out
rm $DIR/curl.out
fi

unmod=$(grep 'X-Rundeck-ExecOutput-Unmodified:' $DIR/headers.out | cut -d' ' -f 2 | tr -d "\r\n")
doff=$(grep 'X-Rundeck-ExecOutput-Offset:' $DIR/headers.out | cut -d' ' -f 2 | tr -d "\r\n")
dlast=$(grep 'X-Rundeck-ExecOutput-LastModifed:' $DIR/headers.out | cut -d' ' -f 2 | tr -d "\r\n")
ddone=$(grep 'X-Rundeck-ExecOutput-Completed:' $DIR/headers.out | cut -d' ' -f 2 | tr -d "\r\n")
#echo "unmod $unmod"
#echo "doff $doff"
#echo "dlast $dlast"
#echo "ddone $ddone"
if [[ $unmod == "true" ]]; then
#echo "unmodifed, sleep 3..."
sleep 2
else
#echo "$ocount lines, sleep 1"
if [[ $ddone != "true" ]]; then
sleep 1
fi
fi
dc=$(( $dc + 1 ))

done

if [[ $ddone != "true" ]]; then
errorMsg "ERROR: not all output was received in $dc requests"
exit 2
fi

diff --ignore-all-space -q $expectfile $outfile
if [[ 0 != $? ]] ; then
errorMsg "ERROR: unexpected output"
exit 2
fi

rm $expectfile $outfile

echo "OK"
261 changes: 261 additions & 0 deletions test/api/test-execution-output.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
#!/bin/bash

#test output from /api/execution/{id}/output

DIR=$(cd `dirname $0` && pwd)
source $DIR/include.sh

####
# Setup: create simple adhoc command execution to provide execution ID.
####

runurl="${APIURL}/run/command"
proj="test"
params="project=${proj}&exec=echo+testing+execution+output+api+line+1;sleep+2;echo+line+2;sleep+2;echo+line+3;sleep+2;echo+line+4+final"

# get listing
docurl ${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: receive output using lastmod param
####

# now submit req
runurl="${APIURL}/execution/${execid}/output.xml"

echo "TEST: /api/execution/${execid}/output.xml using lastmod ..."

doff=0
ddone="false"
dlast=0
dmax=20
dc=0
while [[ $ddone == "false" && $dc -lt $dmax ]]; do
#statements
params="offset=$doff&lastmod=$dlast"

# get listing
docurl ${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

ocount=$($XMLSTARLET sel -T -t -v "count(/result/output/entries/entry)" $DIR/curl.out)

#output text
$XMLSTARLET sel -T -t -m "/result/output/entries/entry" -o "OUT: " -v "." -n $DIR/curl.out

unmod=$($XMLSTARLET sel -T -t -v "/result/output/unmodified" $DIR/curl.out)
doff=$($XMLSTARLET sel -T -t -v "/result/output/offset" $DIR/curl.out)
dlast=$($XMLSTARLET sel -T -t -v "/result/output/lastModified" $DIR/curl.out)
ddone=$($XMLSTARLET sel -T -t -v "/result/output/completed" $DIR/curl.out)
#echo "unmod $unmod, doff $doff, dlast $dlast, ddone $ddone"
if [[ $unmod == "true" ]]; then
#echo "unmodifed, sleep 3..."
sleep 2
else
#echo "$ocount lines, sleep 1"
if [[ $ddone != "true" ]]; then
sleep 1
fi
fi
dc=$(( $dc + 1 ))

done

if [[ $ddone != "true" ]]; then
errorMsg "ERROR: not all output was received in $dc requests"
exit 2
fi

echo "OK"


####
# Setup: run adhoc command to output lines
####

runurl="${APIURL}/run/command"
proj="test"
params="project=${proj}&exec=echo+testing+execution+output+api+line+1;sleep+2;echo+line+2;sleep+2;echo+line+3;sleep+2;echo+line+4+final"

# get listing
docurl ${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: receive output with maxlines param
####

# now submit req
runurl="${APIURL}/execution/${execid}/output.xml"

echo "TEST: /api/execution/${execid}/output.xml using maxlines..."

doff=0
ddone="false"
dlast=0
dmax=20
dc=0
while [[ $ddone == "false" && $dc -lt $dmax ]]; do
#statements
params="offset=$doff&maxlines=1"

# get listing
docurl ${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

ocount=$($XMLSTARLET sel -T -t -v "count(/result/output/entries/entry)" $DIR/curl.out)

#output text
$XMLSTARLET sel -T -t -m "/result/output/entries/entry" -o "OUT: " -v "." -n $DIR/curl.out

unmod=$($XMLSTARLET sel -T -t -v "/result/output/unmodified" $DIR/curl.out)
doff=$($XMLSTARLET sel -T -t -v "/result/output/offset" $DIR/curl.out)
dlast=$($XMLSTARLET sel -T -t -v "/result/output/lastModified" $DIR/curl.out)
ddone=$($XMLSTARLET sel -T -t -v "/result/output/completed" $DIR/curl.out)
#echo "unmod $unmod, doff $doff, dlast $dlast, ddone $ddone"
if [[ $unmod == "true" ]]; then
#echo "unmodifed, sleep 3..."
sleep 2
else
#echo "$ocount lines, sleep 1"
if [[ $ddone != "true" ]]; then
sleep 1
fi
fi
dc=$(( $dc + 1 ))

done

if [[ $ddone != "true" ]]; then
errorMsg "ERROR: not all output was received in $dc requests"
exit 2
fi

echo "OK"



####
# Setup: run adhoc command to output lines
####

runurl="${APIURL}/run/command"
proj="test"
params="project=${proj}&exec=echo+testing+execution+output+api+line+1;sleep+2;echo+line+2;sleep+2;echo+line+3;sleep+2;echo+line+4+final"

# get listing
docurl ${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: receive output greedily
####

# now submit req
runurl="${APIURL}/execution/${execid}/output.xml"

echo "TEST: /api/execution/${execid}/output.xml ..."

doff=0
ddone="false"
dlast=0
dmax=20
dc=0
while [[ $ddone == "false" && $dc -lt $dmax ]]; do
#statements
params="offset=$doff"

# get listing
docurl ${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

ocount=$($XMLSTARLET sel -T -t -v "count(/result/output/entries/entry)" $DIR/curl.out)

#output text
$XMLSTARLET sel -T -t -m "/result/output/entries/entry" -o "OUT: " -v "." -n $DIR/curl.out

unmod=$($XMLSTARLET sel -T -t -v "/result/output/unmodified" $DIR/curl.out)
doff=$($XMLSTARLET sel -T -t -v "/result/output/offset" $DIR/curl.out)
dlast=$($XMLSTARLET sel -T -t -v "/result/output/lastModified" $DIR/curl.out)
ddone=$($XMLSTARLET sel -T -t -v "/result/output/completed" $DIR/curl.out)
#echo "unmod $unmod, doff $doff, dlast $dlast, ddone $ddone"
if [[ $unmod == "true" ]]; then
#echo "unmodifed, sleep 3..."
sleep 2
else
#echo "$ocount lines, sleep 1"
if [[ $ddone != "true" ]]; then
sleep 1
fi
fi
dc=$(( $dc + 1 ))

done

if [[ $ddone != "true" ]]; then
errorMsg "ERROR: not all output was received in $dc requests"
exit 2
fi

echo "OK"

0 comments on commit 51052a9

Please sign in to comment.