Skip to content

Commit 89c888d

Browse files
committed
Support App Engine or Jetty for local testing.
This script will allow us to run tests against a local server for testing. Since the App Engine and Jetty server running and testing is so similar, I combined the scripts rather than copying. The only differences are which plugin to use and what string to wait for before running curl. Since the bookshelf sample also needs a `-Plocal` profile argument, I extended the script to allow passing through arbitrary arguments to Maven.
1 parent 90a280d commit 89c888d

File tree

1 file changed

+53
-12
lines changed

1 file changed

+53
-12
lines changed

test-devserver.sh renamed to scripts/test-localhost.sh

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515

1616
# Usage:
17-
# test-devserver.sh path/to/project
17+
# test-localhost.sh deployment-type path/to/project -- [maven arguments]
1818
#
1919
# This script runs the local appengine:devserver Maven plugin and verifies that
2020
# a request to http://localhost:8080/ does not return an error code.
@@ -23,23 +23,64 @@
2323
# correct (only if autoGenerate=false and the / handler does all queries used),
2424
# as an example.
2525

26-
set -e
27-
set -x
26+
print_usage () {
27+
echo "Usage:" >&2
28+
echo " $0 server-type path/to/project [-- maven arguments]" >&2
29+
echo >&2
30+
echo "server-type can be any of the following:" >&2
31+
echo " appengine" >&2
32+
echo " jetty" >&2
33+
}
34+
35+
if [[ -z "$1" ]]; then
36+
echo "Missing server-type parameter." >&2
37+
print_usage
38+
exit 1
39+
fi
40+
case $1 in
41+
appengine)
42+
mvn_plugin="appengine:devserver"
43+
server_started_message="localhost:8080"
44+
;;
45+
jetty)
46+
mvn_plugin="jetty:run-exploded"
47+
server_started_message="Started Jetty Server"
48+
;;
49+
*)
50+
print_usage
51+
exit 1
52+
;;
53+
esac
2854

29-
if [ -z "$1" ]; then
30-
echo "Missing directory parameter."
31-
echo "Usage:"
32-
echo " $0 path/to/project"
55+
if [[ -z "$2" ]]; then
56+
echo "Missing directory parameter." >&2
57+
print_usage
3358
exit 1
3459
fi
60+
code_path=$2
61+
62+
mvn_command="mvn --batch-mode clean ${mvn_plugin} -DskipTests"
63+
if [[ "$3" == "--" ]]; then
64+
shift 3
65+
for mvn_arg in "${@}"; do
66+
mvn_command="${mvn_command} ${mvn_arg}"
67+
done
68+
elif [[ -n "$3" ]]; then
69+
echo "Got unexpected third argument" >&2
70+
print_usage
71+
exit 1
72+
fi
73+
74+
set -e
75+
set -x
3576

3677
(
37-
cd "$1"
38-
expect -c '
39-
spawn mvn --batch-mode clean appengine:devserver -DskipTests
78+
cd "$code_path"
79+
expect -c "
80+
spawn ${mvn_command}
4081
set timeout 600
41-
expect localhost:8080
42-
sleep 10
82+
expect \"${server_started_message}\"
83+
"'sleep 10
4384
spawn curl --silent --output /dev/stderr --write-out "%{http_code}" http://localhost:8080/
4485
expect {
4586
"200" {

0 commit comments

Comments
 (0)