run.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. [ "$DEBUG" ] && set -x
  3. set -eo pipefail
  4. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  5. image="$1"
  6. # Use the image being tested as our client image since it should already have curl
  7. clientImage="$image"
  8. # Create an instance of the container-under-test
  9. cid="$(docker run -d "$image")"
  10. trap "docker rm -vf $cid > /dev/null" EXIT
  11. _request() {
  12. local method="$1"
  13. shift
  14. local url="${1#/}"
  15. shift
  16. # https://github.com/docker/docker/issues/14203#issuecomment-129865960 (DOCKER_FIX)
  17. docker run --rm --link "$cid":es \
  18. -e DOCKER_FIX=' ' \
  19. "$clientImage" curl -fs -X"$method" "$@" "http://es:9200/$url"
  20. }
  21. _trimmed() {
  22. _request "$@" | sed -r 's/^[[:space:]]+|[[:space:]]+$//g'
  23. }
  24. _req-comp() {
  25. local method="$1"; shift
  26. local url="$1"; shift
  27. local expected="$1"; shift
  28. response="$(_trimmed "$method" "$url")"
  29. [ "$response" = "$expected" ]
  30. }
  31. _req-exit() {
  32. local method="$1"; shift
  33. local url="$1"; shift
  34. local expectedRet="$1"; shift
  35. [ "$(_request "$method" "$url" --output /dev/null || echo "$?")" = "$expectedRet" ]
  36. }
  37. # Make sure our container is listening
  38. . "$dir/../../retry.sh" '! _req-exit GET / 7' # "Failed to connect to host."
  39. # Perform simple health check
  40. _req-comp GET '/_cat/health?h=status' 'green'
  41. # should be green because it's empty and fresh
  42. _req-exit GET '/_cat/indices/test1?h=docs.count' 22 # "HTTP page not retrieved. 4xx"
  43. _req-exit GET '/_cat/indices/test2?h=docs.count' 22 # "HTTP page not retrieved. 4xx"
  44. doc='{"a":"b","c":{"d":"e"}}'
  45. _request POST '/test1/test/1?refresh=true' --data "$doc" -o /dev/null
  46. _req-comp GET '/_cat/indices/test1?h=docs.count' 1
  47. _req-exit GET '/_cat/indices/test2?h=docs.count' 22 # "HTTP page not retrieved. 4xx"
  48. _request POST '/test2/test/1?refresh=true' --data "$doc" -o /dev/null
  49. _req-comp GET '/_cat/indices/test1?h=docs.count' 1
  50. _req-comp GET '/_cat/indices/test2?h=docs.count' 1
  51. _req-comp GET '/test1/test/1/_source' "$doc"
  52. _req-comp GET '/test2/test/1/_source' "$doc"
  53. _request DELETE '/test1/test/1?refresh=true' -o /dev/null
  54. _req-comp GET '/_cat/indices/test1?h=docs.count' 0
  55. _req-comp GET '/_cat/indices/test2?h=docs.count' 1
  56. _request DELETE '/test2/test/1?refresh=true' -o /dev/null
  57. _req-comp GET '/_cat/indices/test1?h=docs.count' 0
  58. _req-comp GET '/_cat/indices/test2?h=docs.count' 0