|
14 | 14 | # limitations under the License.
|
15 | 15 |
|
16 | 16 | # Usage:
|
17 |
| -# test-devserver.sh path/to/project |
| 17 | +# test-localhost.sh deployment-type path/to/project -- [maven arguments] |
18 | 18 | #
|
19 | 19 | # This script runs the local appengine:devserver Maven plugin and verifies that
|
20 | 20 | # a request to http://localhost:8080/ does not return an error code.
|
|
23 | 23 | # correct (only if autoGenerate=false and the / handler does all queries used),
|
24 | 24 | # as an example.
|
25 | 25 |
|
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 |
28 | 54 |
|
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 |
33 | 58 | exit 1
|
34 | 59 | 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 |
35 | 76 |
|
36 | 77 | (
|
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} |
40 | 81 | set timeout 600
|
41 |
| - expect localhost:8080 |
42 |
| - sleep 10 |
| 82 | + expect \"${server_started_message}\" |
| 83 | + "'sleep 10 |
43 | 84 | spawn curl --silent --output /dev/stderr --write-out "%{http_code}" http://localhost:8080/
|
44 | 85 | expect {
|
45 | 86 | "200" {
|
|
0 commit comments