Skip to content

Commit

Permalink
Clean up test scripts with common include
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Feb 15, 2011
1 parent 6db0b4f commit ee695b7
Show file tree
Hide file tree
Showing 31 changed files with 125 additions and 682 deletions.
40 changes: 40 additions & 0 deletions test/api/include.sh
@@ -0,0 +1,40 @@
#!/bin/bash

# common header for test scripts

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

errorMsg() {
echo "$*" 1>&2
}
assert(){
# assert expected, actual
if [ "$1" != "$2" ] ; then
errorMsg "FAIL: Expected value \"$1\" but saw: \"$2\" ${3}"
exit 2
fi
}

# modify to point to xmlstarlet
XMLSTARLET=xml

# xmlstarlet select xpath
# usage: xmlsel XPATH file
xmlsel(){
$XMLSTARLET sel -T -t -v "$1" $2
}

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"

# accept url argument on commandline, if '-' use default
RDURL="$1"
if [ "-" == "$1" ] ; then
RDURL='http://localhost:4440'
fi
shift

APIURL="${RDURL}/api"
33 changes: 4 additions & 29 deletions test/api/test-execution-abort.sh
Expand Up @@ -2,39 +2,14 @@

#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
source $DIR/include.sh

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

runurl="${apiurl}/run/command"
runurl="${APIURL}/run/command"
proj="test"
params="project=${proj}&exec=echo+testing+execution+api%3Bsleep+120"

Expand Down Expand Up @@ -62,7 +37,7 @@ fi
####

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

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

Expand Down Expand Up @@ -90,7 +65,7 @@ echo "OK"
# test /abort
####

runurl="${apiurl}/execution/${execid}/abort"
runurl="${APIURL}/execution/${execid}/abort"

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

Expand Down
31 changes: 3 additions & 28 deletions test/api/test-execution.sh
Expand Up @@ -2,39 +2,14 @@

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

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
source $DIR/include.sh

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

runurl="${apiurl}/run/command"
runurl="${APIURL}/run/command"
proj="test"
params="project=${proj}&exec=echo+testing+execution+api"

Expand Down Expand Up @@ -62,7 +37,7 @@ fi
####

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

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

Expand Down
21 changes: 2 additions & 19 deletions test/api/test-executions-running.sh
Expand Up @@ -2,29 +2,12 @@

#test output from /api/executions/running

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

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

# 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"
runurl="${APIURL}/executions/running"
proj=$2
if [ "" == "$2" ] ; then
proj="test"
Expand Down
23 changes: 2 additions & 21 deletions test/api/test-history.sh
Expand Up @@ -2,32 +2,13 @@

#Test api: /api/history output

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
shift
source $DIR/include.sh

proj="test"

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}/history"
runurl="${APIURL}/history"

echo "TEST: output from /api/history should be valid"

Expand Down
22 changes: 2 additions & 20 deletions test/api/test-invalid.sh
Expand Up @@ -2,29 +2,11 @@

#test output from invalid api request path: /api/dnexist

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
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

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

echo "TEST: api request to invalid api path"

Expand Down
26 changes: 4 additions & 22 deletions test/api/test-job-delete.sh
Expand Up @@ -2,27 +2,9 @@

#test DELETE for /api/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/api'
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
source $DIR/include.sh

###
# setup: create a new job and acquire the ID
Expand Down Expand Up @@ -66,7 +48,7 @@ cat > $DIR/temp.out <<END
END

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

params=""

Expand Down Expand Up @@ -102,7 +84,7 @@ echo "TEST: DELETE job should succeed"


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

# get listing
Expand All @@ -123,7 +105,7 @@ echo "OK"
echo "TEST: Get deleted job should fail"

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

Expand Down
22 changes: 2 additions & 20 deletions test/api/test-job-export-missing.sh
Expand Up @@ -2,27 +2,9 @@

#test output from /api/job/{id} when job ID does not exist

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
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

###
# Export an invalid ID
Expand All @@ -32,7 +14,7 @@ echo "TEST: export job with wrong ID"


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

# expect error message
Expand Down

0 comments on commit ee695b7

Please sign in to comment.