run.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. [ "$DEBUG" ] && set -x
  3. set -eo pipefail
  4. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  5. image="$1"
  6. # Use a client image with curl for testing
  7. clientImage='buildpack-deps:buster-curl'
  8. # ensure the clientImage is ready and available
  9. if ! docker image inspect "$clientImage" &> /dev/null; then
  10. docker pull "$clientImage" > /dev/null
  11. fi
  12. # Create an instance of the container-under-test
  13. serverImage="$("$dir/../image-name.sh" librarytest/jetty-hello-web "$image")"
  14. "$dir/../docker-build.sh" "$dir" "$serverImage" <<EOD
  15. FROM $image
  16. COPY dir/index.jsp /var/lib/jetty/webapps/ROOT/
  17. EOD
  18. cid="$(docker run -d "$serverImage")"
  19. trap "docker rm -vf $cid > /dev/null" EXIT
  20. _request() {
  21. local method="$1"
  22. shift
  23. local url="${1#/}"
  24. shift
  25. docker run --rm \
  26. --link "$cid":jetty \
  27. "$clientImage" \
  28. curl -fs -X"$method" "$@" "http://jetty:8080/$url"
  29. }
  30. # Make sure that Jetty is listening on port 8080
  31. . "$dir/../../retry.sh" --tries 40 --sleep 0.25 '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
  32. # Check that we can request /index.jsp with no params
  33. [ "$(_request GET "/" | tail -1)" = "null" ]
  34. # Check that our index.jsp echoes the value of the "hello" param
  35. hello="world-$RANDOM-$RANDOM"
  36. [ "$(_request GET "/?hello=$hello" | tail -1)" = "$hello" ]