run.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. set -eo pipefail
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. image="$1"
  5. # Use the image being tested as our client image since it should already have curl
  6. clientImage="$image"
  7. # Create an instance of the container-under-test
  8. cid="$(docker run -d -v "$dir/index.jsp":/var/lib/jetty/webapps/ROOT/index.jsp:ro "$image")"
  9. trap "docker rm -vf $cid > /dev/null" EXIT
  10. _request() {
  11. local method="$1"
  12. shift
  13. local url="${1#/}"
  14. shift
  15. docker run --rm --link "$cid":jetty "$clientImage" \
  16. curl -fs -X"$method" "$@" "http://jetty:8080/$url"
  17. }
  18. # Make sure that Jetty is listening on port 8080
  19. attempts=40
  20. tried="$attempts"
  21. duration=0.25
  22. while [ "$tried" -ge 0 -a "$(_request GET / --output /dev/null || echo $?)" = 7 ]; do
  23. (( tried-- ))
  24. if [ "$tried" -le 0 ]; then
  25. echo >&2 "Unable to connect to Jetty. Aborting."
  26. exit 1
  27. fi
  28. sleep "$duration"
  29. done
  30. # Check that we can request /index.jsp with no params
  31. [ "$(_request GET "/" | tail -1)" = "null" ]
  32. # Check that our index.jsp echoes the value of the "hello" param
  33. hello="world-$RANDOM-$RANDOM"
  34. [ "$(_request GET "/?hello=$hello" | tail -1)" = "$hello" ]