run.sh 848 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. set -eo pipefail
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. image="$1"
  5. # since we have curl in the tomcat image, we'll use that
  6. clientImage="$1"
  7. serverImage="$1"
  8. # Create an instance of the container-under-test
  9. cid="$(docker run -d "$serverImage")"
  10. trap "docker rm -vf $cid > /dev/null" EXIT
  11. _request() {
  12. local method="$1"
  13. shift
  14. local url="${1#/}"
  15. shift
  16. docker run --rm --link "$cid":tomcat "$clientImage" \
  17. curl -fs -X"$method" "$@" "http://tomcat:8080/$url"
  18. }
  19. # Make sure that Tomcat is listening
  20. . "$dir/../../retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
  21. # Check that we can request /
  22. [ -n "$(_request GET '/')" ]
  23. # Check that the example "Hello World" servlet works
  24. helloWorld="$(_request GET '/examples/servlets/servlet/HelloWorldExample')"
  25. [[ "$helloWorld" == *'Hello World!'* ]]