diff --git a/package.json b/package.json index 82cdff2..29e41aa 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "An OpenShift Demo app running on NodeJS", "main": "server.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "./tests/run-integration-tests.sh" }, "author": "Nicolas MASSE", "repository": "https://github.com/nmasse-itix/OpenShift-Demo-NodeJS.git", diff --git a/tests/run-integration-tests.sh b/tests/run-integration-tests.sh new file mode 100755 index 0000000..a7adc3f --- /dev/null +++ b/tests/run-integration-tests.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Exit immediately if command returns non-zero status code +set -e + +if [ -z "$1" ]; then + echo "No running instance is given, running our own NodeJS server !" + node server.js &>/dev/null & + echo "Waiting for NodeJS to start..." + sleep 5 # wait for NodeJS to start + node_pid=$! + appurl="http://localhost:8080" + + # Do not forget to kill it when finished + trap "kill $node_pid" EXIT +else + appurl="$1" +fi + +function runtest() { + url="$1" + expected="$2" + ret="$(curl -s -o /dev/null -w "%{http_code}" "$url")" + if [ "$ret" != "$expected" ]; then + echo "$url: Got HTTP Status code '$ret' instead of a '$expected' Status code." + exit 1 + fi +} + +runtest "$appurl/" 200 +runtest "$appurl/info" 200 +runtest "$appurl/blabla" 404 + +echo "Successfully passed integration tests"