Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Apr 25, 2011
1 parent 0078abb commit 85f7492
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 78 deletions.
111 changes: 111 additions & 0 deletions test/api/test-project-resources-refresh.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash

#test update project resources file

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

# now submit req
proj="test"

runurl="${APIURL}/project/${proj}/resources/refresh"

echo "TEST: /api/project/${proj}/resources/refresh (no URL defined)"
params="t=t"

$CURL -X POST ${runurl}?${params} > ${file} || fail "ERROR: failed request"

sh $DIR/api-test-error.sh ${file} "Resources were not updated because no resource model provider URL is configured for project test" || exit 2

echo "OK"

echo "TEST: /api/project/${proj}/resources/refresh (invalid URL)"

#backup project.properties and set invalid resources url

TETC=$RDECK_BASE/projects/test/etc
TPROPS=$TETC/project.properties
TRES=$TETC/resources.xml

if [ ! -f $TPROPS.testbackup ] ; then
cp $TPROPS $TPROPS.testbackup
fi
if [ ! -f $TRES.testbackup ] ; then
cp $TRES $TRES.testbackup
fi

echo "project.resources.url=http://invaliddomain:1234/resources.xml" >> $TPROPS


$CURL -X POST ${runurl}?${params} > ${file} || fail "ERROR: failed request"

sh $DIR/api-test-error.sh ${file} "Error updating node resources file for project test: java.net.UnknownHostException: invaliddomain" || exit 2

echo "OK"

cp $TPROPS.testbackup $TPROPS

echo "TEST: /api/project/${proj}/resources/refresh (valid temp URL)"

cat <<END > $TETC/testUpdateResources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project PUBLIC "-//DTO Labs Inc.//DTD Resources Document 1.0//EN" "project.dtd">
<project>
<node name="test1" type="Node" description="Rundeck test node" tags="test1,testboth" hostname="testhost1" osArch="x86_64" osFamily="unix" osName="Mac OS X" osVersion="10.6.6" username="rdeck" editUrl="" remoteUrl=""/>
<node name="test2" type="Node" description="Rundeck test node" tags="test2,testboth" hostname="testhost2" osArch="x86_64" osFamily="unix" osName="Mac OS X" osVersion="10.6.6" username="rdeck1" editUrl="" remoteUrl=""/>
</project>
END

TEMPURL="file://$TETC/testUpdateResources.xml"

echo "project.resources.url=$TEMPURL" >> $TPROPS


$CURL -X POST ${runurl}?${params} > ${file} || fail "ERROR: failed request"

sh $DIR/api-test-success.sh ${file} "Resources were successfully updated for project test" || exit 2

echo "OK"

#restore backup props, no provider url
if [ -f $TPROPS.testbackup ] ; then
mv $TPROPS.testbackup $TPROPS
fi

echo "TEST: /api/project/${proj}/resources/refresh (POST) (invalid provider URL)"

#backup project.properties and set invalid resources url

data="providerURL=http://invaliddomain:1234/resources.xml"

# post data
$CURL -X POST --data-urlencode "${data}" ${runurl}?${params} > ${file} || fail "ERROR: failed request"

sh $DIR/api-test-error.sh ${file} "Error updating node resources file for project test: java.net.UnknownHostException: invaliddomain" || exit 2

echo "OK"


echo "TEST: /api/project/${proj}/resources/refresh (POST) (valid provider URL)"


TEMPURL="file://$TETC/testUpdateResources.xml"

data="providerURL=$TEMPURL"

# post data
$CURL -X POST --data-urlencode "${data}" ${runurl}?${params} > ${file} || fail "ERROR: failed request"

sh $DIR/api-test-success.sh ${file} "Resources were successfully updated for project test" || exit 2

echo "OK"


if [ -f $TRES.testbackup ] ; then
mv $TRES.testbackup $TRES
fi

rm ${file}

139 changes: 139 additions & 0 deletions test/api/test-project-resources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

#test update project resources file

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

file=$DIR/curl.out

# now submit req
proj="test"

runurl="${APIURL}/project/${proj}/resources"

echo "TEST: /api/project/${proj}/resources (GET)"
params="format=xml"

# get listing
$CURL ${runurl}?${params} > ${file} || fail "ERROR: failed request"

#test curl.out for valid xml
$XMLSTARLET val -w ${file} > /dev/null 2>&1
validxml=$?
if [ 0 == $validxml ] ; then
#test for for possible result error message
$XMLSTARLET el ${file} | grep -e '^result' -q
if [ 0 == $? ] ; then
#test for error message
#If <result error="true"> then an error occured.
waserror=$($XMLSTARLET sel -T -t -v "/result/@error" ${file})
errmsg=$($XMLSTARLET sel -T -t -v "/result/error/message" ${file})
if [ "" != "$waserror" -a "true" == $waserror ] ; then
errorMsg "FAIL: expected resource.xml content but received error result: $errmsg"
exit 2
fi
fi
fi

#test curl.out for valid xml
if [ 0 != $validxml ] ; then
errorMsg "ERROR: Response was not valid xml"
exit 2
fi

#test for expected /joblist element
$XMLSTARLET el ${file} | grep -e '^project' -q
if [ 0 != $? ] ; then
errorMsg "ERROR: Response did not contain expected result"
exit 2
fi

#Check results list
itemcount=$($XMLSTARLET sel -T -t -v "count(/project/node)" ${file})
echo "$itemcount Nodes"
if [ "0" == "$itemcount" ] ; then
errorMsg "FAIL: expected multiple /project/node element"
exit 2
fi

echo "OK"


TETC=$RDECK_BASE/projects/test/etc
TRES=$TETC/resources.xml

if [ ! -f $TRES.testbackup ] ; then
cp $TRES $TRES.testbackup
fi



cat <<END > $TETC/testUpdateResources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE project PUBLIC "-//DTO Labs Inc.//DTD Resources Document 1.0//EN" "project.dtd">
<project>
<node name="test1" type="Node" description="Rundeck test node" tags="test1,testboth" hostname="testhost1" osArch="x86_64" osFamily="unix" osName="Mac OS X" osVersion="10.6.6" username="rdeck" editUrl="" remoteUrl=""/>
<node name="test2" type="Node" description="Rundeck test node" tags="test2,testboth" hostname="testhost2" osArch="x86_64" osFamily="unix" osName="Mac OS X" osVersion="10.6.6" username="rdeck1" editUrl="" remoteUrl=""/>
</project>
END

echo "TEST: /api/project/${proj}/resources (POST) (xml)"


# post data
$CURL -X POST -H 'Content-Type: text/xml' --data-binary "@$TETC/testUpdateResources.xml" ${runurl}?${params} > ${file} || fail "ERROR: failed request"

sh $DIR/api-test-success.sh ${file} "Resources were successfully updated for project test" || exit 2

echo "OK"

#exit 0

cat <<END > $TETC/testUpdateResources.yaml
test1:
tags: test1, testboth
osFamily: unix
osVersion: 10.6.6
osArch: x86_64
editUrl: ''
hostname: testhost1
type: Node
username: rdeck
description: Rundeck test node
remoteUrl: ''
nodename: test1
osName: Mac OS X
test2:
tags: test2, testboth
osFamily: unix
osVersion: 10.6.6
osArch: x86_64
editUrl: ''
hostname: testhost2
type: Node
username: rdeck1
description: Rundeck test node
remoteUrl: ''
nodename: test2
osName: Mac OS X
END

echo "TEST: /api/project/${proj}/resources (POST) (yaml)"

# post data
$CURL -X POST -H 'Content-Type: text/yaml' --data-binary "@$TETC/testUpdateResources.yaml" ${runurl}?${params} > ${file} || fail "ERROR: failed request"

sh $DIR/api-test-success.sh ${file} "Resources were successfully updated for project test" || exit 2

echo "OK"

if [ -f $TRES.testbackup ] ; then
mv $TRES.testbackup $TRES
fi

rm $TETC/testUpdateResources.yaml
rm $TETC/testUpdateResources.xml
rm $DIR/curl.out

73 changes: 0 additions & 73 deletions test/api/test-project-updateResources.sh

This file was deleted.

6 changes: 1 addition & 5 deletions test/api/test-resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ project="test"
params="project=${project}"

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

#test curl.out for valid xml
$XMLSTARLET val -w ${file} > /dev/null 2>&1
Expand Down

0 comments on commit 85f7492

Please sign in to comment.