Skip to content

Instantly share code, notes, and snippets.

@johnlonganecker
Created November 8, 2016 00:25
Show Gist options
  • Save johnlonganecker/3b4efe018136621b281964e250f41b93 to your computer and use it in GitHub Desktop.
Save johnlonganecker/3b4efe018136621b281964e250f41b93 to your computer and use it in GitHub Desktop.
CF RabbitMQ Smoke Test
#!/bin/bash
# example execution
# ./rmq-smoke-test.sh --api https://<api.mycf.com> --user <usr> --password <password> --org smoke-tests --space the-final-frontier --domain <run.appsdomain.com>
set -e -u
while test $# -gt 0; do
case "$1" in
--api)
shift
api=$1
shift
;;
--user)
shift
user=$1
shift
;;
--password)
shift
password=$1
shift
;;
--org)
shift
org=$1
shift
;;
--space)
shift
space=$1
shift
;;
--domain)
shift
appsDomain=$1
shift
;;
*)
break
;;
esac
done
# curl defaults
retry=4
retryDelay=2
maxTime=20
retryMaxTime=130
echo $api $user $password $org $space
# generate random string for app route
appName=$(head /dev/urandom | base64 | tr -dc A-Za-z0-9 | head -c 25)
serviceName=rmq-smoke-test-$(head /dev/urandom | base64 | tr -dc A-Za-z0-9 | head -c 10)
appUri=https://$appName.$appsDomain
clean_up()
{
echo ""
echo "Cleaning up"
echo "-----------------------"
echo "unbinding $serviceName from $appName"
cf unbind-service $appName $serviceName
echo "deleting app $appName"
cf delete -f $appName
echo "deleting service $serviceName"
cf delete-service -f $serviceName
}
# login
cf login -a $api -u $user -p $password -o $org -s $space
# push example app
cf push $appName -m 256m -s cflinuxfs2 -p "cf-rabbitmq-example-app" --no-start
# create service instance
cf create-service rabbitmq-36 standard $serviceName
# bind service
cf bind-service $appName $serviceName
# start app
cf start $appName
# starting tests
echo -e "\nRunning Tests"
echo "-----------------------"
# Checking that the app is responding at url: ", pinguri)
echo "Make sure app is running and responding"
response=$(curl -k -s -X GET --retry $retry --retry-delay $retryDelay --max-time $maxTime --retry-max-time $retryMaxTime $appUri/ping)
if [ "$response" = "OK" ]; then
echo -e "PASS: App is running\n"
else
echo -e "FAILED: App is not running\n"
clean_up
exit 1
fi
# Creating a new queue:
echo "Creating a new Queue"
response=$(curl -k -s -X POST -d "name=test-q" --retry $retry --retry-delay $retryDelay --max-time $maxTime --retry-max-time $retryMaxTime $appUri/queues)
if [ "$response" = "SUCCESS" ]; then
echo -e "PASS: successfully created a new queue\n"
else
echo -e "FAILED: failed to create a new queue\n"
clean_up
exit 1
fi
# can write to and read from a service instance using the $planname
# Listing the queues: ", uri)
echo "List all queues should see just one queue that we created"
response=$(curl -k -s -X GET --retry $retry --retry-delay $retryDelay --max-time $maxTime --retry-max-time $retryMaxTime $appUri/queues)
# should return test-q\n
if [ "$response" = "test.mq.test-q" ]; then
echo -e "PASS: successfully listed queue that we created\n"
else
echo -e "FAILED: failed to find the queue we created\n"
clean_up
exit 1
fi
# Publishing to the queue
echo "Publishing to the new queue"
response=$(curl -k -s -X PUT -d "data=test-message-amqp" --retry $retry --retry-delay $retryDelay --max-time $maxTime --retry-max-time $retryMaxTime $appUri/queue/test-q)
# should respond SUCCESS
if [ "$response" = "SUCCESS" ]; then
echo -e "PASS: successfully published a message to the queue\n"
else
echo -e "FAILED: unsuccessfully published a message to the queue\n"
clean_up
exit 1
fi
# Reading from the (non-empty) queue
echo "Read our published message"
response=$(curl -k -s -X GET --retry $retry --retry-delay $retryDelay --max-time $maxTime --retry-max-time $retryMaxTime $appUri/queue/test-q)
# should response test-message-amqp
if [ "$response" = "test-message-amqp" ]; then
echo -e "PASS: successfully read a message from the queue\n"
else
echo -e "FAILED: unsuccessfully read a message from the queue\n"
clean_up
exit 1
fi
# echo "Reading from the (empty) queue:"
echo "Confirm queue is empty"
response=$(curl -k -s -X GET --retry $retry --retry-delay $retryDelay --max-time $maxTime --retry-max-time $retryMaxTime $appUri/queue/test-q)
# should respond blank
if [ "$response" = "" ]; then
echo -e "PASS: queue is empty\n"
else
echo -e "FAILED: queue is not empty\n"
clean_up
exit 1
fi
clean_up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment